MCPcopy Create free account
hub / github.com/astercloud/aster / NewCustomProvider

Function NewCustomProvider

pkg/provider/openai_compatible.go:71–97  ·  view source on GitHub ↗

NewCustomProvider 创建自定义 OpenAI 兼容 Provider(简化版) 用于用户自带 API Key 场景,如 new-api、API2D 等

(config *types.ModelConfig)

Source from the content-addressed store, hash-verified

69// NewCustomProvider 创建自定义 OpenAI 兼容 Provider(简化版)
70// 用于用户自带 API Key 场景,如 new-api、API2D 等
71func 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
100func NewOpenAICompatibleProvider(

Callers 4

CreateMethod · 0.85
TestCustomProviderFunction · 0.85
NewGatewayProviderFunction · 0.85

Calls 1

Tested by 2

TestCustomProviderFunction · 0.68