Skip to content

Commit

Permalink
feat(client): clear history for debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
PleahMaCaka committed Nov 2, 2023
1 parent cff7f4d commit 746cbf0
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/lib/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
}
})
}

Expand All @@ -89,7 +111,13 @@ export const client = new class Client {
}

public async translateToKr(content: string): Promise<string> {
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
}

}

0 comments on commit 746cbf0

Please sign in to comment.