Skip to content

Commit

Permalink
feat(client): implement translation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PleahMaCaka committed Nov 2, 2023
1 parent 46fa0ad commit f85d658
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/lib/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,25 @@ export const client = new class Client {
mode: "chat-instruct"
}).then(async (res) => {
await this.removeLastHistory()
if (get(stateStore).translate) {
const regex = /`([^`]*)`/g
if (!get(stateStore).translate)
return await this.appendHistory(Author.Assistant, res)

// extract commands from raw response
const commands = msg.match(regex) ?? []
// translate without a command
const regex: RegExp = /`([^`]*)`/g

const translated = await this.translateToKr(res)
// [`cmd1`, `cmd2 arg`]
const commands = res.match(regex)

console.log(commands, translated)
// `cmd1` `cmd2 arg`
const mergedCommands = commands?.join(" ") ?? ""

await this.appendHistory(Author.Assistant, commands + translated)
} else {
await this.appendHistory(Author.Assistant, res)
}
// translated message without commands
const translated = await this.translateToKr(res.replace(regex, "").trim())

console.log(commands)
console.log(translated)

await this.appendHistory(Author.Assistant, `${translated} ${mergedCommands}`)
})
}

Expand Down

0 comments on commit f85d658

Please sign in to comment.