Add support for multiple LLM providers (OpenAI & Gemini)#237
Open
subhranil2605 wants to merge 1 commit into
Open
Add support for multiple LLM providers (OpenAI & Gemini)#237subhranil2605 wants to merge 1 commit into
subhranil2605 wants to merge 1 commit into
Conversation
- Introduced new environment variables for Gemini API key and model ID in .env.example and validation schema. - Created llm-provider.ts to handle form creation, updates, and suggestions using either Gemini or OpenAI. - Refactored nunjucks setup into a separate utility file for better organization. - Updated prototype routes to utilize the new LLM provider functions. - Added new functions in gemini.ts for interacting with the Gemini API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for Google Gemini as an alternative LLM provider alongside OpenAI. Introduces a provider abstraction layer (
llm-provider.ts) that allows switching between providers via environment configuration without changing application logic.Key Changes
New Files
src/gemini.ts(318 lines) — Gemini API integration with structured output supportcreateFormWithGemini()— Generate form structure from descriptionsupdateFormWithGemini()— Update forms with user feedbackgenerateSuggestionsWithGemini()— Suggest form improvementsjudgeFormWithGemini()— Evaluate form qualitysrc/llm-provider.ts(107 lines) — Provider abstraction/router layerLLM_PROVIDERenvironment variablesrc/utils/nunjucks-setup.ts(72 lines) — Extracted nunjucks configuration utilityModified Files
.env.example— AddedLLM_PROVIDER=openaiandGEMINI_API_KEYvariablessrc/validationSchemas/env.ts— Added provider and Gemini API key validationsrc/routes/prototype-routes.ts— Updated 3 function calls to usellm-provider.tsserver.ts&data/zip-download/server.ts— Refactored to use shared nunjucks utilitypackage.json— Added@google/generative-aidependencyTechnical Details
Provider Abstraction Architecture
All LLM calls route through a single
llm-provider.tslayer:User Request
↓
llm-provider.createForm(envVars, ...)
↓
├─ If 'openai' → calls openai.ts functions
└─ If 'gemini' → calls gemini.ts functions
↓
Returns JSON (same schema, any provider)
data/*-schema.jsonConfiguration
LLM_PROVIDERopenaiGEMINI_API_KEYSupported Providers
Testing
Test results: No breaking changes, all tests pass with provider abstraction
Migration Path
Fully backward compatible:
LLM_PROVIDER=geminiGEMINI_API_KEY=your-api-keyLLM_PROVIDERback toopenaiDependencies Added
@google/generative-ai— Official Google SDK for Gemini API