mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-19 02:17:46 +00:00
Port the internal/thinking package from CLIProxyAPI for unified thinking configuration processing across all AI providers. Features: - Core types: ThinkingConfig, ThinkingMode, ThinkingLevel, SuffixResult - Suffix parsing: model-name(16384) or model-name(high) syntax - Validation: auto-conversion between budget/level formats, clamping - Provider appliers: claude, gemini, antigravity, openai, codex - Config extraction: extract thinking config from various request formats - Stripping: remove thinking config for non-supporting models Registry updates: - Add UserDefined field to ModelInfo for passthrough behavior - Add LookupModelInfo function for model capability lookup
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package thinking
|
|
|
|
import (
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
// GetThinkingText extracts the thinking text from a content part.
|
|
// Handles various formats:
|
|
// - Simple string: { "thinking": "text" } or { "text": "text" }
|
|
// - Wrapped object: { "thinking": { "text": "text", "cache_control": {...} } }
|
|
// - Gemini-style: { "thought": true, "text": "text" }
|
|
// Returns the extracted text string.
|
|
func GetThinkingText(part gjson.Result) string {
|
|
// Try direct text field first (Gemini-style)
|
|
if text := part.Get("text"); text.Exists() && text.Type == gjson.String {
|
|
return text.String()
|
|
}
|
|
|
|
// Try thinking field
|
|
thinkingField := part.Get("thinking")
|
|
if !thinkingField.Exists() {
|
|
return ""
|
|
}
|
|
|
|
// thinking is a string
|
|
if thinkingField.Type == gjson.String {
|
|
return thinkingField.String()
|
|
}
|
|
|
|
// thinking is an object with inner text/thinking
|
|
if thinkingField.IsObject() {
|
|
if inner := thinkingField.Get("text"); inner.Exists() && inner.Type == gjson.String {
|
|
return inner.String()
|
|
}
|
|
if inner := thinkingField.Get("thinking"); inner.Exists() && inner.Type == gjson.String {
|
|
return inner.String()
|
|
}
|
|
}
|
|
|
|
return ""
|
|
}
|