添加文案处理的功能
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
type OpenAISuccessResponse = {
|
||||
id: string
|
||||
object: string
|
||||
created: number
|
||||
model: string
|
||||
choices: [
|
||||
{
|
||||
index: number
|
||||
message: {
|
||||
role: string
|
||||
content: string
|
||||
}
|
||||
finish_reason: string
|
||||
}
|
||||
]
|
||||
usage: {
|
||||
prompt_tokens: number
|
||||
completion_tokens: number
|
||||
total_tokens: number
|
||||
}
|
||||
}
|
||||
|
||||
type RixApiErrorResponse = {
|
||||
error: {
|
||||
message: string // 错误信息
|
||||
type: string
|
||||
param: string
|
||||
code: string
|
||||
}
|
||||
}
|
||||
|
||||
type KimiErrorResponse = {
|
||||
error: {
|
||||
message: string
|
||||
type: string
|
||||
}
|
||||
}
|
||||
|
||||
type DoubaoErrorResponse = {
|
||||
error: {
|
||||
code: string
|
||||
message: string
|
||||
param: string
|
||||
type: string
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理OpenAI系列返回的成功response
|
||||
* @param response OpenAI返回的response
|
||||
* @returns 处理后的返回的数据
|
||||
*/
|
||||
export function GetOpenAISuccessResponse(response: string | OpenAISuccessResponse): string {
|
||||
if (typeof response === 'string') {
|
||||
response = JSON.parse(response) as OpenAISuccessResponse
|
||||
}
|
||||
// 开始处理response
|
||||
return response.choices[0].message.content
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理RixApi系列返回的错误response
|
||||
* @param response RixApi返回的response
|
||||
* @returns 处理后的错误信息
|
||||
*/
|
||||
export function GetRixApiErrorResponse(response: string | RixApiErrorResponse): string {
|
||||
if (typeof response === 'string') {
|
||||
response = JSON.parse(response) as RixApiErrorResponse
|
||||
}
|
||||
return response.error.message
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理kimi的错误信息返回
|
||||
* @param response
|
||||
* @returns
|
||||
*/
|
||||
export function GetKimiErrorResponse(response: string | KimiErrorResponse): string {
|
||||
if (typeof response === 'string') {
|
||||
response = JSON.parse(response) as KimiErrorResponse
|
||||
}
|
||||
return response.error.message
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取豆包的错误返回信息
|
||||
* @param response
|
||||
* @returns
|
||||
*/
|
||||
export function GetDoubaoErrorResponse(response: string | DoubaoErrorResponse): string {
|
||||
if (typeof response === 'string') {
|
||||
response = JSON.parse(response) as DoubaoErrorResponse
|
||||
}
|
||||
return response.error.message
|
||||
}
|
||||
Reference in New Issue
Block a user