-
-
Notifications
You must be signed in to change notification settings - Fork 8
Implement Domain-Based System Prompt Generation #671
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
ngoiyaeric
merged 3 commits into
main
from
feat/domain-prompt-generation-17443257101179417112
Jun 25, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,36 +1,166 @@ | ||
| import React, { useState, useEffect } from 'react' | ||
| import type { UseFormReturn } from "react-hook-form" | ||
| import { FormField, FormItem, FormLabel, FormControl, FormDescription, FormMessage } from "@/components/ui/form" | ||
| import { Textarea } from "@/components/ui/textarea" | ||
| import { Input } from "@/components/ui/input" | ||
| import { Button } from "@/components/ui/button" | ||
| import { Loader2, Sparkles } from "lucide-react" | ||
| import { useToast } from "@/components/ui/hooks/use-toast" | ||
| import { startSystemPromptGeneration, getSystemPromptGenerationJob } from "@/lib/actions/system-prompt" | ||
|
|
||
| interface SystemPromptFormProps { | ||
| form: UseFormReturn<any> | ||
| } | ||
|
|
||
| export function SystemPromptForm({ form }: SystemPromptFormProps) { | ||
| const { toast } = useToast() | ||
| const systemPrompt = form.watch("systemPrompt") | ||
| const domain = form.watch("domain") | ||
| const characterCount = systemPrompt?.length || 0 | ||
| const [jobId, setJobId] = useState<string | null>(null) | ||
| const [isGenerating, setIsGenerating] = useState(false) | ||
|
|
||
| const handleGenerate = async () => { | ||
| if (!domain) { | ||
| toast({ | ||
| title: "Domain required", | ||
| description: "Please enter a domain to generate a system prompt.", | ||
| variant: "destructive", | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| setIsGenerating(true) | ||
| const result = await startSystemPromptGeneration(domain) | ||
|
|
||
| if (result.error) { | ||
| toast({ | ||
| title: "Generation failed", | ||
| description: result.error, | ||
| variant: "destructive", | ||
| }) | ||
| setIsGenerating(false) | ||
| } else if (result.jobId) { | ||
| setJobId(result.jobId) | ||
| } | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| let interval: NodeJS.Timeout | null = null | ||
|
|
||
| if (jobId) { | ||
| const pollStartTime = Date.now() | ||
| const MAX_POLL_DURATION = 120000 // 2 minutes | ||
|
|
||
| interval = setInterval(async () => { | ||
| const elapsed = Date.now() - pollStartTime | ||
| if (elapsed > MAX_POLL_DURATION) { | ||
| if (interval) clearInterval(interval) | ||
| setJobId(null) | ||
| setIsGenerating(false) | ||
| toast({ | ||
| title: "Generation timeout", | ||
| description: "The prompt generation took too long. Please try again.", | ||
| variant: "destructive", | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| const job = await getSystemPromptGenerationJob(jobId) | ||
|
|
||
| if (job.error || job.status === 'error') { | ||
| if (interval) clearInterval(interval) | ||
| setJobId(null) | ||
| setIsGenerating(false) | ||
| toast({ | ||
| title: "Generation error", | ||
| description: job.errorMessage || job.error || "An error occurred during generation.", | ||
| variant: "destructive", | ||
| }) | ||
| } else if (job.status === 'complete') { | ||
| if (interval) clearInterval(interval) | ||
| setJobId(null) | ||
| setIsGenerating(false) | ||
| if (job.resultPrompt) { | ||
| form.setValue("systemPrompt", job.resultPrompt, { shouldValidate: true, shouldDirty: true }) | ||
| toast({ | ||
| title: "Prompt generated", | ||
| description: "Your system prompt has been generated based on the domain content.", | ||
| }) | ||
| } | ||
| } | ||
| }, 3000) | ||
| } | ||
|
|
||
| return () => { | ||
| if (interval) clearInterval(interval) | ||
| } | ||
| }, [jobId, form, toast]) | ||
|
|
||
| return ( | ||
| <FormField | ||
| control={form.control} | ||
| name="systemPrompt" | ||
| render={({ field, fieldState, formState }: { field: import("react-hook-form").ControllerRenderProps<any, "systemPrompt">; fieldState: import("react-hook-form").ControllerFieldState; formState: import("react-hook-form").UseFormStateReturn<any>; }) => ( | ||
| <FormItem> | ||
| <FormLabel>System Prompt</FormLabel> | ||
| <FormControl> | ||
| <Textarea | ||
| placeholder="Enter the system prompt for your planetary copilot..." | ||
| className="min-h-[200px] resize-y" | ||
| {...field} | ||
| /> | ||
| </FormControl> | ||
| <FormDescription className="flex justify-between"> | ||
| <span>Define how your copilot should behave and respond to user queries.</span> | ||
| <span className={characterCount > 1800 ? "text-amber-500" : ""}>{characterCount}/2000</span> | ||
| </FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| <div className="space-y-6"> | ||
| <FormField | ||
| control={form.control} | ||
| name="domain" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Business Domain</FormLabel> | ||
| <div className="flex gap-2"> | ||
| <FormControl> | ||
| <Input | ||
| placeholder="example.com" | ||
| {...field} | ||
| disabled={isGenerating} | ||
| /> | ||
| </FormControl> | ||
| <Button | ||
| type="button" | ||
| onClick={handleGenerate} | ||
| disabled={isGenerating || !domain} | ||
| className="shrink-0" | ||
| > | ||
| {isGenerating ? ( | ||
| <> | ||
| <Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
| Generating... | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <Sparkles className="mr-2 h-4 w-4" /> | ||
| Generate | ||
| </> | ||
| )} | ||
| </Button> | ||
| </div> | ||
| <FormDescription> | ||
| Enter your business website to automatically generate a tailored system prompt. | ||
| </FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <FormField | ||
| control={form.control} | ||
| name="systemPrompt" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>System Prompt</FormLabel> | ||
| <FormControl> | ||
| <Textarea | ||
| placeholder="Enter the system prompt for your planetary copilot..." | ||
| className="min-h-[200px] resize-y" | ||
| {...field} | ||
| /> | ||
| </FormControl> | ||
| <FormDescription className="flex justify-between"> | ||
| <span>Define how your copilot should behave and respond to user queries.</span> | ||
| <span className={characterCount > 1800 ? "text-amber-500" : ""}>{characterCount}/2000</span> | ||
| </FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
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,12 @@ | ||
| CREATE TABLE "prompt_generation_jobs" ( | ||
| "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
| "user_id" uuid NOT NULL, | ||
| "domain" text NOT NULL, | ||
| "status" text DEFAULT 'pending' NOT NULL, | ||
| "result_prompt" text, | ||
| "error_message" text, | ||
| "created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
| "updated_at" timestamp with time zone DEFAULT now() NOT NULL | ||
| ); | ||
| --> statement-breakpoint | ||
| ALTER TABLE "prompt_generation_jobs" ADD CONSTRAINT "prompt_generation_jobs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; |
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.