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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions js/genkit/src/genkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,10 @@ export class Genkit implements HasRegistry {
}) as ExecutablePrompt<z.infer<I>, O, CustomOptions>;

executablePrompt.render = async (
opt: PromptGenerateOptions<O, CustomOptions> & {
input?: I;
}
input?: I,
opts?: PromptGenerateOptions<O, CustomOptions>
): Promise<GenerateOptions<O, CustomOptions>> => {
return (await promise).render(opt.input, opt) as Promise<
return (await promise).render(input, opts) as Promise<
GenerateOptions<O, CustomOptions>
>;
};
Expand Down
14 changes: 14 additions & 0 deletions js/genkit/tests/chat_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('chat', () => {
beforeEach(() => {
ai = genkit({
model: 'echoModel',
promptDir: './tests/prompts',
});
defineEchoModel(ai);
});
Expand Down Expand Up @@ -155,6 +156,19 @@ describe('chat', () => {
);
});

it('can start chat from a prompt file with input', async () => {
const preamble = ai.prompt('chat_preamble');
const session = await ai.chat(preamble, {
input: { name: 'Genkit' },
});
const response = await session.send('send it');

assert.strictEqual(
response.text,
'Echo: hi Genkit from template,send it; config: {"version":"abc"}'
);
});

it('can send a rendered prompt to chat', async () => {
const prompt = ai.definePrompt({
name: 'hi',
Expand Down
5 changes: 5 additions & 0 deletions js/genkit/tests/prompts/chat_preamble.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
config:
version: 'abc'
---
hi {{ name }} from template
3 changes: 1 addition & 2 deletions js/genkit/tests/prompts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,15 +1106,14 @@ describe('prompt', () => {
{
content: [
{
text: ' from the prompt file ',
text: ' from the prompt file banana',
},
],
role: 'model',
},
],
returnToolRequests: true,
toolChoice: 'required',
subject: 'banana',
tools: ['toolA', 'toolB'],
});
});
Expand Down