本教程应用GPT-3模型接口模仿ChatGPT我的项目,尽管与真正的ChatGPT存在差别,然而演示了ChatGPT的工作原理。
(ChatGPT服务是基于GPT-3模型,通过大量的微调训练而来的,本教程临时不蕴含训练内容,之后咱们会讲如何进行二次训练)
部署的本地api接口应用了node-chatgpt-api这个库,库基于Node.js开发。我的项目地址:
https://github.com/waylaidwan...
要求Node.js环境 >= 16.0.0
如果没有装置Node.js,能够到这里https://nodejs.org/en/下载安装
装置实现后,关上cmd,输出node,能够看到装置实现,版本符合要求
D:\>nodeWelcome to Node.js v16.14.0.Type ".help" for more information.> .exit
另外还须要你有一个OpenAI的 API KEY,
能够在https://platform.openai.com/a...获取
而后同下载我的项目:
D:\dev2023>git clone https://github.com/waylaidwanderer/node-chatgpt-api.gitCloning into 'node-chatgpt-api'...remote: Enumerating objects: 576, done.remote: Counting objects: 100% (330/330), done.remote: Compressing objects: 100% (92/92), done.Receiving objects: 100% (576/576), 232.08 KiB | 805.00 KiB/s, done.246 eceiving objects: 97% (559/576)Resolving deltas: 100% (351/351), done.
进入我的项目文件夹:
D:\dev2023>cd node-chatgpt-api
装置我的项目依赖:
D:\dev2023\node-chatgpt-api>npm inpm WARN EBADENGINE Unsupported engine {npm WARN EBADENGINE package: '@waylaidwanderer/fetch-event-source@3.0.1',npm WARN EBADENGINE required: { node: '>=16.15' },npm WARN EBADENGINE current: { node: 'v16.14.0', npm: '8.5.2' }npm WARN EBADENGINE }added 163 packages, and audited 164 packages in 5s38 packages are looking for funding run `npm fund` for detailsfound 0 vulnerabilitiesnpm noticenpm notice New major version of npm available! 8.5.2 -> 9.4.2npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.4.2npm notice Run npm install -g npm@9.4.2 to update!
编辑配置文件:
将settings.example.js复制一份为settings.js
D:\dev2023\node-chatgpt-api>copy settings.example.js settings.js已复制 1 个文件。
而后用编辑器关上settings.js文件进行编辑
export default { // OpenAI API 密钥 openaiApiKey: process.env.OPENAI_API_KEY || '这里填写您的openai密钥', chatGptClient: { // (可选)在 https://platform.openai.com/docs/api-reference/completions 中形容的参数 modelOptions: { // 默认状况下模型设置为 text-chat-davinci-002-20221122,但您能够在此处笼罩它和其余任何参数 model: 'text-chat-davinci-002-20221122', }, // (可选)设置自定义阐明,而不是“您是 ChatGPT...” // promptPrefix: 'You are Bob, a cowboy in Western times...', // (可选)为用户设置自定义名称 // userLabel: 'User', // (可选)为 ChatGPT 设置自定义名称 // chatGptLabel: 'ChatGPT', // (可选)设置为 true 以启用 `console.debug()` 日志记录 debug: false, }, // Keyv 缓存的选项,详见 https://www.npmjs.com/package/keyv。 // 这用于存储对话,并反对其余驱动程序(默认状况下,对话存储在内存中) cacheOptions: {}, // API 服务器的选项 apiOptions: { port: process.env.API_PORT || 3000, host: process.env.API_HOST || 'localhost', // (可选)设置为 true 以启用 `console.debug()` 日志记录 debug: false, }, // 如果设置,ChatGPTClient 将应用 `keyv-file` 将对话存储到此 JSON 文件中,而不是存储在内存中。 // 然而,如果设置了 cacheOptions.store,它将笼罩此设置。
这里能够过期行很多配置,比方你能够给ChatGPT换一个名字,
比方:你叫小美...
残缺的ChatGPT自定义阐明:
"You are ChatGPT, a large language model trained by OpenAI. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short. Knowledge cutoff: 2021-09 Current date: 2023-01-31
“你是 ChatGPT,一个由 OpenAI 训练的大型语言模型。对于每个响应,你的答复尽可能简洁(例如,不要简短)。尽可能简洁地答复是十分重要的,所以请记住这一点。如果您正在生成一个列表,请不要有太多的我的项目。放弃我的项目的数量短。常识截止日期: 2021-09 以后日期: 2023-01-31”
默认只须要填好密钥就能够进行应用了,
然而模型定义这里可能须要换成官网的付费模型text-davinci-003。
留神,此处的model默认填的 text-chat-davinci-002-20221122 这是一个泄露模型,应用不计费然而常常无奈连贯,所以如果你想换成失常的,能够填写 text-davinci-003,这个是计费的模型,应用会扣除帐户余额,每个帐户默认赠送18美元,用完之后须要绑定国外信用卡能力持续生产。
应用我的项目:
输出npm run cli启动对话
D:\dev2023\node-chatgpt-api>npm run cli> @waylaidwanderer/chatgpt-api@1.10.5 cli> node bin/cli.js ╔═══════════════╗ ║ ChatGPT CLI ║ ╚═══════════════╝Type "!" to access the command menu.? Write a message: !❯ !editor - Open the editor (for multi-line messages) !resume - Resume last conversation !new - Start new conversation !copy - Copy conversation to clipboard !delete-all - Delete all conversations !exit - Exit ChatGPT CLI
输出!符号能够看到内置了几种命令
!
editor - Open the editor (for multi-line messages) - 关上编辑器(实用于多行音讯)!resume - Resume last conversation - 复原上一次对话!new - Start new conversation - 开始新对话!copy - Copy conversation to clipboard - 将对话复制到剪贴板!delete-all - Delete all conversations - 删除所有对话!exit - Exit ChatGPT CLI - 退出ChatGPT CLI
咱们能够尝试一下聊天:
Type "!" to access the command menu.? Write a message: 你好 ┌ ChatGPT ───────────────────┐ │ 你好!我能为你做些什么?│ └────────────────────────────┘
如果您相熟Node.js开发,您能够将此我的项目嵌入到您的我的项目中进行开发。当然,它也能够作为一个纯正的API接口来调用,以实现您本人的用户管理系统,治理不同用户的上下文,以及将来将要分享的自定义数据集模型训练以及训练后的应用。
// 启动一个node.js服务器npm start 或者 npm run server // 启动一个docker服务器docker-compose up
应用办法
发送音讯:
{ "message": "Hello, how are you today?", "conversationId": "your-conversation-id (optional)", "parentMessageId": "your-parent-message-id (optional)"}
返回音讯:
// HTTP/1.1 200 OK{ "response": "I'm doing well, thank you! How are you?", "conversationId": "your-conversation-id", "messageId": "response-message-id"}
ChatGPT正在迅速走红,寰球都在推广和关注这个我的项目,许多人也正在尝试从中变现获利。然而,他们所采纳的办法往往都过于简略和低门槛,如“写作文”、“写求职信”等。为了实现更高水平的商业价值,咱们心愿尝试更简单,更深度定制的办法。例如,咱们能够通过收集数据库并进行二次训练,比方训练一个适宜公司理论状况的客户服务的机器人。
因而,咱们将在当前逐步分享咱们的钻研步骤和操作方法,以帮忙那些心愿深刻理解GPT模型训练的敌人。这样,他们就能够以更低的技术门槛实现更高级的商业价值。
我的公众号:@大鹏学开发
我的微信号:aaronpeng2046 加我微信拉你进交换群
此内容由猪猪代管经营,业务邮箱:782564273@qq.com