Skip to content

Commit

Permalink
fix: update ollama provider stream handler (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
sytranvn authored Sep 25, 2024
1 parent e8815d9 commit a18721c
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions ai-providers/ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ class OllamaByteSource implements UnderlyingByteSource {
}

async pull (controller: ReadableByteStreamController): Promise<void> {
const { done, value } = await this.response.next()
if (done !== undefined && done) {
controller.close()
return
}
for await (const { done, message } of this.response) {
let response = message.content
if (this.chunkCallback !== undefined) {
response = await this.chunkCallback(response)
}

let response = value.message.content
if (this.chunkCallback !== undefined) {
response = await this.chunkCallback(response)
}
const eventData: AiStreamEvent = {
event: 'content',
data: {
response
}
}
controller.enqueue(encodeEvent(eventData))

const eventData: AiStreamEvent = {
event: 'content',
data: {
response
if (done !== undefined && done) {
controller.close()
return
}
}
controller.enqueue(encodeEvent(eventData))
}
}

Expand Down

0 comments on commit a18721c

Please sign in to comment.