mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-08-06 13:00:44 +08:00
Add Ollama native API to support keep alive parameters (#748)
* Add Chinese translation. * Optimize style. * Add Ollama native API to support keep alive parameters. * Optimized popup page style. * fix: Fixed data type for Ollama keep_alive parameter forever
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
export async function fetchSSE(resource, options) {
|
||||
const { onMessage, onStart, onEnd, onError, ...fetchOptions } = options
|
||||
const resp = await fetch(resource, fetchOptions).catch(async (err) => {
|
||||
await onError(err)
|
||||
})
|
||||
if (!resp) return
|
||||
if (!resp.ok) {
|
||||
await onError(resp)
|
||||
return
|
||||
}
|
||||
let hasStarted = false
|
||||
const reader = resp.body.getReader()
|
||||
let result
|
||||
while (!(result = await reader.read()).done) {
|
||||
const chunk = result.value
|
||||
const str = new TextDecoder().decode(chunk)
|
||||
if (!hasStarted) {
|
||||
const str = new TextDecoder().decode(chunk)
|
||||
hasStarted = true
|
||||
await onStart(str)
|
||||
}
|
||||
let data = JSON.parse(str)
|
||||
onMessage(data)
|
||||
if (data.done) break
|
||||
}
|
||||
await onEnd()
|
||||
}
|
||||
@@ -33,6 +33,7 @@ export async function fetchSSE(resource, options) {
|
||||
console.debug('not common response', error)
|
||||
}
|
||||
if (fakeSseData) {
|
||||
console.log('FAKE')
|
||||
parser.feed(new TextEncoder().encode(fakeSseData))
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user