Summary

Completes the Gemini (Palm2 replacement) API support for the JS SDK as requested in #279.

/claim #279

What’s done

1. Enhanced GeminiAI class (src/ai/src/lib/gemini/gemini.ts)

  • Multi-turn conversation support via messages parameter (array of {role, content})
  • Proper generationConfig with temperature, maxOutputTokens, topP, topK, responseMimeType
  • Safety settings support (safetySettings array)
  • New chatText() convenience method that extracts text content directly
  • Full TypeScript types for all request/response shapes

2. Exported TypeScript types (src/ai/src/types/index.ts)

  • All Gemini types re-exported: GeminiModel, GeminiRole, GeminiResponse, GeminiChatOptions, etc.

3. Unit tests in testcases/palm2 folder (src/ai/src/tests/palm2/geminiEndpoints.test.ts)

  • Constructor tests (API key from param, env var, missing key warning)
  • Chat tests: simple prompt, custom model, generation config params, multi-turn messages, safety settings, retry on failure
  • ChatText tests: text extraction, empty candidates, multi-part concatenation
  • Uses mocked axios (same pattern as OpenAI tests)

4. Jsonnet example (examples/chat-with-gemini/)

  • Prompts defined in jsonnet/main.jsonnet (not hardcoded)
  • API key in jsonnet/secrets.jsonnet
  • Hono server with /chat POST endpoint
  • Follows same structure as chat-with-llm example

Acceptance criteria from issue

  • Classes and TypeScript types for Gemini API
  • Unit testcases in testcases folder named “palm2”
  • Example with jsonnet prompts (not hardcoded)

Implementation notes

  • Uses native HTTP calls via axios (not Google’s @google/generative-ai SDK), matching the existing OpenAI implementation pattern
  • Gemini API replaces deprecated Palm2 as confirmed by maintainer @sandys
  • Backward compatible: existing GeminiAI.chat() API preserved, new features are additive

Claim

Total prize pool $25
Total paid $0
Status Pending
Submitted March 07, 2026
Last updated March 07, 2026

Contributors

MA

maoshuorz

@maoshuorz

100%

Sponsors

AR

Arakoo.ai

@arakoodev

$25