restructure

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyAPIKey = errors.New("API key is required")

ErrEmptyAPIKey indicates that the API key was not provided.

View Source
var ErrTranscriptTooLong = errors.New("transcript exceeds 100K token limit")

ErrTranscriptTooLong indicates the transcript exceeds the 100K token limit.

Functions

This section is empty.

Types

type DeepSeekOption

type DeepSeekOption func(*DeepSeekRestructurer)

DeepSeekOption configures a DeepSeekRestructurer.

func WithDeepSeekBaseURL

func WithDeepSeekBaseURL(url string) DeepSeekOption

WithDeepSeekBaseURL sets a custom base URL (for testing or proxies).

func WithDeepSeekHTTPTimeout

func WithDeepSeekHTTPTimeout(timeout time.Duration) DeepSeekOption

WithDeepSeekHTTPTimeout sets the HTTP client timeout. Default is 5 minutes to accommodate large transcript processing.

func WithDeepSeekMaxInputTokens

func WithDeepSeekMaxInputTokens(max int) DeepSeekOption

WithDeepSeekMaxInputTokens sets the maximum input token limit.

func WithDeepSeekMaxOutputTokens

func WithDeepSeekMaxOutputTokens(max int) DeepSeekOption

WithDeepSeekMaxOutputTokens sets the maximum output token limit.

func WithDeepSeekMaxRetries

func WithDeepSeekMaxRetries(n int) DeepSeekOption

WithDeepSeekMaxRetries sets the maximum number of retry attempts.

func WithDeepSeekModel

func WithDeepSeekModel(model string) DeepSeekOption

WithDeepSeekModel sets the model for restructuring. Available: "deepseek-reasoner" (64K output), "deepseek-chat" (8K output).

func WithDeepSeekRetryDelays

func WithDeepSeekRetryDelays(base, max time.Duration) DeepSeekOption

WithDeepSeekRetryDelays sets the base and max delays for exponential backoff.

type DeepSeekRestructurer

type DeepSeekRestructurer struct {
	// contains filtered or unexported fields
}

DeepSeekRestructurer restructures transcripts using DeepSeek's chat completion API. It supports automatic retries with exponential backoff for transient errors.

func NewDeepSeekRestructurer

func NewDeepSeekRestructurer(apiKey string, opts ...DeepSeekOption) (*DeepSeekRestructurer, error)

NewDeepSeekRestructurer creates a new DeepSeekRestructurer. apiKey is required and must be a valid DeepSeek API key. Returns nil and ErrEmptyAPIKey if apiKey is empty.

func (*DeepSeekRestructurer) Restructure

func (r *DeepSeekRestructurer) Restructure(ctx context.Context, transcript string, tmpl template.Name, outputLang lang.Language) (string, error)

Restructure transforms a raw transcript into structured markdown using the specified template. outputLang specifies the output language. Zero value uses template's native language (English). Returns ErrTranscriptTooLong if the transcript exceeds the token limit (estimated). Automatically retries on transient errors (rate limits, timeouts, server errors).

func (*DeepSeekRestructurer) RestructureWithCustomPrompt

func (r *DeepSeekRestructurer) RestructureWithCustomPrompt(ctx context.Context, content, prompt string) (string, error)

RestructureWithCustomPrompt executes restructuring with a custom prompt (used by MapReduce). Unlike Restructure, this does not resolve templates or check token limits.

type MapReduceOption

type MapReduceOption func(*MapReduceRestructurer)

MapReduceOption configures a MapReduceRestructurer.

func WithMapReduceMaxTokens

func WithMapReduceMaxTokens(max int) MapReduceOption

WithMapReduceMaxTokens sets the max tokens per chunk.

func WithMapReduceProgress

func WithMapReduceProgress(fn func(phase string, current, total int)) MapReduceOption

WithMapReduceProgress sets a progress callback.

type MapReduceRestructurer

type MapReduceRestructurer struct {
	// contains filtered or unexported fields
}

MapReduceRestructurer handles long transcripts by splitting, processing, and merging. It works with any restructurer that implements customPromptRestructurer (both OpenAIRestructurer and DeepSeekRestructurer).

func NewMapReduceRestructurer

func NewMapReduceRestructurer(r customPromptRestructurer, opts ...MapReduceOption) *MapReduceRestructurer

NewMapReduceRestructurer creates a MapReduceRestructurer wrapping an existing restructurer. The restructurer must implement customPromptRestructurer (OpenAIRestructurer or DeepSeekRestructurer).

func (*MapReduceRestructurer) Restructure

func (mr *MapReduceRestructurer) Restructure(ctx context.Context, transcript string, tmpl template.Name, outputLang lang.Language) (string, bool, error)

Restructure processes a transcript, using MapReduce if it exceeds the token limit. Returns the restructured output, whether MapReduce was used, and any error.

type MapReducer

type MapReducer interface {
	// Restructure processes a transcript, using MapReduce if it exceeds the token limit.
	// Returns the restructured output, whether MapReduce was used, and any error.
	Restructure(ctx context.Context, transcript string, tmpl template.Name, outputLang lang.Language) (string, bool, error)
}

MapReducer processes transcripts with automatic chunking for long content. Implementations split long transcripts, process chunks, and merge results.

type OpenAIRestructurer

type OpenAIRestructurer struct {
	// contains filtered or unexported fields
}

OpenAIRestructurer restructures transcripts using OpenAI's chat completion API. It supports automatic retries with exponential backoff for transient errors.

func NewOpenAIRestructurer

func NewOpenAIRestructurer(client *openai.Client, opts ...Option) *OpenAIRestructurer

NewOpenAIRestructurer creates a new OpenAIRestructurer with the given client. Use options to customize model, token limits, and retry behavior.

func (*OpenAIRestructurer) Restructure

func (r *OpenAIRestructurer) Restructure(ctx context.Context, transcript string, tmpl template.Name, outputLang lang.Language) (string, error)

Restructure transforms a raw transcript into structured markdown using the specified template. outputLang specifies the output language. Zero value uses template's native language (English). Returns ErrTranscriptTooLong if the transcript exceeds the token limit (estimated). Automatically retries on transient errors (rate limits, timeouts, server errors).

Token estimation uses len(text)/3 which is conservative for French text. The actual API limit is 128K tokens; we use 100K as a safety margin.

func (*OpenAIRestructurer) RestructureWithCustomPrompt

func (r *OpenAIRestructurer) RestructureWithCustomPrompt(ctx context.Context, content, prompt string) (string, error)

RestructureWithCustomPrompt executes restructuring with a custom prompt (used by MapReduce). Unlike Restructure, this does not resolve templates or check token limits.

type Option

type Option func(*OpenAIRestructurer)

Option configures an OpenAIRestructurer.

func WithMaxInputTokens

func WithMaxInputTokens(max int) Option

WithMaxInputTokens sets the maximum input token limit.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets the maximum number of retry attempts.

func WithModel

func WithModel(model string) Option

WithModel sets the model for restructuring.

func WithRetryDelays

func WithRetryDelays(base, max time.Duration) Option

WithRetryDelays sets the base and max delays for exponential backoff.

type Restructurer

type Restructurer interface {
	// Restructure transforms a transcript using the specified template.
	// outputLang specifies the output language.
	// Zero value outputLang uses the template's native language (English).
	Restructure(ctx context.Context, transcript string, tmpl template.Name, outputLang lang.Language) (string, error)
}

Restructurer transforms raw transcripts into structured markdown using templates.

type TranscriptChunk

type TranscriptChunk struct {
	Index   int    // 0-based index
	Content string // The chunk content
	Total   int    // Total number of chunks
}

TranscriptChunk represents a portion of a transcript for MapReduce processing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL