Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance response handling to support gemini-2.0-thinking #1995

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
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
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 @@
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 @@
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
Loading