diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-17 23:03:24 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-17 23:03:24 +0300 |
| commit | d72f95ae4e6cd4e7a0beca2b9764511c10de8655 (patch) | |
| tree | d5b034abce358cc26f271c3fc492d97da6e5734c /internal/llm/ollama.go | |
| parent | 8dfbbbb6de0f0c67413ee157e976fc3eaee4f914 (diff) | |
refactor(ordering): types/constants first; exported before private; ensure consistent receiver semantics per file
Diffstat (limited to 'internal/llm/ollama.go')
| -rw-r--r-- | internal/llm/ollama.go | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/internal/llm/ollama.go b/internal/llm/ollama.go index a53716b..a796d8c 100644 --- a/internal/llm/ollama.go +++ b/internal/llm/ollama.go @@ -18,32 +18,17 @@ import ( // ollamaClient implements Client against a local Ollama server. type ollamaClient struct { - httpClient *http.Client - baseURL string - defaultModel string - chatLogger logging.ChatLogger -} - -func newOllama(baseURL, model string) Client { - if strings.TrimSpace(baseURL) == "" { - baseURL = "http://localhost:11434" - } - if strings.TrimSpace(model) == "" { - model = "qwen2.5-coder:latest" - } - return ollamaClient{ - httpClient: &http.Client{Timeout: 30 * time.Second}, - baseURL: strings.TrimRight(baseURL, "/"), - defaultModel: model, - chatLogger: logging.NewChatLogger("ollama"), - } + httpClient *http.Client + baseURL string + defaultModel string + chatLogger logging.ChatLogger } type ollamaChatRequest struct { - Model string `json:"model"` - Messages []oaMessage `json:"messages"` - Stream bool `json:"stream"` - Options any `json:"options,omitempty"` + Model string `json:"model"` + Messages []oaMessage `json:"messages"` + Stream bool `json:"stream"` + Options any `json:"options,omitempty"` } type ollamaChatResponse struct { @@ -240,6 +225,22 @@ func (c ollamaClient) ChatStream(ctx context.Context, messages []Message, onDelt break } } - logging.Logf("llm/ollama ", "stream end duration=%s", time.Since(start)) - return nil + logging.Logf("llm/ollama ", "stream end duration=%s", time.Since(start)) + return nil +} + +// Private constructor +func newOllama(baseURL, model string) Client { + if strings.TrimSpace(baseURL) == "" { + baseURL = "http://localhost:11434" + } + if strings.TrimSpace(model) == "" { + model = "qwen2.5-coder:latest" + } + return ollamaClient{ + httpClient: &http.Client{Timeout: 30 * time.Second}, + baseURL: strings.TrimRight(baseURL, "/"), + defaultModel: model, + chatLogger: logging.NewChatLogger("ollama"), + } } |
