| package model_setting
|
|
|
| import (
|
| "net/http"
|
|
|
| "github.com/QuantumNous/new-api/setting/config"
|
| )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| type ClaudeSettings struct {
|
| HeadersSettings map[string]map[string][]string `json:"model_headers_settings"`
|
| DefaultMaxTokens map[string]int `json:"default_max_tokens"`
|
| ThinkingAdapterEnabled bool `json:"thinking_adapter_enabled"`
|
| ThinkingAdapterBudgetTokensPercentage float64 `json:"thinking_adapter_budget_tokens_percentage"`
|
| }
|
|
|
|
|
| var defaultClaudeSettings = ClaudeSettings{
|
| HeadersSettings: map[string]map[string][]string{},
|
| ThinkingAdapterEnabled: true,
|
| DefaultMaxTokens: map[string]int{
|
| "default": 8192,
|
| },
|
| ThinkingAdapterBudgetTokensPercentage: 0.8,
|
| }
|
|
|
|
|
| var claudeSettings = defaultClaudeSettings
|
|
|
| func init() {
|
|
|
| config.GlobalConfig.Register("claude", &claudeSettings)
|
| }
|
|
|
|
|
| func GetClaudeSettings() *ClaudeSettings {
|
|
|
| if _, ok := claudeSettings.DefaultMaxTokens["default"]; !ok {
|
| claudeSettings.DefaultMaxTokens["default"] = 8192
|
| }
|
| return &claudeSettings
|
| }
|
|
|
| func (c *ClaudeSettings) WriteHeaders(originModel string, httpHeader *http.Header) {
|
| if headers, ok := c.HeadersSettings[originModel]; ok {
|
| for headerKey, headerValues := range headers {
|
|
|
| existingValues := httpHeader.Values(headerKey)
|
| existingValuesMap := make(map[string]bool)
|
| for _, v := range existingValues {
|
| existingValuesMap[v] = true
|
| }
|
|
|
|
|
| for _, headerValue := range headerValues {
|
| if !existingValuesMap[headerValue] {
|
| httpHeader.Add(headerKey, headerValue)
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| func (c *ClaudeSettings) GetDefaultMaxTokens(model string) int {
|
| if maxTokens, ok := c.DefaultMaxTokens[model]; ok {
|
| return maxTokens
|
| }
|
| return c.DefaultMaxTokens["default"]
|
| }
|
|
|