diff --git a/pkg/ollama/api.go b/pkg/ollama/api.go index c70cbd50..2493cec9 100644 --- a/pkg/ollama/api.go +++ b/pkg/ollama/api.go @@ -66,6 +66,7 @@ type Message struct { Images []string `json:"images,omitempty"` // For multimodal support ToolCalls []ToolCall `json:"tool_calls,omitempty"` // For function calling ToolCallID string `json:"tool_call_id,omitempty"` // For tool results + Thinking string `json:"thinking,omitempty"` // Internal field for model's thinking output } // ToolCall represents a function call made by the model diff --git a/pkg/ollama/http_handler.go b/pkg/ollama/http_handler.go index 46a15219..b854d4e2 100644 --- a/pkg/ollama/http_handler.go +++ b/pkg/ollama/http_handler.go @@ -1056,11 +1056,13 @@ func (s *streamingChatResponseWriter) Write(data []byte) (int, error) { continue } - // Extract content and tool calls from structured response + // Extract content, tool calls, and thinking from structured response var content string + var thinking string var toolCalls []ToolCall if len(chunk.Choices) > 0 { content = chunk.Choices[0].Delta.Content + thinking = chunk.Choices[0].Delta.ReasoningContent if len(chunk.Choices[0].Delta.ToolCalls) > 0 { // Convert tool calls to Ollama format toolCalls = convertToolCallsToOllamaFormat(chunk.Choices[0].Delta.ToolCalls) @@ -1075,6 +1077,9 @@ func (s *streamingChatResponseWriter) Write(data []byte) (int, error) { if len(toolCalls) > 0 { message.ToolCalls = toolCalls } + if thinking != "" { + message.Thinking = thinking + } ollamaChunk := ChatResponse{ Model: s.modelName, @@ -1242,6 +1247,10 @@ func (h *HTTPHandler) convertChatResponse(w http.ResponseWriter, respRecorder *r if len(openAIResp.Choices[0].Message.ToolCalls) > 0 { message.ToolCalls = convertToolCallsToOllamaFormat(openAIResp.Choices[0].Message.ToolCalls) } + // Include thinking content if present + if openAIResp.Choices[0].Message.ReasoningContent != "" { + message.Thinking = openAIResp.Choices[0].Message.ReasoningContent + } } // Build Ollama response