PAIR-code / PAIR-code/deliberate-lab
use Gemma 4 in DL
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 96
- Forks
- 40
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 20
Description
For users wishing to use Gemma 4 (or future Gemma models with native system prompt support) via the Gemini API or Vertex AI.
Issue:
The backend relies on the Vercel AI SDK, which incorrectly assumes Gemma models do not support system instructions (Gemma 1-3 do not support system instructions). The SDK identifies Gemma models using a simple prefix check:
const isGemmaModel = this.modelId.toLowerCase().startsWith('gemma-'); ([Source](https://github.com/vercel/ai/blob/a983d06996ec688b45e0ae177c431a4c994c51fc/packages/google/src/google-language-model.ts#L260))
When a Gemma model is detected, the SDK forces one of two behaviors:
- Prepends the system instruction to the first user message. ([Source](https://github.com/vercel/ai/blob/a983d06996ec688b45e0ae177c431a4c994c51fc/packages/google/src/convert-to-google-messages.ts#L641))
- Ignores the system instruction entirely if the conversation does not start with a user message (e.g., if a fixed initial message is configured). ([Source](https://github.com/vercel/ai/blob/a983d06996ec688b45e0ae177c431a4c994c51fc/packages/google/src/convert-to-google-messages.ts#L671))
Workaround:
You can bypass this by formatting the model ID as models/{gemma-model-name}. This avoids the hardcoded logic and ensures system instructions are processed correctly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the backend's Vercel AI SDK model configuration and how Gemini API or Vertex AI model IDs are passed through. Compare the SDK behavior in google-language-model.ts and convert-to-google-messages.ts for Gemma system instructions, then verify that Gemma 4 receives them without relying on the models/{gemma-model-name} workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100