Skip to content

Commit 6749ba6

Browse files
committed
feat: added go sdk setup in custom providers doc
1 parent 46cdc22 commit 6749ba6

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

docs/features/custom-providers.mdx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,94 @@ curl --location 'http://localhost:8080/api/providers' \
109109

110110
</Tab>
111111

112+
<Tab title="Go SDK">
113+
114+
Create a custom provider using the Go SDK by implementing the Account interface with custom provider configuration:
115+
116+
```go
117+
package main
118+
119+
import (
120+
"context"
121+
"fmt"
122+
"os"
123+
"time"
124+
125+
"github.com/maximhq/bifrost/core/schemas"
126+
)
127+
128+
// Define custom provider name
129+
const ProviderOpenAICustom = schemas.ModelProvider("openai-custom")
130+
131+
type MyAccount struct{}
132+
133+
func (a *MyAccount) GetConfiguredProviders() ([]schemas.ModelProvider, error) {
134+
return []schemas.ModelProvider{
135+
schemas.OpenAI,
136+
ProviderOpenAICustom, // Include your custom provider
137+
}, nil
138+
}
139+
140+
func (a *MyAccount) GetKeysForProvider(ctx context.Context, provider schemas.ModelProvider) ([]schemas.Key, error) {
141+
switch provider {
142+
case schemas.OpenAI:
143+
return []schemas.Key{{
144+
Value: os.Getenv("OPENAI_API_KEY"),
145+
Models: []string{},
146+
Weight: 1.0,
147+
}}, nil
148+
case ProviderOpenAICustom:
149+
return []schemas.Key{{
150+
Value: os.Getenv("OPENAI_CUSTOM_API_KEY"), // API key for OpenAI-compatible endpoint
151+
Models: []string{},
152+
Weight: 1.0,
153+
}}, nil
154+
}
155+
return nil, fmt.Errorf("provider %s not supported", provider)
156+
}
157+
158+
func (a *MyAccount) GetConfigForProvider(provider schemas.ModelProvider) (*schemas.ProviderConfig, error) {
159+
switch provider {
160+
case schemas.OpenAI:
161+
return &schemas.ProviderConfig{
162+
NetworkConfig: schemas.DefaultNetworkConfig,
163+
ConcurrencyAndBufferSize: schemas.DefaultConcurrencyAndBufferSize,
164+
}, nil
165+
case ProviderOpenAICustom:
166+
return &schemas.ProviderConfig{
167+
NetworkConfig: schemas.NetworkConfig{
168+
BaseURL: "https://your-openai-compatible-endpoint.com", // Custom base URL
169+
DefaultRequestTimeoutInSeconds: 60,
170+
MaxRetries: 1,
171+
RetryBackoffInitial: 100 * time.Millisecond,
172+
RetryBackoffMax: 2 * time.Second,
173+
},
174+
ConcurrencyAndBufferSize: schemas.ConcurrencyAndBufferSize{
175+
Concurrency: 3,
176+
BufferSize: 10,
177+
},
178+
CustomProviderConfig: &schemas.CustomProviderConfig{
179+
BaseProviderType: schemas.OpenAI, // Use OpenAI protocol
180+
AllowedRequests: &schemas.AllowedRequests{
181+
TextCompletion: false,
182+
ChatCompletion: true, // Enable chat completion
183+
ChatCompletionStream: true, // Enable streaming
184+
Embedding: false,
185+
Speech: false,
186+
SpeechStream: false,
187+
Transcription: false,
188+
TranscriptionStream: false,
189+
},
190+
},
191+
}, nil
192+
}
193+
return nil, fmt.Errorf("provider %s not supported", provider)
194+
}
195+
196+
```
197+
198+
</Tab>
199+
112200
</Tabs>
113201

114202
## Configuration Options

0 commit comments

Comments
 (0)