Commit d829958f by Seefs

fix: reason convert

parent 0e76cc3f
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"github.com/QuantumNous/new-api/relay/channel/openrouter" "github.com/QuantumNous/new-api/relay/channel/openrouter"
relaycommon "github.com/QuantumNous/new-api/relay/common" relaycommon "github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/relay/helper" "github.com/QuantumNous/new-api/relay/helper"
"github.com/QuantumNous/new-api/relay/reasonmap"
"github.com/QuantumNous/new-api/service" "github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/setting/model_setting" "github.com/QuantumNous/new-api/setting/model_setting"
"github.com/QuantumNous/new-api/types" "github.com/QuantumNous/new-api/types"
...@@ -28,18 +29,7 @@ const ( ...@@ -28,18 +29,7 @@ const (
) )
func stopReasonClaude2OpenAI(reason string) string { func stopReasonClaude2OpenAI(reason string) string {
switch reason { return reasonmap.ClaudeStopReasonToOpenAIFinishReason(reason)
case "stop_sequence":
return "stop"
case "end_turn":
return "stop"
case "max_tokens":
return "length"
case "tool_use":
return "tool_calls"
default:
return reason
}
} }
func maybeMarkClaudeRefusal(c *gin.Context, stopReason string) { func maybeMarkClaudeRefusal(c *gin.Context, stopReason string) {
......
package reasonmap
import (
"strings"
"github.com/QuantumNous/new-api/constant"
)
func ClaudeStopReasonToOpenAIFinishReason(stopReason string) string {
switch strings.ToLower(stopReason) {
case "stop_sequence":
return "stop"
case "end_turn":
return "stop"
case "max_tokens":
return "length"
case "tool_use":
return "tool_calls"
case "refusal":
return constant.FinishReasonContentFilter
default:
return stopReason
}
}
func OpenAIFinishReasonToClaudeStopReason(finishReason string) string {
switch strings.ToLower(finishReason) {
case "stop":
return "end_turn"
case "stop_sequence":
return "stop_sequence"
case "length", "max_tokens":
return "max_tokens"
case constant.FinishReasonContentFilter:
return "refusal"
case "tool_calls":
return "tool_use"
default:
return finishReason
}
}
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/QuantumNous/new-api/dto" "github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/relay/channel/openrouter" "github.com/QuantumNous/new-api/relay/channel/openrouter"
relaycommon "github.com/QuantumNous/new-api/relay/common" relaycommon "github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/relay/reasonmap"
) )
func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.RelayInfo) (*dto.GeneralOpenAIRequest, error) { func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.RelayInfo) (*dto.GeneralOpenAIRequest, error) {
...@@ -540,20 +541,7 @@ func ResponseOpenAI2Claude(openAIResponse *dto.OpenAITextResponse, info *relayco ...@@ -540,20 +541,7 @@ func ResponseOpenAI2Claude(openAIResponse *dto.OpenAITextResponse, info *relayco
} }
func stopReasonOpenAI2Claude(reason string) string { func stopReasonOpenAI2Claude(reason string) string {
switch reason { return reasonmap.OpenAIFinishReasonToClaudeStopReason(reason)
case "stop":
return "end_turn"
case "stop_sequence":
return "stop_sequence"
case "length":
fallthrough
case "max_tokens":
return "max_tokens"
case "tool_calls":
return "tool_use"
default:
return reason
}
} }
func toJSONString(v interface{}) string { func toJSONString(v interface{}) string {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment