NewCustomProvider 创建自定义 OpenAI 兼容 Provider(简化版) 用于用户自带 API Key 场景,如 new-api、API2D 等
(config *types.ModelConfig)
| 69 | // NewCustomProvider 创建自定义 OpenAI 兼容 Provider(简化版) |
| 70 | // 用于用户自带 API Key 场景,如 new-api、API2D 等 |
| 71 | func NewCustomProvider(config *types.ModelConfig) (*OpenAICompatibleProvider, error) { |
| 72 | if config.BaseURL == "" { |
| 73 | return nil, errors.New("custom provider: base_url is required") |
| 74 | } |
| 75 | if config.APIKey == "" { |
| 76 | return nil, errors.New("custom provider: api_key is required") |
| 77 | } |
| 78 | |
| 79 | providerName := "custom" |
| 80 | if config.Provider != "" { |
| 81 | providerName = config.Provider |
| 82 | } |
| 83 | |
| 84 | return NewOpenAICompatibleProvider( |
| 85 | config, |
| 86 | strings.TrimSuffix(config.BaseURL, "/"), |
| 87 | providerName, |
| 88 | &OpenAICompatibleOptions{ |
| 89 | RequireAPIKey: true, |
| 90 | Timeout: 5 * time.Minute, |
| 91 | MaxRetries: 3, |
| 92 | RetryDelay: 1 * time.Second, |
| 93 | RetryOn429: true, |
| 94 | RetryOn500: true, |
| 95 | }, |
| 96 | ) |
| 97 | } |
| 98 | |
| 99 | // NewOpenAICompatibleProvider 创建 OpenAI 兼容 Provider |
| 100 | func NewOpenAICompatibleProvider( |