try and raise ollama timeout

main
Bel LaPointe 2024-04-19 13:18:12 -06:00
parent e5e98e2890
commit 20256bd6b4
1 changed files with 13 additions and 0 deletions

13
ai.go
View File

@ -2,6 +2,8 @@ package main
import ( import (
"context" "context"
"net/http"
"time"
"github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/ollama" "github.com/tmc/langchaingo/llms/ollama"
@ -32,9 +34,20 @@ func NewAIOllama(url, model string) AIOllama {
} }
func (ai AIOllama) Do(ctx context.Context, prompt string) (string, error) { func (ai AIOllama) Do(ctx context.Context, prompt string) (string, error) {
c := &http.Client{
Timeout: time.Hour,
Transport: &http.Transport{
//DisableKeepAlives: true,
IdleConnTimeout: time.Hour,
ResponseHeaderTimeout: time.Hour,
ExpectContinueTimeout: time.Hour,
},
}
defer c.CloseIdleConnections()
llm, err := ollama.New( llm, err := ollama.New(
ollama.WithModel(ai.model), ollama.WithModel(ai.model),
ollama.WithServerURL(ai.url), ollama.WithServerURL(ai.url),
ollama.WithHTTPClient(c),
) )
if err != nil { if err != nil {
return "", err return "", err