Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/ai/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ export async function prompt<
>(
registry: Registry,
name: string,
options?: { variant?: string; dir?: string }
options?: { variant?: string; dir?: string | null }
): Promise<ExecutablePrompt<I, O, CustomOptions>> {
return await lookupPrompt<I, O, CustomOptions>(
registry,
Expand Down
9 changes: 6 additions & 3 deletions js/genkit/src/genkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
7hokerz marked this conversation as resolved.
/** Default model to use if no model is specified. */
model?: ModelArgument<any>;
/** Additional runtime context data for flows and tools. */
Expand Down Expand Up @@ -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
Comment thread
pavelgj marked this conversation as resolved.
? './prompts'
: this.options.promptDir,
})
);
}
Expand Down
13 changes: 13 additions & 0 deletions js/genkit/tests/prompts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,19 @@ describe('prompt', () => {
});
});

it('does not auto-load prompts when promptDir is null', async () => {
Comment thread
7hokerz marked this conversation as resolved.
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

Expand Down
Loading