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:
LzSkyline
2024-07-30 16:53:08 +08:00
committed by GitHub
parent 9ad66983c3
commit 488170068c
13 changed files with 241 additions and 5 deletions
+27
View File
@@ -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()
}
+1
View File
@@ -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
}