Skip to content

Commit 1d4ffeb

Browse files
authored
fix(js/genkit): Explicitly allow null types in promptDir (#5036)
1 parent d5c08d0 commit 1d4ffeb

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

js/ai/src/prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ export async function prompt<
877877
>(
878878
registry: Registry,
879879
name: string,
880-
options?: { variant?: string; dir?: string }
880+
options?: { variant?: string; dir?: string | null }
881881
): Promise<ExecutablePrompt<I, O, CustomOptions>> {
882882
return await lookupPrompt<I, O, CustomOptions>(
883883
registry,

js/genkit/src/genkit.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export type PromptFn<
147147
export interface GenkitOptions {
148148
/** List of plugins to load. */
149149
plugins?: (GenkitPlugin | GenkitPluginV2)[];
150-
/** Directory where dotprompts are stored. */
151-
promptDir?: string;
150+
/** Directory where dotprompts are stored. Set to `null` to disable automatic prompt loading. */
151+
promptDir?: string | null;
152152
/** Default model to use if no model is specified. */
153153
model?: ModelArgument<any>;
154154
/** Additional runtime context data for flows and tools. */
@@ -346,7 +346,10 @@ export class Genkit extends GenkitAI implements HasRegistry {
346346
`${name}${options?.variant ? `.${options?.variant}` : ''}`,
347347
prompt(this.registry, name, {
348348
...options,
349-
dir: this.options.promptDir ?? './prompts',
349+
dir:
350+
this.options.promptDir === undefined
351+
? './prompts'
352+
: this.options.promptDir,
350353
})
351354
);
352355
}

js/genkit/tests/prompts_test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,19 @@ describe('prompt', () => {
10571057
});
10581058
});
10591059

1060+
it('does not auto-load prompts when promptDir is null', async () => {
1061+
const aiWithoutPromptDir = genkit({
1062+
model: 'echoModel',
1063+
promptDir: null,
1064+
});
1065+
1066+
const prompt = aiWithoutPromptDir.prompt('test');
1067+
const response = prompt();
1068+
await assert.rejects(response, {
1069+
message: 'NOT_FOUND: Prompt test not found',
1070+
});
1071+
});
1072+
10601073
it('loads from from the sub folder', async () => {
10611074
const testPrompt = ai.prompt('sub/test'); // see tests/prompts/sub folder
10621075

0 commit comments

Comments
 (0)