mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
configurable timeout
This commit is contained in:
3
env.go
3
env.go
@@ -23,6 +23,7 @@ type EnvSettings struct {
|
||||
TitleModel string `json:"title-model"`
|
||||
ImageGeneration bool `json:"image-generation"`
|
||||
Transformation string `json:"transformation"`
|
||||
Timeout int64 `json:"timeout"`
|
||||
}
|
||||
|
||||
type EnvUI struct {
|
||||
@@ -55,6 +56,7 @@ var env = Environment{
|
||||
Settings: EnvSettings{
|
||||
CleanContent: true,
|
||||
ImageGeneration: true,
|
||||
Timeout: 300,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -176,6 +178,7 @@ func (e *Environment) Store() error {
|
||||
"$.settings.title-model": {yaml.HeadComment(" model used to generate titles (needs to have structured output support; default: google/gemini-2.5-flash-lite)")},
|
||||
"$.settings.image-generation": {yaml.HeadComment(" allow image generation (optional; default: true)")},
|
||||
"$.settings.transformation": {yaml.HeadComment(" what transformation method to use for too long contexts (optional; default: middle-out)")},
|
||||
"$.settings.timeout": {yaml.HeadComment(" the http timeout to use for completion requests in seconds (optional; default: 300s)")},
|
||||
|
||||
"$.ui.reduced-motion": {yaml.HeadComment(" disables things like the floating stars in the background (optional; default: false)")},
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/revrost/go-openrouter"
|
||||
)
|
||||
@@ -12,7 +14,22 @@ func init() {
|
||||
}
|
||||
|
||||
func OpenRouterClient() *openrouter.Client {
|
||||
return openrouter.NewClient(env.Tokens.OpenRouter, openrouter.WithXTitle("Whiskr"), openrouter.WithHTTPReferer("https://github.com/coalaura/whiskr"))
|
||||
timeout := env.Settings.Timeout
|
||||
|
||||
if timeout <= 0 {
|
||||
timeout = 1
|
||||
}
|
||||
|
||||
cc := openrouter.DefaultConfig(env.Tokens.OpenRouter)
|
||||
|
||||
cc.XTitle = "Whiskr"
|
||||
cc.HttpReferer = "https://github.com/coalaura/whiskr"
|
||||
|
||||
cc.HTTPClient = &http.Client{
|
||||
Timeout: time.Duration(timeout) * time.Second,
|
||||
}
|
||||
|
||||
return openrouter.NewClientWithConfig(*cc)
|
||||
}
|
||||
|
||||
func OpenRouterStartStream(ctx context.Context, request openrouter.ChatCompletionRequest) (*openrouter.ChatCompletionStream, error) {
|
||||
|
||||
Reference in New Issue
Block a user