Skip to content

Commit

Permalink
Fix OpenAI response parse failure when the content filter is turned on (
Browse files Browse the repository at this point in the history
  • Loading branch information
blrchen committed Jun 23, 2024
1 parent 5613aba commit 2d8939d
Show file tree
Hide file tree
Showing 3 changed files with 987 additions and 761 deletions.
11 changes: 8 additions & 3 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ const getOpenAIStream = async (

try {
const json = JSON.parse(data)
const text = json.choices[0]?.delta.content
const queue = encoder.encode(text)
controller.enqueue(queue)
const text = json.choices[0]?.delta?.content
if (text !== undefined) {
const queue = encoder.encode(text)
controller.enqueue(queue)
} else {
console.error('Received undefined content:', json)
}
} catch (e) {
console.error('Error parsing event data:', e)
controller.error(e)
}
}
Expand Down
Loading

0 comments on commit 2d8939d

Please sign in to comment.