Repository navigation
feat(api): integrate OpenRouter SDK and implement AI form generation … #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Basharkhan7776
merged 2 commits into
Openlabsops:main
from
yashraj639:feat/ai-form-generation
Jul 17, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { OpenRouter } from "@openrouter/sdk"; | ||
| import { config } from "../env"; | ||
|
|
||
| export const aiClient = new OpenRouter({ | ||
| apiKey: config.ai.apiKey, | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * Builds the system prompt for AI form generation. | ||
| * Instructs the LLM to return a valid FormDefinition JSON object. | ||
| */ | ||
| export function buildFormGenerationPrompt(): string { | ||
| return `You are an expert form builder. Generate a form based on the user's request. | ||
|
|
||
| You MUST respond with ONLY a valid JSON object matching this exact structure: | ||
| { | ||
| "version": "1.0", | ||
| "elements": [ ...array of form elements... ] | ||
| } | ||
|
|
||
| ## Available element types: | ||
|
|
||
| 1. "textInput" - Single-line text { id, type, label, required?, description?, placeholder?, maxLength? } | ||
| 2. "textarea" - Multi-line text { id, type, label, required?, description?, placeholder?, rows?(2-20) } | ||
| 3. "rating" - Star rating { id, type, label, required?, description?, max?(2-10, default 5) } | ||
| 4. "multipleChoice" - Pick one { id, type, label, required?, description?, options: [{id, label}] } (min 2 options) | ||
| 5. "checkbox" - Pick many { id, type, label, required?, description?, options: [{id, label}] } (min 1 option) | ||
| 6. "dropdown" - Dropdown pick one { id, type, label, required?, description?, placeholder?, options: [{id, label}] } (min 2 options) | ||
| 7. "email" - Email input { id, type, label, required?, description?, placeholder? } | ||
| 8. "phone" - Phone input { id, type, label, required?, description?, placeholder? } | ||
| 9. "datePicker" - Date { id, type, label, required?, description?, minDate?, maxDate? } | ||
| 10. "heading" - Section heading { id, type, label, description?, level?: "h1"|"h2"|"h3" } (no required field) | ||
| 11. "paragraph" - Static text { id, type, label, description? } (no required field) | ||
|
|
||
| ## Rules: | ||
| - Every element MUST have a unique "id" that is a valid UUID v4. Generate a unique, random UUID for each element (using only hexadecimal characters 0-9 and a-f). | ||
| - Do NOT use letters beyond 'f' (such as g, h, i, j, k, l, m, etc.) in any UUID. | ||
| - Every option inside "multipleChoice", "checkbox", and "dropdown" elements MUST also have a unique "id" in valid UUID v4 format. Generate a completely unique, random UUID for each option (do NOT use simple strings like "opt1" or "agree"). | ||
| - Every element MUST have a "label" (non-empty string) | ||
| - Use "heading" or "paragraph" elements to organise sections | ||
| - Generate 5-12 elements appropriate for the request | ||
| - Return ONLY the JSON — no markdown, no explanation, no code fences`; | ||
| } |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/db/prisma/migrations/20260701000001_add_cloned_form_fk/migration.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "user_owned_templates" DROP CONSTRAINT IF EXISTS "user_owned_templates_clonedFormId_fkey"; | ||
| ALTER TABLE "user_owned_templates" ADD CONSTRAINT "user_owned_templates_clonedFormId_fkey" FOREIGN KEY ("clonedFormId") REFERENCES "forms"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.