Skip to content

Commit

Permalink
refactor: chatdto.statusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
pond918 committed May 31, 2023
1 parent 520a071 commit 9cf1db2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/bots/chat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +27,6 @@ export class ChatDto {
stateless?: boolean
} & Record<string, unknown> = {},
) {
code ? (this.code = code) : (this.id = nanoid())
statusCode ? (this.statusCode = statusCode) : (this.id = nanoid())
}
}
2 changes: 1 addition & 1 deletion src/bots/huggingface/GradioBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/storage/chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 9cf1db2

Please sign in to comment.