Merge pull request #2779 from RedwindA/feat/gemini2oaiSTOP

feat(gemini): map OpenAI stop to Gemini stopSequences
This commit is contained in:
Calcium-Ion
2026-01-29 23:21:35 +08:00
committed by GitHub

View File

@@ -217,6 +217,13 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
"IMAGE",
}
}
if stopSequences := parseStopSequences(textRequest.Stop); len(stopSequences) > 0 {
// Gemini supports up to 5 stop sequences
if len(stopSequences) > 5 {
stopSequences = stopSequences[:5]
}
geminiRequest.GenerationConfig.StopSequences = stopSequences
}
adaptorWithExtraBody := false
@@ -631,6 +638,31 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
return &geminiRequest, nil
}
// parseStopSequences 解析停止序列,支持字符串或字符串数组
func parseStopSequences(stop any) []string {
if stop == nil {
return nil
}
switch v := stop.(type) {
case string:
if v != "" {
return []string{v}
}
case []string:
return v
case []interface{}:
sequences := make([]string, 0, len(v))
for _, item := range v {
if str, ok := item.(string); ok && str != "" {
sequences = append(sequences, str)
}
}
return sequences
}
return nil
}
func hasFunctionCallContent(call *dto.FunctionCall) bool {
if call == nil {
return false