Skip to content

Commit

Permalink
improve delta process (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed Mar 23, 2024
1 parent dba68e7 commit d49280c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/services/apis/custom-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ export async function generateAnswersWithCustomApi(port, question, session, apiK
}

if (data.response) answer = data.response
else
answer +=
data.choices[0]?.delta?.content ||
data.choices[0]?.message?.content ||
data.choices[0]?.text ||
''
else {
const delta = data.choices[0]?.delta?.content
const content = data.choices[0]?.message?.content
const text = data.choices[0]?.text
if (delta !== undefined) {
answer += delta
} else if (content) {
answer = content
} else if (text) {
answer += text
}
}
port.postMessage({ answer: answer, done: false, session: null })
},
async onStart() {},
Expand Down
15 changes: 10 additions & 5 deletions src/services/apis/openai-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,16 @@ export async function generateAnswersWithChatgptApiCompat(
console.debug('json error', error)
return
}
answer +=
data.choices[0]?.delta?.content ||
data.choices[0]?.message?.content ||
data.choices[0]?.text ||
''
const delta = data.choices[0]?.delta?.content
const content = data.choices[0]?.message?.content
const text = data.choices[0]?.text
if (delta !== undefined) {
answer += delta
} else if (content) {
answer = content
} else if (text) {
answer += text
}
port.postMessage({ answer: answer, done: false, session: null })
},
async onStart() {},
Expand Down

0 comments on commit d49280c

Please sign in to comment.