Reduce code duplication across form generation and routing#238
Open
subhranil2605 wants to merge 7 commits into
Open
Reduce code duplication across form generation and routing#238subhranil2605 wants to merge 7 commits into
subhranil2605 wants to merge 7 commits 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.
Create createOpenAIClient() helper to consolidate the identical OpenAI client initialization pattern that was duplicated across 4 functions (createFormWithOpenAI, generateSuggestionsWithOpenAI, judgeFormWithOpenAI, updateFormWithOpenAI). Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Consolidate the identical macro options generation for multiple_choice and single_choice field types into buildChoiceFieldOptions() helper. The only differences between them (checked expression and macro name) are now parameters. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Create validatePaginationParams() in validation-utils.ts to consolidate the identical pagination parameter validation pattern that was duplicated across admin-routes, prototype-routes, and user-routes. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Create createGeminiClient() helper to consolidate the identical Gemini client initialization pattern that was duplicated across 4 functions in gemini.ts. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Consolidate the identical filter registration and view engine setup that was duplicated in setupNunjucksEnv() and setupNunjucksEnvZipDownload(). The zip-download version now re-exports from the shared utility. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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
Test plan