Skip to content

Commit 013326b

Browse files
FybreFybre
andauthored
feat: add configurable provider timeout (#13)
Add requestTimeoutS field to agent defaults config (default 60s). Allows users to increase timeout for slow models or congested providers. Co-authored-by: Fybre <craig@fybre.me>
1 parent 977ebdc commit 013326b

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

internal/config/schema.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type AgentDefaults struct {
1818
Temperature float64 `json:"temperature"`
1919
MaxToolIterations int `json:"maxToolIterations"`
2020
HeartbeatIntervalS int `json:"heartbeatIntervalS"`
21+
RequestTimeoutS int `json:"requestTimeoutS"`
2122
}
2223

2324
type ChannelsConfig struct {

internal/providers/factory.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import "github.com/local/picobot/internal/config"
88
// - else fallback to stub
99
func NewProviderFromConfig(cfg config.Config) LLMProvider {
1010
if cfg.Providers.OpenAI != nil && cfg.Providers.OpenAI.APIKey != "" {
11-
return NewOpenAIProvider(cfg.Providers.OpenAI.APIKey, cfg.Providers.OpenAI.APIBase)
11+
return NewOpenAIProvider(
12+
cfg.Providers.OpenAI.APIKey,
13+
cfg.Providers.OpenAI.APIBase,
14+
cfg.Agents.Defaults.RequestTimeoutS,
15+
)
1216
}
1317
return NewStubProvider()
1418
}

internal/providers/openai.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ type OpenAIProvider struct {
1919
Client *http.Client
2020
}
2121

22-
func NewOpenAIProvider(apiKey, apiBase string) *OpenAIProvider {
22+
func NewOpenAIProvider(apiKey, apiBase string, timeoutSecs int) *OpenAIProvider {
2323
if apiBase == "" {
2424
apiBase = "https://api.openai.com/v1" // sensible default; can be overridden
2525
}
26+
if timeoutSecs <= 0 {
27+
timeoutSecs = 60 // default 60 seconds
28+
}
2629
return &OpenAIProvider{
2730
APIKey: apiKey,
2831
APIBase: strings.TrimRight(apiBase, "/"),
2932
Client: &http.Client{
30-
Timeout: 60 * time.Second,
33+
Timeout: time.Duration(timeoutSecs) * time.Second,
3134
},
3235
}
3336
}

0 commit comments

Comments
 (0)