尝试将文本聊天-davinci-002-20230126 与 OpenAI API 一起使用现在会返回 404 错误。有人已经找到了新型号名称,但此时不愿意分享。找到新模型后,我将更新此存储库。如果你有任何潜在客户,请打开问题或拉取请求。
同时,我添加了对 text-davinci-003 等模型的支持,你可以将其用作直接替换。请记住,text-davinci-003不如
text-chat-davinci-002(通过RHLF训练并微调为对话AI),尽管结果仍然非常好。
请注意,使用
文本-davinci-003将花费你的积分($)。
Discord 用户 @pig#8932 找到了一个工作模型,.我已经更新了库以使用此模型。
text-chat-davinci-002
text-chat-davinci-002-20221122
通过OpenAI的API使用官方ChatGPT模型的ChatGPT实现。
这是使用官方 ChatGPT 原始模型的 ChatGPT 实现。这个模型名称在我检查官方 ChatGPT 网站发出的网络请求时被短暂泄露,我发现它适用于 OpenAI API。使用此模型目前不会花费任何积分。
text-chat-davinci-002
text-chat-davinci-002-20230126
据我所知,我是第一个发现这一点的人,并且该模型的使用已经在acheong08 / ChatGPT等库中实现。
这个库的以前版本使用transitive-bullshit/chatgpt-api仍然在archive/old-version分支
上可用。
模型本身没有任何对话支持,因此此库使用缓存来存储对话并将其作为上下文传递给模型。这使你可以以与官方网站几乎相同的方式与 ChatGPT 进行持续对话。
text-chat-davinci-002-20221122
ChatGPTClient
keyv-file
settings.example.js
npm i @waylaidwanderer/chatgpt-api
import ChatGPTClient from '@waylaidwanderer/chatgpt-api';
const clientOptions = {
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions: {
// The model is set to text-chat-davinci-002-20221122 by default, but you can override
// it and any other parameters here
model: 'text-chat-davinci-002-20221122',
},
// (Optional) Set custom instructions instead of "You are ChatGPT...".
// promptPrefix: 'You are Bob, a cowboy in Western times...',
// (Optional) Set a custom name for the user
// userLabel: 'User',
// (Optional) Set a custom name for ChatGPT
// chatGptLabel: 'ChatGPT',
// (Optional) Set to true to enable `console.debug()` logging
debug: false,
};
const cacheOptions = {
// Options for the Keyv cache, see https://www.npmjs.com/package/keyv
// This is used for storing conversations, and supports additional drivers (conversations are stored in memory by default)
// For example, to use a JSON file (`npm i keyv-file`) as a database:
// store: new KeyvFile({ filename: 'cache.json' }),
};
const chatGptClient = new ChatGPTClient('OPENAI_API_KEY', clientOptions, cacheOptions);
const response = await chatGptClient.sendMessage('Hello!');
console.log(response); // { response: 'Hi! How can I help you today?', conversationId: '...', messageId: '...' }
const response2 = await chatGptClient.sendMessage('Write a poem about cats.', { conversationId: response.conversationId, parentMessageId: response.messageId });
console.log(response2.response); // Cats are the best pets in the world.
const response3 = await chatGptClient.sendMessage('Now write it in French.', { conversationId: response2.conversationId, parentMessageId: response2.messageId });
console.log(response3.response); // Les chats sont les meilleurs animaux de compagnie du monde.
你可以使用以下方法安装软件包
npm i -g @waylaidwanderer/chatgpt-api
然后使用 运行它。
这采用可选参数,如果未设置,则在当前目录中查找,内容如下:
chatgpt-api
--settings=<path_to_settings.js>
settings.js
module.exports = {
// Your OpenAI API key
openaiApiKey: process.env.OPENAI_API_KEY || '',
chatGptClient: {
// (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions: {
// The model is set to text-chat-davinci-002-20221122 by default, but you can override
// it and any other parameters here
model: 'text-chat-davinci-002-20221122',
},
// (Optional) Set custom instructions instead of "You are ChatGPT...".
// promptPrefix: 'You are Bob, a cowboy in Western times...',
// (Optional) Set a custom name for the user
// userLabel: 'User',
// (Optional) Set a custom name for ChatGPT
// chatGptLabel: 'ChatGPT',
// (Optional) Set to true to enable `console.debug()` logging
debug: false,
},
// Options for the Keyv cache, see https://www.npmjs.com/package/keyv
// This is used for storing conversations, and supports additional drivers (conversations are stored in memory by default)
cacheOptions: {},
// Options for the API server
apiOptions: {
port: process.env.API_PORT || 3000,
host: process.env.API_HOST || 'localhost',
// (Optional) Set to true to enable `console.debug()` logging
debug: false,
},
// If set, ChatGPTClient will use `keyv-file` to store conversations to this JSON file instead of in memory.
// However, `cacheOptions.store` will override this if set
storageFilePath: process.env.STORAGE_FILE_PATH || './cache.json',
};
或者,你可以直接安装并运行包。
git clone https://github.com/waylaidwanderer/node-chatgpt-api
npm install
settings.example.js
settings.js
npm start
npm run server
docker-compose up
要与 ChatGPT 开始对话,请使用以下格式的 JSON 正文向服务器的终端节点发送 POST 请求:
/conversation
{
"message": "Hello, how are you today?",
"conversationId": "your-conversation-id (optional)",
"parentMessageId": "your-parent-message-id (optional)"
}
服务器将返回一个包含 ChatGPT 响应的 JSON 对象:
{
"response": "I'm doing well, thank you! How are you?",
"conversationId": "your-conversation-id",
"messageId": "response-message-id"
}
如果请求不成功,服务器将返回一个 JSON 对象,其中包含错误消息和状态代码 503。
如果将消息发送到 ChatGPT 时出错:
{
"error": "There was an error communicating with ChatGPT."
}
使用与 API 服务器相同的说明安装包。
如果全局安装:
chatgpt-cli
如果在本地安装:
npm run cli
ChatGPT 的回复会自动复制到你的剪贴板,因此你可以将它们粘贴到其他应用程序中。
由于是 ChatGPT 的原始模型,我必须尽最大努力复制 ChatGPT 官方网站使用它的方式。经过广泛的测试和比较响应,我相信 ChatGPT 使用的模型有一些额外的微调。
这意味着我的实现或原始模型在某些方面的行为可能不完全相同:
text-chat-davinci-002-20221122
对话不与任何用户 ID 相关联,因此,如果这对你很重要,则应实现自己的用户 ID 系统。
ChatGPT 的模型参数(温度、频率损失等)是未知的,所以我设置了一些我认为合理的默认值。
对话仅限于大约最后 3000 个令牌,因此在较长的对话中可能会忘记较早的消息。
众所周知,作为微调的一部分,ChatGPT 有以下序言:
“你是ChatGPT,一个由OpenAI训练的大型语言模型。对于每个回答,你回答得尽可能简洁(例如,不要冗长)。尽可能简洁地回答非常重要,因此请记住这一点。如果要生成列表,请不要有太多项目。保持项目数简短。
知识截止时间:2021-09
当前日期:2023-01-31”
随着OpenAI更新ChatGPT,这个序言也可能改变。我的实现中的默认提示前缀尝试复制与当前 ChatGPT 模型类似的行为。
如果你想参与此项目,请创建一个拉取请求,详细说明你的更改。
该项目根据 MIT 许可证获得许可。