Skip to content

Commit

Permalink
fix: runTools without stream should not emit user message events (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjp20 authored Sep 3, 2024
1 parent d935ad3 commit 22ded4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/lib/ChatCompletionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ export class ChatCompletionRunner<ParsedT = null> extends AbstractChatCompletion
return runner;
}

override _addMessage(this: ChatCompletionRunner<ParsedT>, message: ChatCompletionMessageParam) {
super._addMessage(message);
override _addMessage(
this: ChatCompletionRunner<ParsedT>,
message: ChatCompletionMessageParam,
emit: boolean = true,
) {
super._addMessage(message, emit);
if (isAssistantMessage(message) && message.content) {
this._emit('content', message.content as string);
}
Expand Down
12 changes: 0 additions & 12 deletions tests/lib/ChatCompletionRunFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,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 @@ -700,7 +699,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 @@ -855,10 +853,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 @@ -1090,10 +1084,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 @@ -1207,7 +1197,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 @@ -1413,7 +1402,6 @@ describe('resource completions', () => {
]);

expect(listener.messages).toEqual([
{ role: 'user', content: 'tell me what the weather is like' },
{
role: 'assistant',
content: null,
Expand Down

0 comments on commit 22ded4d

Please sign in to comment.