first commit
This commit is contained in:
35
core/providers/openai/websocket.go
Normal file
35
core/providers/openai/websocket.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package openai
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/maximhq/bifrost/core/schemas"
|
||||
)
|
||||
|
||||
// SupportsWebSocketMode returns true since OpenAI natively supports the Responses API WebSocket Mode.
|
||||
func (provider *OpenAIProvider) SupportsWebSocketMode() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// WebSocketResponsesURL returns the WebSocket URL for the OpenAI Responses API.
|
||||
// Converts the HTTP base URL to a WSS URL: https://api.openai.com -> wss://api.openai.com/v1/responses
|
||||
func (provider *OpenAIProvider) WebSocketResponsesURL(key schemas.Key) string {
|
||||
base := provider.networkConfig.BaseURL
|
||||
base = strings.Replace(base, "https://", "wss://", 1)
|
||||
base = strings.Replace(base, "http://", "ws://", 1)
|
||||
return base + "/v1/responses"
|
||||
}
|
||||
|
||||
// WebSocketHeaders returns the headers required for the upstream WebSocket connection to OpenAI.
|
||||
func (provider *OpenAIProvider) WebSocketHeaders(key schemas.Key) map[string]string {
|
||||
headers := map[string]string{
|
||||
"Authorization": "Bearer " + key.Value.GetValue(),
|
||||
}
|
||||
for k, v := range provider.networkConfig.ExtraHeaders {
|
||||
if strings.EqualFold(k, "Authorization") {
|
||||
continue
|
||||
}
|
||||
headers[k] = v
|
||||
}
|
||||
return headers
|
||||
}
|
||||
Reference in New Issue
Block a user