Skip to content

Commit

Permalink
feat: enhance response handling to support gemini-2.0-thinking
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdlzg committed Dec 21, 2024
1 parent e9f117f commit 89eb083
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions relay/adaptor/gemini/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ var ModelList = []string{
"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,
},

Check warning on line 61 in relay/adaptor/gemini/main.go

View check run for this annotation

Codecov / codecov/patch

relay/adaptor/gemini/main.go#L58-L61

Added lines #L58 - L61 were not covered by tests
},
GenerationConfig: ChatGenerationConfig{
Temperature: textRequest.Temperature,
Expand Down Expand Up @@ -247,7 +251,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)

Check warning on line 259 in relay/adaptor/gemini/main.go

View check run for this annotation

Codecov / codecov/patch

relay/adaptor/gemini/main.go#L254-L259

Added lines #L254 - L259 were not covered by tests
}
choice.Message.Content = builder.String()

Check warning on line 261 in relay/adaptor/gemini/main.go

View check run for this annotation

Codecov / codecov/patch

relay/adaptor/gemini/main.go#L261

Added line #L261 was not covered by tests
}
} else {
choice.Message.Content = ""
Expand Down
2 changes: 1 addition & 1 deletion relay/adaptor/vertexai/gemini/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var ModelList = []string{
"gemini-pro", "gemini-pro-vision",
"gemini-1.5-pro-001", "gemini-1.5-flash-001",
"gemini-1.5-pro-002", "gemini-1.5-flash-002",
"gemini-2.0-flash-exp",
"gemini-2.0-flash-exp", "gemini-2.0-flash-thinking-exp",
}

type Adaptor struct {
Expand Down
17 changes: 9 additions & 8 deletions relay/billing/ratio/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ var ModelRatio = map[string]float64{
"bge-large-en": 0.002 * RMB,
"tao-8k": 0.002 * RMB,
// https://ai.google.dev/pricing
"gemini-pro": 1, // $0.00025 / 1k characters -> $0.001 / 1k tokens
"gemini-1.0-pro": 1,
"gemini-1.5-pro": 1,
"gemini-1.5-pro-001": 1,
"gemini-1.5-flash": 1,
"gemini-1.5-flash-001": 1,
"gemini-2.0-flash-exp": 1,
"aqa": 1,
"gemini-pro": 1, // $0.00025 / 1k characters -> $0.001 / 1k tokens
"gemini-1.0-pro": 1,
"gemini-1.5-pro": 1,
"gemini-1.5-pro-001": 1,
"gemini-1.5-flash": 1,
"gemini-1.5-flash-001": 1,
"gemini-2.0-flash-exp": 1,
"gemini-2.0-flash-thinking-exp": 1,
"aqa": 1,
// https://open.bigmodel.cn/pricing
"glm-4": 0.1 * RMB,
"glm-4v": 0.1 * RMB,
Expand Down

0 comments on commit 89eb083

Please sign in to comment.