mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-05 08:13:43 +08:00
feat: update README and enhance response handling for Claude model to support reasoning and thinking
This commit is contained in:
@@ -26,7 +26,7 @@ Also welcome to register and use my deployed one-api gateway, which supports var
|
||||
- [Support o3-mini](#support-o3-mini)
|
||||
- [Support gemini-2.0-flash](#support-gemini-20-flash)
|
||||
- [Support OpenRouter's reasoning content](#support-openrouters-reasoning-content)
|
||||
- [Support claude-3-7-sonnet #2143](#support-claude-3-7-sonnet-2143)
|
||||
- [Support claude-3-7-sonnet \& thinking](#support-claude-3-7-sonnet--thinking)
|
||||
- [Bug fix](#bug-fix)
|
||||
|
||||
## New Features
|
||||
@@ -124,9 +124,12 @@ type UserRequestCost struct {
|
||||
|
||||
- [feat: support OpenRouter reasoning #2108](https://github.com/songquanpeng/one-api/pull/2108)
|
||||
|
||||
### Support claude-3-7-sonnet #2143
|
||||
### Support claude-3-7-sonnet & thinking
|
||||
|
||||
- [feat: support claude-3-7-sonnet #2143](https://github.com/songquanpeng/one-api/pull/2143/files)
|
||||
- [feat: support claude thinking #2144](https://github.com/songquanpeng/one-api/pull/2144)
|
||||
|
||||

|
||||
|
||||
## Bug fix
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package anthropic
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -235,9 +236,17 @@ func ResponseClaude2OpenAI(claudeResponse *Response) *openai.TextResponse {
|
||||
|
||||
tools := make([]model.Tool, 0)
|
||||
for _, v := range claudeResponse.Content {
|
||||
reasoningText += v.Text
|
||||
if v.Thinking != nil {
|
||||
reasoningText += *v.Thinking
|
||||
switch v.Type {
|
||||
case "thinking":
|
||||
if v.Thinking != nil {
|
||||
reasoningText += *v.Thinking
|
||||
} else {
|
||||
logger.Errorf(context.Background(), "thinking is nil in response")
|
||||
}
|
||||
case "text":
|
||||
responseText += v.Text
|
||||
default:
|
||||
logger.Warnf(context.Background(), "unknown response type %q", v.Type)
|
||||
}
|
||||
|
||||
if v.Type == "tool_use" {
|
||||
@@ -252,6 +261,7 @@ func ResponseClaude2OpenAI(claudeResponse *Response) *openai.TextResponse {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
choice := openai.TextResponseChoice{
|
||||
Index: 0,
|
||||
Message: model.Message{
|
||||
@@ -373,6 +383,8 @@ func Handler(c *gin.Context, resp *http.Response, promptTokens int, modelName st
|
||||
return openai.ErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), nil
|
||||
}
|
||||
|
||||
logger.Debugf(c.Request.Context(), "response <- %s\n", string(responseBody))
|
||||
|
||||
var claudeResponse Response
|
||||
err = json.Unmarshal(responseBody, &claudeResponse)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user