mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
33 lines
880 B
Go
33 lines
880 B
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
// extractGeminiReasoningEffortFromBody reads only an explicit level from the
|
|
// forwarded Gemini request. A budget or an omitted level does not define a
|
|
// billing level, even when the upstream model enables thinking by default.
|
|
func extractGeminiReasoningEffortFromBody(body []byte) *string {
|
|
config := gjson.GetBytes(body, "generationConfig")
|
|
if !config.Exists() {
|
|
config = gjson.GetBytes(body, "generation_config")
|
|
}
|
|
thinking := config.Get("thinkingConfig")
|
|
if !thinking.Exists() {
|
|
thinking = config.Get("thinking_config")
|
|
}
|
|
level := thinking.Get("thinkingLevel")
|
|
if !level.Exists() {
|
|
level = thinking.Get("thinking_level")
|
|
}
|
|
effort := strings.ToLower(strings.TrimSpace(level.String()))
|
|
switch effort {
|
|
case "minimal", "low", "medium", "high":
|
|
return &effort
|
|
default:
|
|
return nil
|
|
}
|
|
}
|