You've already forked bilibili-subtitle
init
This commit is contained in:
20
src/chrome/openaiService.ts
Normal file
20
src/chrome/openaiService.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {getServerUrl} from '../util/biz_util'
|
||||
|
||||
export const handleChatCompleteTask = async (task: Task) => {
|
||||
const data = task.def.data
|
||||
const serverUrl = getServerUrl(task.def.serverUrl)
|
||||
const resp = await fetch(`${serverUrl}/v1/chat/completions`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: 'Bearer ' + task.def.extra.apiKey,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
task.resp = await resp.json()
|
||||
if (task.resp.usage) {
|
||||
return (task.resp.usage.total_tokens??0) > 0
|
||||
} else {
|
||||
throw new Error(`${task.resp.error.code as string??''} ${task.resp.error.message as string ??''}`)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user