Skip to content

Commit

Permalink
update loading before answer
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Nov 10, 2023
1 parent 487f375 commit c14e658
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declare module 'vue' {
NPopover: typeof import('naive-ui')['NPopover']
NSelect: typeof import('naive-ui')['NSelect']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NSwitch: typeof import('naive-ui')['NSwitch']
NThing: typeof import('naive-ui')['NThing']
NUpload: typeof import('naive-ui')['NUpload']
Expand Down
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ const resolveMessages = async ({ resToolCalls, resText, resTextTemp, messages, f
let speakIndex = STATUS.speakIndex
STATUS.speakIndex += 1

if (!resText && !_.isEmpty(resToolCalls)) {
if (!_.isEmpty(resToolCalls)) {
messageLogAndSend({
id: nanoid(),
from,
Expand Down Expand Up @@ -346,6 +346,13 @@ const resolveMessages = async ({ resToolCalls, resText, resTextTemp, messages, f
prepareChatOption.tool_choice = 'auto'
}

// alert chat
messageSend({
id: clientMessageId,
from,
content: ''
})

for await (const { token, f_token } of useOpenaiChatStreamFunction(prepareChatOption)) {
if (token) {
resTextTemp += token
Expand All @@ -372,7 +379,6 @@ const resolveMessages = async ({ resToolCalls, resText, resTextTemp, messages, f
}
}
}
if (!_.isEmpty(f_token)) console.log(f_token)
let [{ index, id, type, function: { name, arguments: arg} } = { function: {} }] = f_token
if (index !== undefined ) {
if (resToolCalls[index]) {
Expand All @@ -397,7 +403,13 @@ const resolveMessages = async ({ resToolCalls, resText, resTextTemp, messages, f
})
}
}
if (resText) {
if (_.isEmpty(resText)) {
messageSend({
id: clientMessageId,
from,
action: 'revoke'
})
} else {
messageSend({
id: clientMessageId,
from,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chat-xiuliu",
"private": true,
"version": "2.2.0",
"version": "2.2.1",
"description": "ChatGPT Client with Function Calling",
"author": "SchneeHertz",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const escapeHtml = (unsafe) => {
onMounted(() => {
ipcRenderer.on('send-message', (event, arg) => {
if (arg.action === 'revoke') {
messageHistory.value = _.filter(messageHistory.value, m => m.id !== arg.id)
return
}
if (typeof arg.content === 'string') {
arg.text = renderCodeBlocks(escapeHtml(arg.content))
} else {
Expand Down Expand Up @@ -155,6 +159,7 @@ const switchAudio = () => {
}
const emptyHistory = () => {
ipcRenderer.invoke('empty-history')
messageHistory.value = []
}
const saveCapture = async () => {
const screenshotTarget = document.querySelector('#message-list')
Expand Down Expand Up @@ -203,6 +208,7 @@ const resolveImage = async ({ file }) => {
{{message.from}}
</template>
<pre v-html="message.text"></pre>
<n-spin size="small" v-if="!message.text" />
<p v-if="message.countToken" class="token-count">Used {{ message.tokenCount }} tokens</p>
</n-thing>
</n-card>
Expand Down

0 comments on commit c14e658

Please sign in to comment.