From 96ffbd5cf53c448bdfc0d86f1e7e866a358e01bd Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sat, 21 Feb 2026 16:26:13 +0300 Subject: Feat: openrouter reasoning --- models/models.go | 1 + models/openrouter.go | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index 8f42795..b089ecd 100644 --- a/models/models.go +++ b/models/models.go @@ -86,6 +86,7 @@ type TextChunk struct { ToolResp bool FuncName string ToolID string + Reasoning string // For models that send reasoning separately (OpenRouter, etc.) } type TextContentPart struct { diff --git a/models/openrouter.go b/models/openrouter.go index 6196498..62709a1 100644 --- a/models/openrouter.go +++ b/models/openrouter.go @@ -25,17 +25,23 @@ func NewOpenRouterCompletionReq(model, prompt string, props map[string]float32, } type OpenRouterChatReq struct { - Messages []RoleMsg `json:"messages"` - Model string `json:"model"` - Stream bool `json:"stream"` - Temperature float32 `json:"temperature"` - MinP float32 `json:"min_p"` - NPredict int32 `json:"max_tokens"` - Tools []Tool `json:"tools"` + Messages []RoleMsg `json:"messages"` + Model string `json:"model"` + Stream bool `json:"stream"` + Temperature float32 `json:"temperature"` + MinP float32 `json:"min_p"` + NPredict int32 `json:"max_tokens"` + Tools []Tool `json:"tools"` + Reasoning *ReasoningConfig `json:"reasoning,omitempty"` } -func NewOpenRouterChatReq(cb ChatBody, props map[string]float32) OpenRouterChatReq { - return OpenRouterChatReq{ +type ReasoningConfig struct { + Effort string `json:"effort,omitempty"` // xhigh, high, medium, low, minimal, none + Summary string `json:"summary,omitempty"` // auto, concise, detailed +} + +func NewOpenRouterChatReq(cb ChatBody, props map[string]float32, reasoningEffort string) OpenRouterChatReq { + req := OpenRouterChatReq{ Messages: cb.Messages, Model: cb.Model, Stream: cb.Stream, @@ -43,6 +49,13 @@ func NewOpenRouterChatReq(cb ChatBody, props map[string]float32) OpenRouterChatR MinP: props["min_p"], NPredict: int32(props["n_predict"]), } + // Only include reasoning config if effort is specified and not "none" + if reasoningEffort != "" && reasoningEffort != "none" { + req.Reasoning = &ReasoningConfig{ + Effort: reasoningEffort, + } + } + return req } type OpenRouterChatRespNonStream struct { @@ -82,6 +95,7 @@ type OpenRouterChatResp struct { Delta struct { Role string `json:"role"` Content string `json:"content"` + Reasoning string `json:"reasoning"` ToolCalls []ToolDeltaResp `json:"tool_calls"` } `json:"delta"` FinishReason string `json:"finish_reason"` -- cgit v1.2.3