diff --git a/src/ai/dev.ts b/src/ai/dev.ts index 4f77a33..861dfb2 100644 --- a/src/ai/dev.ts +++ b/src/ai/dev.ts @@ -1,4 +1,5 @@ import { config } from 'dotenv'; config(); -import '@/ai/flows/suggest-tags.ts'; \ No newline at end of file +import '@/ai/flows/suggest-tags.ts'; +import '@/ai/flows/suggest-title.ts'; diff --git a/src/ai/flows/suggest-title.ts b/src/ai/flows/suggest-title.ts new file mode 100644 index 0000000..e93cd03 --- /dev/null +++ b/src/ai/flows/suggest-title.ts @@ -0,0 +1,56 @@ +// This file uses server-side code. +'use server'; + +/** + * @fileOverview AI-powered title suggestion for prompts. + * + * - suggestTitle - A function that suggests a relevant title for a given prompt. + * - SuggestTitleInput - The input type for the suggestTitle function. + * - SuggestTitleOutput - The return type for the suggestTitle function. + */ + +import {ai} from '@/ai/genkit'; +import {z} from 'genkit'; + +const SuggestTitleInputSchema = z.object({ + promptText: z + .string() + .describe('The text content of the prompt for which a title is to be suggested.'), +}); +export type SuggestTitleInput = z.infer; + +const SuggestTitleOutputSchema = z.object({ + title: z + .string() + .describe('The suggested title for the given prompt.'), +}); +export type SuggestTitleOutput = z.infer; + +export async function suggestTitle(input: SuggestTitleInput): Promise { + return suggestTitleFlow(input); +} + +const suggestTitlePrompt = ai.definePrompt({ + name: 'suggestTitlePrompt', + input: {schema: SuggestTitleInputSchema}, + output: {schema: SuggestTitleOutputSchema}, + prompt: `You are a title generation expert. + + Given the following prompt, suggest a short, concise, and descriptive title (max 5 words). + + Prompt: {{{promptText}}} + + Title:`, +}); + +const suggestTitleFlow = ai.defineFlow( + { + name: 'suggestTitleFlow', + inputSchema: SuggestTitleInputSchema, + outputSchema: SuggestTitleOutputSchema, + }, + async input => { + const {output} = await suggestTitlePrompt(input); + return output!; + } +); diff --git a/src/components/create-prompt-dialog.tsx b/src/components/create-prompt-dialog.tsx index 061130d..13ff4e8 100644 --- a/src/components/create-prompt-dialog.tsx +++ b/src/components/create-prompt-dialog.tsx @@ -104,15 +104,10 @@ export function CreatePromptDialog() { Create a new prompt - Craft your next masterpiece. Add notes and tags to keep it organized. + Craft your next masterpiece. A title will be automatically generated. Add notes and tags to keep it organized.
-
- - - {state.errors?.title &&

{state.errors.title[0]}

} -