Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions packages/sdk/src/LLM/Chat.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class LocalChatStore extends SDKObject implements ILLMContextStore {
public get id() {
return this._conversationId;
}
constructor(private _conversationId: string, candidate: AccessCandidate) {
constructor(
private _conversationId: string,
candidate: AccessCandidate,
) {
super();
this._storage = new StorageInstance(null, null, candidate);
}
Expand Down Expand Up @@ -46,7 +49,11 @@ class LocalChatStore extends SDKObject implements ILLMContextStore {
class ChatCommand {
private _conversation: Conversation;

constructor(private prompt: string, private chat: Chat, private options?: PromptOptions) {
constructor(
private prompt: string,
private chat: Chat,
private options?: PromptOptions,
) {
this._conversation = chat._conversation;
}

Expand All @@ -57,7 +64,12 @@ class ChatCommand {
private async run(): Promise<string> {
await this.chat.ready;
await this._conversation.ready; //when we switch agent mode at runtime, we need to wait for the conversation to be ready
const result = await this._conversation.streamPrompt(this.prompt, this.options?.headers, this.options?.concurrentCalls);
const result = await this._conversation.streamPrompt(
this.prompt,
this.options?.headers,
this.options?.concurrentCalls,
this.options?.abortSignal,
);
return result;
}

Expand Down Expand Up @@ -151,9 +163,11 @@ class ChatCommand {
this._conversation.on(TLLMEvent.Data, dataHandler);

// Start the streaming process - don't await as we want to return the eventEmitter immediately
this._conversation.streamPrompt(this.prompt, this.options?.headers, this.options?.concurrentCalls).catch((error) => {
eventEmitter.emit(TLLMEvent.Error, error);
});
this._conversation
.streamPrompt(this.prompt, this.options?.headers, this.options?.concurrentCalls, this.options?.abortSignal)
.catch((error) => {
eventEmitter.emit(TLLMEvent.Error, error);
});
return eventEmitter;
}
}
Expand Down Expand Up @@ -187,7 +201,11 @@ export class Chat extends SDKObject {
public get agentData() {
return this._data;
}
constructor(options: ChatOptions & { candidate: AccessCandidate }, private source?: Agent | Record<string, any>, private _convOptions: any = {}) {
constructor(
options: ChatOptions & { candidate: AccessCandidate },
private source?: Agent | Record<string, any>,
private _convOptions: any = {},
) {
super();

const _data = source?.data || source || {};
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/SDKTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type ChatOptions = {
export type PromptOptions = {
headers?: Record<string, string>;
concurrentCalls?: number;
abortSignal?: AbortSignal;
};

export enum Scope {
Expand Down