From 9cf1db241126465e0829357bce2addb2db84f2c1 Mon Sep 17 00:00:00 2001 From: pond918 Date: Wed, 31 May 2023 08:35:06 +0800 Subject: [PATCH] refactor: chatdto.statusCode --- src/bots/chat.dto.ts | 9 +++++---- src/bots/huggingface/GradioBot.ts | 2 +- src/storage/chat-history.ts | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bots/chat.dto.ts b/src/bots/chat.dto.ts index a868094..5adfc3c 100644 --- a/src/bots/chat.dto.ts +++ b/src/bots/chat.dto.ts @@ -4,15 +4,16 @@ export class ChatDto { /** local msg id */ readonly id?: string /** status code. empty means ok; positive means still processing; negative means no more processing */ - readonly code?: number + statusCode?: number + message?: string /** - * @param code status code. empty means ok; positive means still processing; negative means no more processing + * @param statusCode status code. empty means ok; positive means still processing; negative means no more processing * @param options */ constructor( public prompt: string | string[], - code = 0, + statusCode = 0, public readonly options: { /** msg type: true: response, false: request */ resp?: boolean @@ -26,6 +27,6 @@ export class ChatDto { stateless?: boolean } & Record = {}, ) { - code ? (this.code = code) : (this.id = nanoid()) + statusCode ? (this.statusCode = statusCode) : (this.id = nanoid()) } } diff --git a/src/bots/huggingface/GradioBot.ts b/src/bots/huggingface/GradioBot.ts index 4ca1fb8..263b9f2 100644 --- a/src/bots/huggingface/GradioBot.ts +++ b/src/bots/huggingface/GradioBot.ts @@ -57,7 +57,7 @@ export default abstract class GradioBot extends LLMBot { for (const key in this._fnIndexes) { const fn_index = this._fnIndexes[key] const resp = await this._sendFnIndex(fn_index, prompt, streamCallback) - resp && !resp.code && resp.prompt && (result = resp) + resp && !resp.statusCode && resp.prompt && (result = resp) } return result } diff --git a/src/storage/chat-history.ts b/src/storage/chat-history.ts index 9f3b6cf..868b0b7 100644 --- a/src/storage/chat-history.ts +++ b/src/storage/chat-history.ts @@ -18,7 +18,7 @@ export class ChatHistory { // async append(msg: ChatDto & { prompt: string }) { async append(msg: ChatDto) { if (msg.options.compound) throw new Error('chat.history.append.compound.not.allowed') - if (msg.code) throw new Error('chat.history.append.undone.not.allowed') + if (msg.statusCode) throw new Error('chat.history.append.undone.not.allowed') let branched = false @@ -68,7 +68,7 @@ export class ChatHistory { if (!(mid = m.options.lastMsgId)) break } } - const retMsg = new ChatDto(ret.reverse(), msg.code, { ...msg.options, compound: 1 }) + const retMsg = new ChatDto(ret.reverse(), msg.statusCode, { ...msg.options, compound: 1 }) _conversationKey && (retMsg.options._conversationKey = _conversationKey) return retMsg }