kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: xt定制-根据不同模型分类有不同请求地址
rodzic
600b35eaec
commit
110431f167
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "chatgpt",
|
"name": "@tzzack/chatgpt",
|
||||||
"version": "5.2.2",
|
"version": "1.0.0",
|
||||||
"description": "Node.js client for the official ChatGPT API.",
|
"description": "Node.js client for the official ChatGPT API.",
|
||||||
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
"author": "Travis Fischer <travis@transitivebullsh.it>",
|
||||||
"repository": "transitive-bullshit/chatgpt-api",
|
"repository": "transitive-bullshit/chatgpt-api",
|
||||||
|
|
|
@ -181,7 +181,8 @@ export class ChatGPTAPI {
|
||||||
|
|
||||||
const responseP = new Promise<types.ChatMessage>(
|
const responseP = new Promise<types.ChatMessage>(
|
||||||
async (resolve, reject) => {
|
async (resolve, reject) => {
|
||||||
const url = `${this._apiBaseUrl}/chat/completions`
|
const model = completionParams.model
|
||||||
|
let url = `${this._apiBaseUrl}/chat/completions`
|
||||||
const headers = {
|
const headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${this._apiKey}`
|
Authorization: `Bearer ${this._apiKey}`
|
||||||
|
@ -193,6 +194,20 @@ export class ChatGPTAPI {
|
||||||
messages,
|
messages,
|
||||||
stream
|
stream
|
||||||
}
|
}
|
||||||
|
const isGpt = [
|
||||||
|
'gpt-4',
|
||||||
|
'gpt-4-0314',
|
||||||
|
'gpt-4-32k',
|
||||||
|
'gpt-4-32k-0314',
|
||||||
|
'gpt-3.5-turbo',
|
||||||
|
'gpt-3.5-turbo-0301'
|
||||||
|
].includes(model)
|
||||||
|
if (!isGpt) {
|
||||||
|
url = `${this._apiBaseUrl}/completions`
|
||||||
|
// @ts-ignore
|
||||||
|
body.prompt = messages[messages.length - 1].content
|
||||||
|
delete body.messages
|
||||||
|
}
|
||||||
|
|
||||||
// Support multiple organizations
|
// Support multiple organizations
|
||||||
// See https://platform.openai.com/docs/api-reference/authentication
|
// See https://platform.openai.com/docs/api-reference/authentication
|
||||||
|
@ -227,12 +242,18 @@ export class ChatGPTAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.choices?.length) {
|
if (response.choices?.length) {
|
||||||
const delta = response.choices[0].delta
|
if (isGpt) {
|
||||||
result.delta = delta.content
|
const delta = response.choices[0].delta
|
||||||
if (delta?.content) result.text += delta.content
|
result.delta = delta.content
|
||||||
|
if (delta?.content) result.text += delta.content
|
||||||
|
|
||||||
if (delta.role) {
|
if (delta.role) {
|
||||||
result.role = delta.role
|
result.role = delta.role
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
|
const text = response.choices[0].text
|
||||||
|
result.text += text
|
||||||
}
|
}
|
||||||
|
|
||||||
result.detail = response
|
result.detail = response
|
||||||
|
|
Ładowanie…
Reference in New Issue