Skip to content

Commit

Permalink
fix(thread): fix end of stream
Browse files Browse the repository at this point in the history
  • Loading branch information
paztek committed Dec 11, 2023
1 parent e1e610a commit 98d0f02
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 119 deletions.
16 changes: 13 additions & 3 deletions dist/index.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* llobotomy-azure v0.0.1
* llobotomy-azure v0.0.2
* (c) Matthieu Balmes
* Released under the MIT License.
*/
Expand Down Expand Up @@ -37,16 +37,22 @@ class Thread extends EventEmitter {
constructor(messages = []) {
super();
this.messages = messages;
this._stream = new stream.PassThrough();
this._stream = null;
}
get stream() {
if (!this._stream) {
return null;
}
return this._stream;
}
addMessage(message) {
this.messages.push(message);
this.emit('message', message);
}
run(assistant) {
this._stream = new stream.Readable({
read: () => { },
});
this.doRun(assistant);
}
doRun(assistant) {
Expand Down Expand Up @@ -190,7 +196,10 @@ class Thread extends EventEmitter {
if (delta.content) {
content += delta.content;
// Write also to the stream of the thread
this._stream.write(delta.content);
if (!this._stream) {
throw new Error('No stream available');
}
this._stream?.push(delta.content);
}
if (choice.finishReason === 'stop') {
// Adds the assistant's response to the messages
Expand All @@ -200,6 +209,7 @@ class Thread extends EventEmitter {
};
this.addMessage(message);
this.emit('completed');
this._stream?.push(null);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.esm.js.map

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*!
* llobotomy-azure v0.0.1
* llobotomy-azure v0.0.2
* (c) Matthieu Balmes
* Released under the MIT License.
*/

import { Readable, PassThrough } from 'stream';
import { Readable } from 'stream';
import EventEmitter from 'events';

class Assistant {
Expand Down Expand Up @@ -35,16 +35,22 @@ class Thread extends EventEmitter {
constructor(messages = []) {
super();
this.messages = messages;
this._stream = new PassThrough();
this._stream = null;
}
get stream() {
if (!this._stream) {
return null;
}
return this._stream;
}
addMessage(message) {
this.messages.push(message);
this.emit('message', message);
}
run(assistant) {
this._stream = new Readable({
read: () => { },
});
this.doRun(assistant);
}
doRun(assistant) {
Expand Down Expand Up @@ -188,7 +194,10 @@ class Thread extends EventEmitter {
if (delta.content) {
content += delta.content;
// Write also to the stream of the thread
this._stream.write(delta.content);
if (!this._stream) {
throw new Error('No stream available');
}
this._stream?.push(delta.content);
}
if (choice.finishReason === 'stop') {
// Adds the assistant's response to the messages
Expand All @@ -198,6 +207,7 @@ class Thread extends EventEmitter {
};
this.addMessage(message);
this.emit('completed');
this._stream?.push(null);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ LLobotoMy for Azure
### Interfaces

- [AssistantCreateParams](interfaces/AssistantCreateParams.md)
- [FunctionTool](interfaces/FunctionTool.md)
- [ToolCall](interfaces/ToolCall.md)
- [ToolOutput](interfaces/ToolOutput.md)
12 changes: 6 additions & 6 deletions docs/classes/Assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#### Defined in

[src/assistant/assistant.ts:20](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/assistant/assistant.ts#L20)
[src/assistant/assistant.ts:20](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/assistant/assistant.ts#L20)

## Properties

Expand All @@ -43,7 +43,7 @@

#### Defined in

[src/assistant/assistant.ts:14](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/assistant/assistant.ts#L14)
[src/assistant/assistant.ts:14](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/assistant/assistant.ts#L14)

___

Expand All @@ -53,7 +53,7 @@ ___

#### Defined in

[src/assistant/assistant.ts:18](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/assistant/assistant.ts#L18)
[src/assistant/assistant.ts:18](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/assistant/assistant.ts#L18)

___

Expand All @@ -63,7 +63,7 @@ ___

#### Defined in

[src/assistant/assistant.ts:17](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/assistant/assistant.ts#L17)
[src/assistant/assistant.ts:17](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/assistant/assistant.ts#L17)

___

Expand All @@ -73,7 +73,7 @@ ___

#### Defined in

[src/assistant/assistant.ts:16](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/assistant/assistant.ts#L16)
[src/assistant/assistant.ts:16](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/assistant/assistant.ts#L16)

## Methods

Expand All @@ -93,4 +93,4 @@ ___

#### Defined in

[src/assistant/assistant.ts:27](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/assistant/assistant.ts#L27)
[src/assistant/assistant.ts:27](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/assistant/assistant.ts#L27)
6 changes: 3 additions & 3 deletions docs/classes/RequiredAction.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ EventEmitter.constructor

#### Defined in

[src/thread/thread.ts:207](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L207)
[src/thread/thread.ts:218](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L218)

## Properties

Expand All @@ -77,7 +77,7 @@ EventEmitter.constructor

#### Defined in

[src/thread/thread.ts:205](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L205)
[src/thread/thread.ts:216](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L216)

___

Expand Down Expand Up @@ -934,7 +934,7 @@ ___

#### Defined in

[src/thread/thread.ts:216](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L216)
[src/thread/thread.ts:227](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L227)

___

Expand Down
24 changes: 12 additions & 12 deletions docs/classes/Thread.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ EventEmitter.constructor

#### Defined in

[src/thread/thread.ts:9](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L9)
[src/thread/thread.ts:9](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L9)

## Properties

### \_stream

`Private` **\_stream**: `PassThrough`
`Private` **\_stream**: ``null`` \| `Readable` = `null`

#### Defined in

[src/thread/thread.ts:7](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L7)
[src/thread/thread.ts:7](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L7)

___

Expand All @@ -96,7 +96,7 @@ ___

#### Defined in

[src/thread/thread.ts:9](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L9)
[src/thread/thread.ts:9](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L9)

___

Expand Down Expand Up @@ -221,15 +221,15 @@ node_modules/@types/node/events.d.ts:395

### stream

`get` **stream**(): `Readable`
`get` **stream**(): ``null`` \| `Readable`

#### Returns

`Readable`
``null`` \| `Readable`

#### Defined in

[src/thread/thread.ts:13](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L13)
[src/thread/thread.ts:13](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L13)

## Methods

Expand Down Expand Up @@ -306,7 +306,7 @@ ___

#### Defined in

[src/thread/thread.ts:17](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L17)
[src/thread/thread.ts:21](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L21)

___

Expand All @@ -326,7 +326,7 @@ ___

#### Defined in

[src/thread/thread.ts:26](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L26)
[src/thread/thread.ts:33](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L33)

___

Expand Down Expand Up @@ -494,7 +494,7 @@ The first choice of these completions successively looks like this:

#### Defined in

[src/thread/thread.ts:170](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L170)
[src/thread/thread.ts:177](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L177)

___

Expand Down Expand Up @@ -533,7 +533,7 @@ The first choice of these completions successively looks like this:

#### Defined in

[src/thread/thread.ts:92](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L92)
[src/thread/thread.ts:99](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L99)

___

Expand Down Expand Up @@ -1048,7 +1048,7 @@ ___

#### Defined in

[src/thread/thread.ts:22](https://github.com/paztek/llobotomy-azure/blob/a12ace7/src/thread/thread.ts#L22)
[src/thread/thread.ts:26](https://github.com/paztek/llobotomy-azure/blob/6b547f5/src/thread/thread.ts#L26)

___

Expand Down
Loading

0 comments on commit 98d0f02

Please sign in to comment.