Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions relay/channel/gemini/relay-gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Comment on lines +641 to +664

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Inconsistent empty-string filtering between []string and []interface{} cases.

The []interface{} case (lines 654-661) filters out empty strings, but the []string case (lines 652-653) returns the slice directly without any filtering. This inconsistency could allow empty stop sequences to reach the Gemini API when the input is []string.

🔧 Proposed fix to add filtering for []string
 	case []string:
-		return v
+		sequences := make([]string, 0, len(v))
+		for _, s := range v {
+			if s != "" {
+				sequences = append(sequences, s)
+			}
+		}
+		return sequences
 	case []interface{}:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 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
}
// parseStopSequences 解析停止序列,支持字符串或字符串数组
func parseStopSequences(stop any) []string {
if stop == nil {
return nil
}
switch v := stop.(type) {
case string:
if v != "" {
return []string{v}
}
case []string:
sequences := make([]string, 0, len(v))
for _, s := range v {
if s != "" {
sequences = append(sequences, s)
}
}
return sequences
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
}
🤖 Prompt for AI Agents
In `@relay/channel/gemini/relay-gemini.go` around lines 641 - 664, The
parseStopSequences function currently returns []string unchanged for the
[]string case while filtering out empty strings for []interface{}; update the
[]string branch in parseStopSequences to iterate over the input slice and append
only non-empty strings (like the []interface{} branch) so empty entries are
consistently removed before returning; keep the existing nil handling and
preserve the function signature and behavior for string and other cases.


func hasFunctionCallContent(call *dto.FunctionCall) bool {
if call == nil {
return false
Expand Down