Skip to content

Commit

Permalink
fix: groq frequently stops during long responses (#2584)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Apr 2, 2024
1 parent 3fded8f commit fe89901
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions core/src/browser/extensions/engines/helpers/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ export function requestInference(
}
const text = decoder.decode(value)
const lines = text.trim().split('\n')
let cachedLines = ''
for (const line of lines) {
if (line.startsWith('data: ') && !line.includes('data: [DONE]')) {
const data = JSON.parse(line.replace('data: ', ''))
content += data.choices[0]?.delta?.content ?? ''
if (content.startsWith('assistant: ')) {
content = content.replace('assistant: ', '')
try {
const toParse = cachedLines + line
if (!line.includes('data: [DONE]')) {
const data = JSON.parse(toParse.replace('data: ', ''))
content += data.choices[0]?.delta?.content ?? ''
if (content.startsWith('assistant: ')) {
content = content.replace('assistant: ', '')
}
if (content !== '') subscriber.next(content)
}
subscriber.next(content)
} catch {
cachedLines = line
}
}
}
Expand Down

0 comments on commit fe89901

Please sign in to comment.