Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Nov 21, 2023
1 parent 99972e3 commit 1008945
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
20 changes: 7 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ const messageLogAndSend = (message) => {
}

let errorlogFile = fs.createWriteStream(path.join(LOG_PATH, 'error_log.txt'), { flags: 'w' })
console.error = (...message) => {
errorlogFile.write(format(...message) + '\n')
process.stderr.write(format(...message) + '\n')
}
process
.on('unhandledRejection', (reason, promise) => {
errorlogFile.write(format('Unhandled Rejection at:', promise, 'reason:', reason) + '\n')
console.error('Unhandled Rejection at:', promise, 'reason:', reason)
})
.on('uncaughtException', err => {
errorlogFile.write(format(err, 'Uncaught Exception thrown') + '\n')
console.error(err, 'Uncaught Exception thrown')
process.exit(1)
})
Expand Down Expand Up @@ -240,7 +242,7 @@ const speakPrompt = async ({ text, preAudioPath }) => {
resolveSpeakTextList()
}
} catch (e) {
console.log(e)
console.error(e)
resolveSpeakTextList()
}
}
Expand Down Expand Up @@ -332,12 +334,11 @@ const resolveMessages = async ({ resToolCalls, resText, resTextTemp, messages, f
break
}
} catch (e) {
console.log(e)
console.error(e)
functionCallResult = e.message
}
messages.push({ role: 'tool', tool_call_id: toolCall.id, content: functionCallResult + '' })
// addHistory([{ role: 'tool', tool_call_id: toolCall.id, content: functionCallResult + '' }])
console.log({ role: 'tool', tool_call_id: toolCall.id, content: functionCallResult + '' })
messageLogAndSend({
id: nanoid(),
from: 'Function Calling',
Expand Down Expand Up @@ -495,7 +496,7 @@ const resloveAdminPrompt = async ({ prompt, promptType = 'string', triggerRecord
})
}
} catch (e) {
console.log(e)
console.error(e)
if (triggerRecord && STATUS.isSpeechTalk) triggerSpeech()
}
return resText
Expand Down Expand Up @@ -567,18 +568,11 @@ const triggerSpeech = async () => {
}

ipcMain.handle('send-prompt', async (event, prompt) => {
console.log('prompt', prompt)
resloveAdminPrompt({
prompt: prompt.content,
promptType: prompt.type
})
})
ipcMain.handle('get-admin-name', async () => {
return ADMIN_NAME
})
ipcMain.handle('open-config', async () => {
shell.openExternal(path.join(STORE_PATH, 'config.json'))
})
ipcMain.handle('switch-speech-talk', async () => {
STATUS.isSpeechTalk = !STATUS.isSpeechTalk
STATUS.isAudioPlay = STATUS.isSpeechTalk
Expand Down
3 changes: 2 additions & 1 deletion modules/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ const readFileFromDisk = async ({ filePath }) => {
return await fs.promises.readFile(filePath, { encoding: 'utf-8' })
}

const javaScriptInterpreter = async ({ code }) => {uickjs = await getQuickJS()
const javaScriptInterpreter = async ({ code }) => {
const quickjs = await getQuickJS()
let result = quickjs.evalCode(code, {
shouldInterrupt: shouldInterruptAfterDeadline(Date.now() + 10000),
memoryLimitBytes: 100 * 1024 * 1024,
Expand Down
12 changes: 5 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const printMessage = (type, msg, option) => {
const messageHistory = ref([])
let ADMIN_NAME
onMounted(() => ipcRenderer.invoke('get-admin-name').then(name => ADMIN_NAME = name))
const renderCodeBlocks = (text) => {
return text.replace(/```(\w+)\n((?:(?!```)[\s\S])*)(?:```)?/g, (match, language, code) => {
return `<pre class="code-block${language ? ` language-${language}` : ''}"><code class="${language ? `language-${language}` : ''}">${code.trim()}</code></pre>`
Expand Down Expand Up @@ -111,7 +108,7 @@ const sendText = (event) => {
})
messageHistory.value.push({
id: nanoid(),
from: ADMIN_NAME,
from: config.value.ADMIN_NAME,
text: inputText.value,
images: imageBlobUrlList.value
})
Expand All @@ -124,7 +121,7 @@ const sendText = (event) => {
})
messageHistory.value.push({
id: nanoid(),
from: ADMIN_NAME,
from: config.value.ADMIN_NAME,
text: inputText.value
})
}
Expand All @@ -135,7 +132,8 @@ const scrollToBottom = (id) => {
const element = document.getElementById(id)
element.scrollTop = element.scrollHeight
}
// API Key Check
// config
const setting = ref(null)
const config = ref({})
onMounted(async () => {
Expand Down Expand Up @@ -227,7 +225,7 @@ const removeImage = (index) => {
<n-card v-for="message in messageHistory" :key="message.id" class="message-card">
<n-thing>
<template #avatar>
<n-avatar v-if="[ADMIN_NAME, `(${ADMIN_NAME})`, '群聊'].includes(message.from)" size="small">
<n-avatar v-if="[config.ADMIN_NAME, `(${config.ADMIN_NAME})`, '群聊'].includes(message.from)" size="small">
<n-icon><UserCircle /></n-icon>
</n-avatar>
<n-avatar v-else size="small" :src="XiuliuAvatar"></n-avatar>
Expand Down

0 comments on commit 1008945

Please sign in to comment.