Feat/chat support voice input (#532)

This commit is contained in:
zxhlyh
2023-07-07 17:50:42 +08:00
committed by GitHub
parent feebb5dd1f
commit a03a92e9db
70 changed files with 1420 additions and 26 deletions

View File

@@ -35,7 +35,9 @@ export type IOnError = (msg: string) => void
type IOtherOptions = {
isPublicAPI?: boolean
bodyStringify?: boolean
needAllResponseContent?: boolean
deleteContentType?: boolean
onData?: IOnData // for stream
onError?: IOnError
onCompleted?: IOnCompleted // for stream
@@ -132,7 +134,9 @@ const baseFetch = (
fetchOptions: any,
{
isPublicAPI = false,
bodyStringify = true,
needAllResponseContent,
deleteContentType,
}: IOtherOptions,
) => {
const options = Object.assign({}, baseOptions, fetchOptions)
@@ -141,6 +145,15 @@ const baseFetch = (
options.headers.set('Authorization', `bearer ${sharedToken}`)
}
if (deleteContentType) {
options.headers.delete('Content-Type')
}
else {
const contentType = options.headers.get('Content-Type')
if (!contentType)
options.headers.set('Content-Type', ContentType.json)
}
const urlPrefix = isPublicAPI ? PUBLIC_API_PREFIX : API_PREFIX
let urlWithPrefix = `${urlPrefix}${url.startsWith('/') ? url : `/${url}`}`
@@ -160,7 +173,7 @@ const baseFetch = (
delete options.params
}
if (body)
if (body && bodyStringify)
options.body = JSON.stringify(body)
// Handle timeout
@@ -285,6 +298,10 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
signal: abortController.signal,
}, fetchOptions)
const contentType = options.headers.get('Content-Type')
if (!contentType)
options.headers.set('Content-Type', ContentType.json)
getAbortController?.(abortController)
const urlPrefix = isPublicAPI ? PUBLIC_API_PREFIX : API_PREFIX