Skip to content

Commit

Permalink
chore(js/genkit): added a few more prompt tests (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj authored Dec 10, 2024
1 parent fa11e2e commit cab3bd2
Showing 1 changed file with 99 additions and 3 deletions.
102 changes: 99 additions & 3 deletions js/genkit/tests/prompts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe('definePrompt - dotprompt', () => {
assert.strictEqual(response.text, 'Echo: hi Genkit; config: {}');
});

it('calls dotprompt with history', async () => {
it('calls dotprompt with history and places it at {{ history }}', async () => {
const hi = ai.definePrompt(
{
name: 'hi',
Expand All @@ -281,7 +281,7 @@ describe('definePrompt - dotprompt', () => {
}),
},
},
'{{ history}} hi {{ name }}'
'{{ role "system"}} talk like a pirate {{ history}} hi {{ name }}'
);

const response = await hi(
Expand All @@ -294,6 +294,10 @@ describe('definePrompt - dotprompt', () => {
}
);
assert.deepStrictEqual(response.messages, [
{
role: 'system',
content: [{ text: ' talk like a pirate ' }],
},
{
role: 'user',
content: [{ text: 'hi' }],
Expand All @@ -311,7 +315,99 @@ describe('definePrompt - dotprompt', () => {
{
role: 'model',
content: [
{ text: 'Echo: hi,bye, hi Genkit' },
{ text: 'Echo: system: talk like a pirate ,hi,bye, hi Genkit' },
{ text: '; config: {}' },
],
},
]);
});

it('calls dotprompt with history and places it before user message', async () => {
const hi = ai.definePrompt(
{
name: 'hi',
model: 'echoModel',
input: {
schema: z.object({
name: z.string(),
}),
},
},
'hi {{ name }}'
);

const response = await hi(
{ name: 'Genkit' },
{
messages: [
{ role: 'user', content: [{ text: 'hi' }] },
{ role: 'model', content: [{ text: 'bye' }] },
],
}
);
assert.deepStrictEqual(response.messages, [
{
role: 'user',
content: [{ text: 'hi' }],
},
{
role: 'model',
content: [{ text: 'bye' }],
},
{
role: 'user',
content: [{ text: 'hi Genkit' }],
},
{
role: 'model',
content: [
{ text: 'Echo: hi,bye,hi Genkit' },
{ text: '; config: {}' },
],
},
]);
});

it('streams dotprompt with history and places it before user message', async () => {
const hi = ai.definePrompt(
{
name: 'hi',
model: 'echoModel',
input: {
schema: z.object({
name: z.string(),
}),
},
},
'hi {{ name }}'
);

const response = await hi.stream(
{ name: 'Genkit' },
{
messages: [
{ role: 'user', content: [{ text: 'hi' }] },
{ role: 'model', content: [{ text: 'bye' }] },
],
}
);
assert.deepStrictEqual((await response.response).messages, [
{
role: 'user',
content: [{ text: 'hi' }],
},
{
role: 'model',
content: [{ text: 'bye' }],
},
{
role: 'user',
content: [{ text: 'hi Genkit' }],
},
{
role: 'model',
content: [
{ text: 'Echo: hi,bye,hi Genkit' },
{ text: '; config: {}' },
],
},
Expand Down

0 comments on commit cab3bd2

Please sign in to comment.