Skip to content

Commit

Permalink
feat: enhance response handling to support gemini-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdlzg committed Dec 21, 2024
1 parent 90456a0 commit dd47131
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion relay/adaptor/gemini/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package gemini
// https://ai.google.dev/models/gemini

var ModelList = []string{
"gemini-pro", "gemini-1.0-pro", "gemini-1.5-flash", "gemini-1.5-pro", "text-embedding-004", "aqa",
"gemini-pro", "gemini-1.0-pro", "gemini-1.5-flash", "gemini-1.5-pro", "text-embedding-004", "aqa", "gemini-2.0-flash-exp", "gemini-2.0-flash-thinking-exp",
}
13 changes: 12 additions & 1 deletion relay/adaptor/gemini/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
Category: "HARM_CATEGORY_DANGEROUS_CONTENT",
Threshold: config.GeminiSafetySetting,
},
{
Category: "HARM_CATEGORY_CIVIC_INTEGRITY",
Threshold: config.GeminiSafetySetting,
},
},
GenerationConfig: ChatGenerationConfig{
Temperature: textRequest.Temperature,
Expand Down Expand Up @@ -273,7 +277,14 @@ func responseGeminiChat2OpenAI(response *ChatResponse) *openai.TextResponse {
if candidate.Content.Parts[0].FunctionCall != nil {
choice.Message.ToolCalls = getToolCalls(&candidate)
} else {
choice.Message.Content = candidate.Content.Parts[0].Text
var builder strings.Builder
for _, part := range candidate.Content.Parts {
if i > 0 {
builder.WriteString("\n")
}
builder.WriteString(part.Text)
}
choice.Message.Content = builder.String()
}
} else {
choice.Message.Content = ""
Expand Down

0 comments on commit dd47131

Please sign in to comment.