+22
-11
@@ -13,6 +13,7 @@ import (
|
||||
const (
|
||||
defaultOpenAIBaseURL = "https://ark.cn-beijing.volces.com/api/v3"
|
||||
defaultOpenAITimeout = 120
|
||||
defaultContextWindowTokens = 262144
|
||||
defaultToolRouterTimeout = 30
|
||||
defaultToolRouterMaxTokens = 512
|
||||
defaultToolRouterSystemText = `你可以按需直接调用可用工具来回答用户问题。
|
||||
@@ -24,13 +25,14 @@ const (
|
||||
)
|
||||
|
||||
type OpenAIConfig struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Active bool `yaml:"active,omitempty" json:"active"`
|
||||
APIKey string `yaml:"api_key" json:"-"`
|
||||
BaseURL string `yaml:"base_url" json:"base_url"`
|
||||
Model string `yaml:"model" json:"model"`
|
||||
Timeout int `yaml:"timeout" json:"timeout"`
|
||||
ParseThinkTags *bool `yaml:"parse_think_tags,omitempty" json:"parse_think_tags,omitempty"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Active bool `yaml:"active,omitempty" json:"active"`
|
||||
APIKey string `yaml:"api_key" json:"-"`
|
||||
BaseURL string `yaml:"base_url" json:"base_url"`
|
||||
Model string `yaml:"model" json:"model"`
|
||||
Timeout int `yaml:"timeout" json:"timeout"`
|
||||
ContextWindowTokens int `yaml:"context_window_tokens" json:"context_window_tokens"`
|
||||
ParseThinkTags *bool `yaml:"parse_think_tags,omitempty" json:"parse_think_tags,omitempty"`
|
||||
}
|
||||
|
||||
type OpenAIConfigs []OpenAIConfig
|
||||
@@ -87,10 +89,11 @@ type Config struct {
|
||||
|
||||
func defaultOpenAIConfig() OpenAIConfig {
|
||||
return OpenAIConfig{
|
||||
Name: "default",
|
||||
Active: true,
|
||||
BaseURL: defaultOpenAIBaseURL,
|
||||
Timeout: defaultOpenAITimeout,
|
||||
Name: "default",
|
||||
Active: true,
|
||||
BaseURL: defaultOpenAIBaseURL,
|
||||
Timeout: defaultOpenAITimeout,
|
||||
ContextWindowTokens: defaultContextWindowTokens,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,6 +212,10 @@ func ensureFile(path string) error {
|
||||
return Write(path, cfg)
|
||||
}
|
||||
|
||||
func NormalizeOpenAIConfigs(cfg *Config) (bool, error) {
|
||||
return normalizeOpenAIConfigs(cfg)
|
||||
}
|
||||
|
||||
func normalizeOpenAIConfigs(cfg *Config) (bool, error) {
|
||||
changed := false
|
||||
if len(cfg.OpenAI) == 0 {
|
||||
@@ -245,6 +252,10 @@ func normalizeOpenAIConfigs(cfg *Config) (bool, error) {
|
||||
profile.Timeout = defaultOpenAITimeout
|
||||
changed = true
|
||||
}
|
||||
if profile.ContextWindowTokens <= 0 {
|
||||
profile.ContextWindowTokens = defaultContextWindowTokens
|
||||
changed = true
|
||||
}
|
||||
if profile.Active {
|
||||
if activeIndex == -1 {
|
||||
activeIndex = i
|
||||
|
||||
Reference in New Issue
Block a user