Skip to content

Commit

Permalink
feat(thread): add a ID to thread to help the application identify them
Browse files Browse the repository at this point in the history
  • Loading branch information
paztek committed Jan 21, 2024
1 parent 9df98ed commit debbf07
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 92 deletions.
16 changes: 7 additions & 9 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,21 @@ class ThreadMessageConverter {
}

class Thread extends EventEmitter {
constructor(messages = []) {
constructor(id, messages = []) {
super();
this.id = id;
this.messages = messages;
this._stream = null;
this.converter = new ThreadMessageConverter();
this.toolEmulator = new ToolEmulator();
}
get stream() {
if (!this._stream) {
return null;
}
return this._stream;
}
addMessage(message) {
this.doAddMessage(message);
}
async run(assistant) {
this._stream = new stream.Readable({
read: () => { },
});
try {
return await this.doRun(assistant);
}
Expand All @@ -155,13 +150,16 @@ class Thread extends EventEmitter {
}
}
async doRun(assistant) {
this._stream = new stream.Readable({
read: () => { },
});
this.emitImmediate('in_progress');
const messages = this.converter.convert(this.messages);
const stream = await assistant.streamChatCompletions(messages);
const stream$1 = await assistant.streamChatCompletions(messages);
let content = null;
const toolCalls = [];
let functionCall = undefined;
stream.on('data', (completion) => {
stream$1.on('data', (completion) => {
if (!completion.id || completion.id === '') {
// First completion is empty when using old models like gpt-35-turbo
return;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

12 changes: 5 additions & 7 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: 7 additions & 9 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.

12 changes: 5 additions & 7 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,21 @@ class ThreadMessageConverter {
}

class Thread extends EventEmitter {
constructor(messages = []) {
constructor(id, messages = []) {
super();
this.id = id;
this.messages = messages;
this._stream = null;
this.converter = new ThreadMessageConverter();
this.toolEmulator = new ToolEmulator();
}
get stream() {
if (!this._stream) {
return null;
}
return this._stream;
}
addMessage(message) {
this.doAddMessage(message);
}
async run(assistant) {
this._stream = new Readable({
read: () => { },
});
try {
return await this.doRun(assistant);
}
Expand All @@ -153,6 +148,9 @@ class Thread extends EventEmitter {
}
}
async doRun(assistant) {
this._stream = new Readable({
read: () => { },
});
this.emitImmediate('in_progress');
const messages = this.converter.convert(this.messages);
const stream = await assistant.streamChatCompletions(messages);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LLobotoMy for Azure

#### Defined in

[src/message/message.ts:32](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L32)
[src/message/message.ts:32](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L32)

___

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

#### Defined in

[src/message/message.ts:16](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L16)
[src/message/message.ts:16](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L16)

___

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

#### Defined in

[src/message/message.ts:20](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L20)
[src/message/message.ts:20](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L20)

___

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

#### Defined in

[src/message/message.ts:25](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L25)
[src/message/message.ts:25](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L25)

___

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

#### Defined in

[src/message/message.ts:12](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L12)
[src/message/message.ts:12](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L12)

___

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

#### Defined in

[src/message/message.ts:18](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L18)
[src/message/message.ts:18](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L18)

___

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

#### Defined in

[src/message/message.ts:14](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L14)
[src/message/message.ts:14](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L14)

___

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

#### Defined in

[src/message/message.ts:23](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L23)
[src/message/message.ts:23](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L23)

___

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

#### Defined in

[src/message/message.ts:10](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/message/message.ts#L10)
[src/message/message.ts:10](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/message/message.ts#L10)

## Functions

Expand All @@ -147,7 +147,7 @@ m is ChatRequestMessage

#### Defined in

[src/thread/thread.ts:262](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/thread/thread.ts#L262)
[src/thread/thread.ts:261](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/thread/thread.ts#L261)

___

Expand All @@ -167,4 +167,4 @@ m is ChatResponseMessage

#### Defined in

[src/thread/thread.ts:256](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/thread/thread.ts#L256)
[src/thread/thread.ts:255](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/thread/thread.ts#L255)
14 changes: 7 additions & 7 deletions docs/classes/Assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#### Defined in

[src/assistant/assistant.ts:26](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/assistant/assistant.ts#L26)
[src/assistant/assistant.ts:26](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/assistant/assistant.ts#L26)

## Properties

Expand All @@ -44,7 +44,7 @@

#### Defined in

[src/assistant/assistant.ts:19](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/assistant/assistant.ts#L19)
[src/assistant/assistant.ts:19](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/assistant/assistant.ts#L19)

___

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

#### Defined in

[src/assistant/assistant.ts:23](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/assistant/assistant.ts#L23)
[src/assistant/assistant.ts:23](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/assistant/assistant.ts#L23)

___

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

#### Defined in

[src/assistant/assistant.ts:21](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/assistant/assistant.ts#L21)
[src/assistant/assistant.ts:21](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/assistant/assistant.ts#L21)

___

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

#### Defined in

[src/assistant/assistant.ts:22](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/assistant/assistant.ts#L22)
[src/assistant/assistant.ts:22](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/assistant/assistant.ts#L22)

___

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

#### Defined in

[src/assistant/assistant.ts:24](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/assistant/assistant.ts#L24)
[src/assistant/assistant.ts:24](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/assistant/assistant.ts#L24)

## Methods

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

#### Defined in

[src/assistant/assistant.ts:34](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/assistant/assistant.ts#L34)
[src/assistant/assistant.ts:34](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/assistant/assistant.ts#L34)
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:241](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/thread/thread.ts#L241)
[src/thread/thread.ts:240](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/thread/thread.ts#L240)

## Properties

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

#### Defined in

[src/thread/thread.ts:241](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/thread/thread.ts#L241)
[src/thread/thread.ts:240](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/thread/thread.ts#L240)

___

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

#### Defined in

[src/thread/thread.ts:245](https://github.com/paztek/llobotomy-azure/blob/26afba8/src/thread/thread.ts#L245)
[src/thread/thread.ts:244](https://github.com/paztek/llobotomy-azure/blob/9df98ed/src/thread/thread.ts#L244)

___

Expand Down

0 comments on commit debbf07

Please sign in to comment.