Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.
Closed
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
40 changes: 40 additions & 0 deletions packages/types/src/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,44 @@ export const geminiModels = {
supportsReasoningBudget: true,
maxThinkingTokens: 24_576,
},

// Robotics models
"gemini-robotics-er-1.5-preview": {
maxTokens: 8192,
contextWindow: 1_000_000,
supportsImages: true,
supportsNativeTools: true,
supportsPromptCache: false,
inputPrice: 0.3,
outputPrice: 2.5,
},

// Gemma 3 models
"gemma-3-27b-it": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: true,
supportsNativeTools: false,
supportsPromptCache: false,
inputPrice: 0.07,
outputPrice: 0.5,
},
"gemma-3-12b-it": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: true,
supportsNativeTools: false,
supportsPromptCache: false,
inputPrice: 0.03,
outputPrice: 0.1,
},
"gemma-3-4b-it": {
maxTokens: 8192,
contextWindow: 128_000,
supportsImages: true,
supportsNativeTools: false,
supportsPromptCache: false,
inputPrice: 0.02,
outputPrice: 0.07,
},
} as const satisfies Record<string, ModelInfo>
37 changes: 36 additions & 1 deletion src/api/providers/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,30 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
? (this.options.modelTemperature ?? info.defaultTemperature ?? 1)
: info.defaultTemperature

// Check if the model is a Gemma 3 model
const isGemma3 = model.includes("gemma-3")

// Prepend system instruction to the first user message if it's a Gemma 3 model,
// as they don't support the system instruction parameter.
if (isGemma3 && systemInstruction) {
if (contents.length > 0 && contents[0].role === "user") {
const firstMessage = contents[0]
// Create a new text part for the system instruction
const systemPart = { text: systemInstruction }
// Prepend it to the existing parts
firstMessage.parts = [systemPart, ...(firstMessage.parts || [])]
} else {
// If no messages or first message is not user (e.g. starts with model),
// prepend a new user message with the system instruction.
contents.unshift({
role: "user",
parts: [{ text: systemInstruction }],
})
}
}

const config: GenerateContentConfig = {
systemInstruction,
...(isGemma3 ? {} : { systemInstruction }),
httpOptions: this.options.googleGeminiBaseUrl ? { baseUrl: this.options.googleGeminiBaseUrl } : undefined,
thinkingConfig,
maxOutputTokens,
Expand Down Expand Up @@ -337,6 +359,19 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
TelemetryService.instance.captureException(apiError)

if (error instanceof Error) {
// Parse "limit: 15000, model: gemma-3-27b\nPlease retry in 31.714908887s"
// Use a more flexible regex to handle potential variations in spacing or text
const match = error.message.match(/limit:\s*(\d+)\s*,\s*model:\s*([^,\n]+).*?retry in\s*([\d.]+)/s)
if (match) {
const [, limit, model, retry] = match
throw new Error(
t("common:errors.gemini.resource_exhausted", {
limit,
model: model.trim(),
retry: Math.round(Number(retry)),
}),
)
}
throw new Error(t("common:errors.gemini.generate_stream", { error: error.message }))
}

Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/ca/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/de/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"thinking_complete_no_output": "(Thinking complete, but no output was generated.)",
"thinking_complete_truncated": "(Thinking complete, but output was truncated due to token limit.)",
"thinking_complete_safety": "(Thinking complete, but output was blocked due to safety settings.)",
"thinking_complete_recitation": "(Thinking complete, but output was blocked due to recitation check.)"
"thinking_complete_recitation": "(Thinking complete, but output was blocked due to recitation check.)",
"resource_exhausted": "Rate limit reached for {{model}}. The limit is {{limit}} requests per minute. Please retry in {{retry}} seconds."
},
"cerebras": {
"authenticationFailed": "Cerebras API authentication failed. Please check your API key is valid and not expired.",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/es/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/fr/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/hi/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/id/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/it/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/ja/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/ko/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/nl/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/pl/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/pt-BR/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/ru/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/tr/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/vi/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/zh-CN/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/locales/zh-TW/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading