feat: 支持gemini官方openai兼容
This commit is contained in:
@@ -36,9 +36,13 @@ func newGeminiChannel(f *Factory, group *models.Group) (ChannelProxy, error) {
|
|||||||
|
|
||||||
// ModifyRequest adds the API key as a query parameter for Gemini requests.
|
// ModifyRequest adds the API key as a query parameter for Gemini requests.
|
||||||
func (ch *GeminiChannel) ModifyRequest(req *http.Request, apiKey *models.APIKey, group *models.Group) {
|
func (ch *GeminiChannel) ModifyRequest(req *http.Request, apiKey *models.APIKey, group *models.Group) {
|
||||||
q := req.URL.Query()
|
if strings.Contains(req.URL.Path, "v1beta/openai") {
|
||||||
q.Set("key", apiKey.KeyValue)
|
req.Header.Set("Authorization", "Bearer "+apiKey.KeyValue)
|
||||||
req.URL.RawQuery = q.Encode()
|
} else {
|
||||||
|
q := req.URL.Query()
|
||||||
|
q.Set("key", apiKey.KeyValue)
|
||||||
|
req.URL.RawQuery = q.Encode()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsStreamRequest checks if the request is for a streaming response.
|
// IsStreamRequest checks if the request is for a streaming response.
|
||||||
@@ -56,6 +60,14 @@ func (ch *GeminiChannel) IsStreamRequest(c *gin.Context, bodyBytes []byte) bool
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type streamPayload struct {
|
||||||
|
Stream bool `json:"stream"`
|
||||||
|
}
|
||||||
|
var p streamPayload
|
||||||
|
if err := json.Unmarshal(bodyBytes, &p); err == nil {
|
||||||
|
return p.Stream
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user