From 746cbf0ed4e96335919c5489420e4d55f76ead1a Mon Sep 17 00:00:00 2001 From: PleahMaCaka Date: Thu, 2 Nov 2023 14:09:22 +0900 Subject: [PATCH] feat(client): clear history for debug mode --- src/lib/client/Client.ts | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib/client/Client.ts b/src/lib/client/Client.ts index 97ac62d..5ab2ca1 100644 --- a/src/lib/client/Client.ts +++ b/src/lib/client/Client.ts @@ -46,6 +46,15 @@ export const client = new class Client { }) } + public async clearHistory() { + stateStore.update((state) => { + return { + ...state, + history: [] + } + }) + } + // not tested public async removeLastHistory() { stateStore.update((state) => { @@ -78,7 +87,20 @@ export const client = new class Client { mode: "chat-instruct" }).then(async (res) => { await this.removeLastHistory() - await this.appendHistory(Author.Assistant, res) + if (get(stateStore).translate) { + const regex = /`([^`]*)`/g + + // extract commands from raw response + const commands = msg.match(regex) ?? [] + + const translated = await this.translateToKr(res) + + console.log(commands, translated) + + await this.appendHistory(Author.Assistant, commands + translated) + } else { + await this.appendHistory(Author.Assistant, res) + } }) } @@ -89,7 +111,13 @@ export const client = new class Client { } public async translateToKr(content: string): Promise { - return await this._axios.post(`${this._serverUrl}/service/translate/toKr`, content).then(res => res.data) + this.updateServerUrl() + + const res = await this._axios.post(`${this._serverUrl}/service/translate/toKr`, { + text: content + }) + + return res.data.text } }