diff options
| author | Xe Iaso <me@xeiaso.net> | 2024-09-07 11:53:06 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2024-09-07 11:53:06 -0400 |
| commit | 0bc8663d0f6faf773e05767a75f25a292387f784 (patch) | |
| tree | 0a584322bd5aaaeb535dccb1bd0aeadabbfe5655 /web | |
| parent | a96c8927da0fff4b2c1fd7ef7237cbaac3936ebf (diff) | |
| download | x-0bc8663d0f6faf773e05767a75f25a292387f784.tar.xz x-0bc8663d0f6faf773e05767a75f25a292387f784.zip | |
web/ollama: make default keepalive measured in days
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'web')
| -rw-r--r-- | web/ollama/ollama.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/web/ollama/ollama.go b/web/ollama/ollama.go index 7210c58..a5c71c3 100644 --- a/web/ollama/ollama.go +++ b/web/ollama/ollama.go @@ -76,13 +76,14 @@ type Message struct { } type CompleteRequest struct { - Model string `json:"model"` - Messages []Message `json:"messages"` - Format *string `json:"format,omitempty"` - Template *string `json:"template,omitempty"` - Stream bool `json:"stream"` - Options map[string]any `json:"options"` - Tools []Tool `json:"tools"` + Model string `json:"model"` + Messages []Message `json:"messages"` + Format *string `json:"format,omitempty"` + Template *string `json:"template,omitempty"` + Stream bool `json:"stream"` + Options map[string]any `json:"options"` + Tools []Tool `json:"tools"` + KeepAlive string `json:"keep_alive"` } type CompleteResponse struct { @@ -99,6 +100,10 @@ type CompleteResponse struct { } func (c *Client) Chat(ctx context.Context, inp *CompleteRequest) (*CompleteResponse, error) { + if inp.KeepAlive == "" { + inp.KeepAlive = (9999 * time.Minute).String() + } + buf := &bytes.Buffer{} if err := json.NewEncoder(buf).Encode(inp); err != nil { return nil, fmt.Errorf("ollama: error encoding request: %w", err) @@ -144,10 +149,11 @@ func p[T any](v T) *T { // Hallucinate prompts the model to hallucinate a "valid" JSON response to the given input. func Hallucinate[T valid.Interface](ctx context.Context, c *Client, opts HallucinateOpts) (*T, error) { inp := &CompleteRequest{ - Model: opts.Model, - Messages: opts.Messages, - Format: p("json"), - Stream: true, + Model: opts.Model, + Messages: opts.Messages, + Format: p("json"), + Stream: true, + KeepAlive: (9999 * time.Minute).String(), } tries := 0 for tries <= 5 { @@ -306,6 +312,10 @@ type GenerateResponse struct { } func (c *Client) Generate(ctx context.Context, gr *GenerateRequest) (*GenerateResponse, error) { + if gr.KeepAlive == "" { + gr.KeepAlive = (9999 * time.Minute).String() + } + buf := &bytes.Buffer{} if err := json.NewEncoder(buf).Encode(gr); err != nil { return nil, fmt.Errorf("ollama: error encoding request: %w", err) |
