adding reasoning high parameter and parsing reasoning content
This commit is contained in:
parent
13e4028d42
commit
3407bf3055
1 changed files with 16 additions and 3 deletions
|
|
@ -90,6 +90,12 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too
|
|||
}
|
||||
}
|
||||
|
||||
// K2-Think models require reasoning_effort parameter for proper tool calling
|
||||
lowerModel := strings.ToLower(model)
|
||||
if strings.Contains(lowerModel, "k2-think") {
|
||||
requestBody["reasoning_effort"] = "high"
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal request: %w", err)
|
||||
|
|
@ -128,6 +134,7 @@ func (p *HTTPProvider) parseResponse(body []byte) (*LLMResponse, error) {
|
|||
Choices []struct {
|
||||
Message struct {
|
||||
Content string `json:"content"`
|
||||
ReasoningContent string `json:"reasoning_content"` // For reasoning models like K2-Think
|
||||
ToolCalls []struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
|
|
@ -185,8 +192,14 @@ func (p *HTTPProvider) parseResponse(body []byte) (*LLMResponse, error) {
|
|||
})
|
||||
}
|
||||
|
||||
// For reasoning models (like K2-Think), use reasoning_content if content is null/empty
|
||||
content := choice.Message.Content
|
||||
if content == "" && choice.Message.ReasoningContent != "" {
|
||||
content = choice.Message.ReasoningContent
|
||||
}
|
||||
|
||||
return &LLMResponse{
|
||||
Content: choice.Message.Content,
|
||||
Content: content,
|
||||
ToolCalls: toolCalls,
|
||||
FinishReason: choice.FinishReason,
|
||||
Usage: apiResponse.Usage,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue