Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/ollama/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion pkg/ollama/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down