diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-08 09:53:17 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-08 09:53:17 +0300 |
| commit | cd4265b8f87811db758c89bab5e62daa6c39337a (patch) | |
| tree | 94c0a129b4b6ee9132baaa81eb3fbc96b083cbd4 /internal/models | |
| parent | 7e7d34bfc0aec2aa8dff4cefa720e4a9b42d95d8 (diff) | |
feat(httpctx): add timeouts for OpenAI, Gemini, and HTTP downloads
Introduce internal/httpctx with non-zero http.Client timeouts for go-openai
and google.golang.org/genai, shared image download client, and
WithTimeoutUnlessSet for operation-level deadlines when callers use Background.
Wire NewOpenAIClient/NewGenAIClient everywhere clients are constructed.
Apply Search timeouts for DALL-E and Nano Banana, provider audio timeouts,
model-list timeouts, Veo operation timeouts, story page download context,
and single-word CLI processing cap.
Made-with: Cursor
Diffstat (limited to 'internal/models')
| -rw-r--r-- | internal/models/lister.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/internal/models/lister.go b/internal/models/lister.go index ca3d3a2..2f05988 100644 --- a/internal/models/lister.go +++ b/internal/models/lister.go @@ -10,6 +10,8 @@ import ( "github.com/sashabaranov/go-openai" "google.golang.org/genai" + + "codeberg.org/snonux/totalrecall/internal/httpctx" ) type openAIModelLister interface { @@ -43,11 +45,11 @@ func NewLister(openAIKey, geminiKey string, out io.Writer) *Lister { } if lister.openAIKey != "" { - lister.openAIClient = openai.NewClient(lister.openAIKey) + lister.openAIClient = httpctx.NewOpenAIClient(lister.openAIKey) } if lister.geminiKey != "" { - client, err := genai.NewClient(context.Background(), &genai.ClientConfig{ + client, err := httpctx.NewGenAIClient(context.Background(), &genai.ClientConfig{ APIKey: lister.geminiKey, }) if err != nil { @@ -97,7 +99,10 @@ func (l *Lister) printOpenAIModels() error { return fmt.Errorf("OpenAI client not initialized") } - models, err := l.openAIClient.ListModels(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), httpctx.ListModelsTimeout) + defer cancel() + + models, err := l.openAIClient.ListModels(ctx) if err != nil { return fmt.Errorf("failed to list OpenAI models: %w", err) } @@ -193,7 +198,9 @@ func (l *Lister) printGeminiModels() error { return fmt.Errorf("gemini client not initialized") } - ctx := context.Background() + ctx, cancel := context.WithTimeout(context.Background(), httpctx.ListModelsTimeout) + defer cancel() + config := &genai.ListModelsConfig{ QueryBase: genai.Ptr(true), } |
