关于chatgpt:不会写代码也能部署一个独立ChatGPT

9次阅读

共计 4641 个字符,预计需要花费 12 分钟才能阅读完成。

本教程应用 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:\>node
Welcome 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.git
Cloning 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 i
npm 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 5s

38 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 8.5.2 -> 9.4.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.4.2
npm 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

正文完
 0