Skip to content

Commit

Permalink
fix: runTools without stream should not emit user message events
Browse files Browse the repository at this point in the history
  • Loading branch information
yjp20 committed Aug 20, 2024
1 parent f1a4a68 commit 4162ba9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/lib/ChatCompletionRunFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ describe('resource completions', () => {
await runner.done();

expect(listener.messages).toEqual([
{ role: 'user', content: 'tell me what the weather is like' },
{
role: 'assistant',
content: null,
Expand Down Expand Up @@ -747,7 +746,6 @@ describe('resource completions', () => {
await runner.done().catch(() => {});

expect(listener.messages).toEqual([
{ role: 'user', content: 'tell me what the weather is like' },
{
role: 'assistant',
content: null,
Expand Down Expand Up @@ -893,10 +891,6 @@ describe('resource completions', () => {
await runner.done();

expect(listener.messages).toEqual([
{
role: 'user',
content: 'can you tell me how many properties are in {"a": 1, "b": 2, "c": 3}',
},
{
role: 'assistant',
content: null,
Expand Down Expand Up @@ -1102,10 +1096,6 @@ describe('resource completions', () => {
]);

expect(listener.messages).toEqual([
{
role: 'user',
content: 'can you tell me how many properties are in {"a": 1, "b": 2, "c": 3}',
},
{
role: 'assistant',
content: null,
Expand Down Expand Up @@ -1199,7 +1189,6 @@ describe('resource completions', () => {
]);

expect(listener.messages).toEqual([
{ role: 'user', content: 'tell me what the weather is like' },
{
role: 'assistant',
content: null,
Expand Down Expand Up @@ -1388,7 +1377,6 @@ describe('resource completions', () => {
]);

expect(listener.messages).toEqual([
{ role: 'user', content: 'tell me what the weather is like' },
{
role: 'assistant',
content: null,
Expand Down
8 changes: 6 additions & 2 deletions src/lib/ChatCompletionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ export class ChatCompletionRunner extends AbstractChatCompletionRunner<ChatCompl
return runner;
}

override _addMessage(this: ChatCompletionRunner, message: ChatCompletionMessageParam) {
super._addMessage(message);
override _addMessage(
this: ChatCompletionRunner,
message: ChatCompletionMessageParam,
emit: boolean = true,
) {
super._addMessage(message, emit);
if (isAssistantMessage(message) && message.content) {
this._emit('content', message.content as string);
}
Expand Down

0 comments on commit 4162ba9

Please sign in to comment.