diff --git a/js/ai/src/prompt.ts b/js/ai/src/prompt.ts index aa228bd084..4d9ee77c5c 100644 --- a/js/ai/src/prompt.ts +++ b/js/ai/src/prompt.ts @@ -875,7 +875,7 @@ export async function prompt< >( registry: Registry, name: string, - options?: { variant?: string; dir?: string } + options?: { variant?: string; dir?: string | null } ): Promise> { return await lookupPrompt( registry, diff --git a/js/genkit/src/genkit.ts b/js/genkit/src/genkit.ts index 01333ae7d9..92ba1d4724 100644 --- a/js/genkit/src/genkit.ts +++ b/js/genkit/src/genkit.ts @@ -160,8 +160,8 @@ export type PromptFn< export interface GenkitOptions { /** List of plugins to load. */ plugins?: (GenkitPlugin | GenkitPluginV2)[]; - /** Directory where dotprompts are stored. */ - promptDir?: string; + /** Directory where dotprompts are stored. Set to `null` to disable automatic prompt loading. */ + promptDir?: string | null; /** Default model to use if no model is specified. */ model?: ModelArgument; /** Additional runtime context data for flows and tools. */ @@ -360,7 +360,10 @@ export class Genkit implements HasRegistry { `${name}${options?.variant ? `.${options?.variant}` : ''}`, prompt(this.registry, name, { ...options, - dir: this.options.promptDir ?? './prompts', + dir: + this.options.promptDir === undefined + ? './prompts' + : this.options.promptDir, }) ); } diff --git a/js/genkit/tests/prompts_test.ts b/js/genkit/tests/prompts_test.ts index 7db00cd165..9f6e429a91 100644 --- a/js/genkit/tests/prompts_test.ts +++ b/js/genkit/tests/prompts_test.ts @@ -1057,6 +1057,19 @@ describe('prompt', () => { }); }); + it('does not auto-load prompts when promptDir is null', async () => { + const aiWithoutPromptDir = genkit({ + model: 'echoModel', + promptDir: null, + }); + + const prompt = aiWithoutPromptDir.prompt('test'); + const response = prompt(); + await assert.rejects(response, { + message: 'NOT_FOUND: Prompt test not found', + }); + }); + it('loads from from the sub folder', async () => { const testPrompt = ai.prompt('sub/test'); // see tests/prompts/sub folder