Skip to content

Commit

Permalink
Properly look up prompt variants
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDoyle committed Nov 22, 2024
1 parent 97ca6a7 commit 6f2fd84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/genkit/src/genkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class Genkit {
// check the registry first as not all prompt types can be
// loaded by dotprompt (e.g. functional)
let action = (await this.registry.lookupAction(
`/prompt/${name}`
`/prompt/${name}${options?.variant ? `.${options?.variant}` : ''}`
)) as PromptAction<I>;
// nothing in registry - check for dotprompt file.
if (!action) {
Expand Down
6 changes: 6 additions & 0 deletions js/genkit/tests/prompts/test.variant.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
description: a prompt variant in a file
config:
temperature: 13
---
Hello from a variant of the hello prompt
11 changes: 11 additions & 0 deletions js/genkit/tests/prompts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,17 @@ describe('prompt', () => {
);
});

it('loads a varaint from from the folder', async () => {
const testPrompt = ai.prompt('test', { variant: 'variant' }); // see tests/prompts folder

const { text } = await testPrompt();

assert.strictEqual(
text,
'Echo: Hello from a variant of the hello prompt\n; config: {"temperature":13}'
);
});

it('returns a ref to functional prompts', async () => {
ai.definePrompt(
{
Expand Down

0 comments on commit 6f2fd84

Please sign in to comment.