🔧 refactor(dto): update BudgetTokens handling in Thinking struct
This commit is contained in:
@@ -178,7 +178,14 @@ type ClaudeRequest struct {
|
|||||||
|
|
||||||
type Thinking struct {
|
type Thinking struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
BudgetTokens int `json:"budget_tokens"`
|
BudgetTokens *int `json:"budget_tokens,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Thinking) GetBudgetTokens() int {
|
||||||
|
if c.BudgetTokens == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return *c.BudgetTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClaudeRequest) IsStringSystem() bool {
|
func (c *ClaudeRequest) IsStringSystem() bool {
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ func RequestOpenAI2ClaudeMessage(textRequest dto.GeneralOpenAIRequest) (*dto.Cla
|
|||||||
// BudgetTokens 为 max_tokens 的 80%
|
// BudgetTokens 为 max_tokens 的 80%
|
||||||
claudeRequest.Thinking = &dto.Thinking{
|
claudeRequest.Thinking = &dto.Thinking{
|
||||||
Type: "enabled",
|
Type: "enabled",
|
||||||
BudgetTokens: int(float64(claudeRequest.MaxTokens) * model_setting.GetClaudeSettings().ThinkingAdapterBudgetTokensPercentage),
|
BudgetTokens: common.GetPointer[int](int(float64(claudeRequest.MaxTokens) * model_setting.GetClaudeSettings().ThinkingAdapterBudgetTokensPercentage)),
|
||||||
}
|
}
|
||||||
// TODO: 临时处理
|
// TODO: 临时处理
|
||||||
// https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking
|
// https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ func ClaudeHelper(c *gin.Context) (claudeError *dto.ClaudeErrorWithStatusCode) {
|
|||||||
// BudgetTokens 为 max_tokens 的 80%
|
// BudgetTokens 为 max_tokens 的 80%
|
||||||
textRequest.Thinking = &dto.Thinking{
|
textRequest.Thinking = &dto.Thinking{
|
||||||
Type: "enabled",
|
Type: "enabled",
|
||||||
BudgetTokens: int(float64(textRequest.MaxTokens) * model_setting.GetClaudeSettings().ThinkingAdapterBudgetTokensPercentage),
|
BudgetTokens: common.GetPointer[int](int(float64(textRequest.MaxTokens) * model_setting.GetClaudeSettings().ThinkingAdapterBudgetTokensPercentage)),
|
||||||
}
|
}
|
||||||
// TODO: 临时处理
|
// TODO: 临时处理
|
||||||
// https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking
|
// https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
|
|||||||
|
|
||||||
isOpenRouter := info.ChannelType == common.ChannelTypeOpenRouter
|
isOpenRouter := info.ChannelType == common.ChannelTypeOpenRouter
|
||||||
|
|
||||||
if claudeRequest.Thinking != nil {
|
if claudeRequest.Thinking != nil && claudeRequest.Thinking.Type == "enabled" {
|
||||||
if isOpenRouter {
|
if isOpenRouter {
|
||||||
reasoning := openrouter.RequestReasoning{
|
reasoning := openrouter.RequestReasoning{
|
||||||
MaxTokens: claudeRequest.Thinking.BudgetTokens,
|
MaxTokens: claudeRequest.Thinking.GetBudgetTokens(),
|
||||||
}
|
}
|
||||||
reasoningJSON, err := json.Marshal(reasoning)
|
reasoningJSON, err := json.Marshal(reasoning)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user