From a286fb5a24836dcc3030f0f90546d3ed30a8c9d2 Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Sat, 25 May 2024 13:20:08 -0400 Subject: [PATCH 1/3] Passthrough streaming callback on dotprompt render --- js/plugins/dotprompt/src/prompt.ts | 1 + js/plugins/dotprompt/tests/prompt_test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/js/plugins/dotprompt/src/prompt.ts b/js/plugins/dotprompt/src/prompt.ts index 43ffc4664c..95cc6b205e 100644 --- a/js/plugins/dotprompt/src/prompt.ts +++ b/js/plugins/dotprompt/src/prompt.ts @@ -175,6 +175,7 @@ export class Dotprompt implements PromptMetadata { jsonSchema: options.output?.jsonSchema || this.output?.jsonSchema, }, tools: (options.tools || []).concat(this.tools || []), + streamingCallback: options.streamingCallback, }; } diff --git a/js/plugins/dotprompt/tests/prompt_test.ts b/js/plugins/dotprompt/tests/prompt_test.ts index ab5534ac7f..bb7cbf2940 100644 --- a/js/plugins/dotprompt/tests/prompt_test.ts +++ b/js/plugins/dotprompt/tests/prompt_test.ts @@ -90,6 +90,16 @@ describe('Prompt', () => { await invalidSchemaPrompt.render({ input: { foo: 'baz' } }); }, ValidationError); }); + + it('should render with streaming callback', async () => { + const prompt = testPrompt(`Hello {{name}}, how are you?`); + + const streamingCallback = (c) => console.log(c); + + const rendered = await prompt.render({ input: { name: 'Michael' }, streamingCallback}); + assert.strictEqual(rendered.streamingCallback, streamingCallback); + }); + }); describe('#generate', () => { From f18a3882a9c19e44faf40b2ef787fceb03e693ab Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Sat, 25 May 2024 13:23:35 -0400 Subject: [PATCH 2/3] format --- js/plugins/dotprompt/tests/prompt_test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/plugins/dotprompt/tests/prompt_test.ts b/js/plugins/dotprompt/tests/prompt_test.ts index bb7cbf2940..d73e2febaf 100644 --- a/js/plugins/dotprompt/tests/prompt_test.ts +++ b/js/plugins/dotprompt/tests/prompt_test.ts @@ -96,10 +96,12 @@ describe('Prompt', () => { const streamingCallback = (c) => console.log(c); - const rendered = await prompt.render({ input: { name: 'Michael' }, streamingCallback}); + const rendered = await prompt.render({ + input: { name: 'Michael' }, + streamingCallback, + }); assert.strictEqual(rendered.streamingCallback, streamingCallback); }); - }); describe('#generate', () => { From e957690c4c8dbdd96abcc896be24c20cb451ca8e Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Tue, 28 May 2024 11:41:00 -0400 Subject: [PATCH 3/3] returnToolRequests --- js/plugins/dotprompt/src/prompt.ts | 1 + js/plugins/dotprompt/tests/prompt_test.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/js/plugins/dotprompt/src/prompt.ts b/js/plugins/dotprompt/src/prompt.ts index 95cc6b205e..4c5de60765 100644 --- a/js/plugins/dotprompt/src/prompt.ts +++ b/js/plugins/dotprompt/src/prompt.ts @@ -176,6 +176,7 @@ export class Dotprompt implements PromptMetadata { }, tools: (options.tools || []).concat(this.tools || []), streamingCallback: options.streamingCallback, + returnToolRequests: options.returnToolRequests, }; } diff --git a/js/plugins/dotprompt/tests/prompt_test.ts b/js/plugins/dotprompt/tests/prompt_test.ts index d73e2febaf..3c7a66761a 100644 --- a/js/plugins/dotprompt/tests/prompt_test.ts +++ b/js/plugins/dotprompt/tests/prompt_test.ts @@ -91,7 +91,7 @@ describe('Prompt', () => { }, ValidationError); }); - it('should render with streaming callback', async () => { + it('should render with overrided fields', async () => { const prompt = testPrompt(`Hello {{name}}, how are you?`); const streamingCallback = (c) => console.log(c); @@ -99,8 +99,10 @@ describe('Prompt', () => { const rendered = await prompt.render({ input: { name: 'Michael' }, streamingCallback, + returnToolRequests: true, }); assert.strictEqual(rendered.streamingCallback, streamingCallback); + assert.strictEqual(rendered.returnToolRequests, true); }); });