Add /ai persona command, debug logging toggle, context trimming, persona override

This commit is contained in:
2026-06-16 21:11:44 +02:00
parent 31a81fbfaa
commit f038316615
7 changed files with 254 additions and 44 deletions
+22 -1
View File
@@ -9,19 +9,37 @@ import (
"time"
)
// logFunc is a callback for logging (hooked to the Mattermost plugin API).
type logFunc func(msg string, keyValuePairs ...any)
// OllamaClient communicates with the Ollama API.
type OllamaClient struct {
baseURL string
httpClient *http.Client
logInfo logFunc
logEnabled bool
}
// SetLogging enables or disables request/response logging.
func (c *OllamaClient) SetLogging(enabled bool) {
c.logEnabled = enabled
}
// NewOllamaClient creates a new client for the given Ollama server URL.
func NewOllamaClient(baseURL string) *OllamaClient {
func NewOllamaClient(baseURL string, logInfo logFunc) *OllamaClient {
return &OllamaClient{
baseURL: strings.TrimRight(baseURL, "/"),
httpClient: &http.Client{
Timeout: 30 * time.Second,
},
logInfo: logInfo,
}
}
// logRequest logs the full Ollama API request for debugging.
func (c *OllamaClient) logRequest(model, body string) {
if c.logEnabled && c.logInfo != nil {
c.logInfo("Ollama API call", "model", model, "url", c.baseURL+"/api/chat", "body", body)
}
}
@@ -113,6 +131,9 @@ func (c *OllamaClient) ChatCompletionStream(req *ChatRequest) (<-chan StreamEven
return nil, fmt.Errorf("marshal request: %w", err)
}
// Log the full API request for debugging.
c.logRequest(req.Model, string(body))
httpReq, err := http.NewRequest("POST", c.baseURL+"/api/chat", strings.NewReader(string(body)))
if err != nil {
return nil, fmt.Errorf("create request: %w", err)