feat: add support for openrouter reasoning efforts in request handling
This commit is contained in:
@@ -188,6 +188,7 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
|
|||||||
if len(request.Usage) == 0 {
|
if len(request.Usage) == 0 {
|
||||||
request.Usage = json.RawMessage(`{"include":true}`)
|
request.Usage = json.RawMessage(`{"include":true}`)
|
||||||
}
|
}
|
||||||
|
// 适配 OpenRouter 的 thinking 后缀
|
||||||
if strings.HasSuffix(info.UpstreamModelName, "-thinking") {
|
if strings.HasSuffix(info.UpstreamModelName, "-thinking") {
|
||||||
info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking")
|
info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-thinking")
|
||||||
request.Model = info.UpstreamModelName
|
request.Model = info.UpstreamModelName
|
||||||
@@ -195,7 +196,7 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
|
|||||||
reasoning := map[string]any{
|
reasoning := map[string]any{
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
}
|
}
|
||||||
if request.ReasoningEffort != "" {
|
if request.ReasoningEffort != "" && request.ReasoningEffort != "none" {
|
||||||
reasoning["effort"] = request.ReasoningEffort
|
reasoning["effort"] = request.ReasoningEffort
|
||||||
}
|
}
|
||||||
marshal, err := common.Marshal(reasoning)
|
marshal, err := common.Marshal(reasoning)
|
||||||
@@ -204,6 +205,23 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
|
|||||||
}
|
}
|
||||||
request.Reasoning = marshal
|
request.Reasoning = marshal
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if len(request.Reasoning) == 0 {
|
||||||
|
// 适配 OpenAI 的 ReasoningEffort 格式
|
||||||
|
if request.ReasoningEffort != "" {
|
||||||
|
reasoning := map[string]any{
|
||||||
|
"enabled": true,
|
||||||
|
}
|
||||||
|
if request.ReasoningEffort != "none" {
|
||||||
|
reasoning["effort"] = request.ReasoningEffort
|
||||||
|
marshal, err := common.Marshal(reasoning)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error marshalling reasoning: %w", err)
|
||||||
|
}
|
||||||
|
request.Reasoning = marshal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(request.Model, "o") || strings.HasPrefix(request.Model, "gpt-5") {
|
if strings.HasPrefix(request.Model, "o") || strings.HasPrefix(request.Model, "gpt-5") {
|
||||||
|
|||||||
Reference in New Issue
Block a user