不會(huì)寫代碼,也能部署一個(gè)獨(dú)立ChatGPT?

1.png

本教程使用GPT-3模型接口模擬ChatGPT項(xiàng)目,雖然與真正的ChatGPT存在差異,但是演示了ChatGPT的工作原理。

(ChatGPT服務(wù)是基于GPT-3模型,經(jīng)過大量的微調(diào)訓(xùn)練而來的,本教程暫時(shí)不包含訓(xùn)練內(nèi)容,之后我們會(huì)講如何進(jìn)行二次訓(xùn)練)

部署的本地api接口使用了node-chatgpt-api這個(gè)庫(kù),庫(kù)基于Node.js開發(fā)。項(xiàng)目地址:
https://github.com/waylaidwanderer/node-chatgpt-api

2.png

要求Node.js環(huán)境 >= 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

另外還需要你有一個(gè)OpenAI的 API KEY,
可以在https://platform.openai.com/account/api-keys獲取

3.png

然后同下載項(xiàng)目:

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.

進(jìn)入項(xiàng)目文件夾:

D:\dev2023>cd node-chatgpt-api

安裝項(xiàng)目依賴:

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復(fù)制一份為settings.js

D:\dev2023\node-chatgpt-api>copy settings.example.js settings.js
已復(fù)制         1 個(gè)文件。

然后用編輯器打開settings.js文件進(jìn)行編輯

export default {
    // OpenAI API 密鑰
    openaiApiKey: process.env.OPENAI_API_KEY || '這里填寫您的openai密鑰',
    chatGptClient: {
        // (可選)在 https://platform.openai.com/docs/api-reference/completions 中描述的參數(shù)
        modelOptions: {
            // 默認(rèn)情況下模型設(shè)置為 text-chat-davinci-002-20221122,但您可以在此處覆蓋它和其他任何參數(shù)
            model: 'text-chat-davinci-002-20221122',
        },
        // (可選)設(shè)置自定義說明,而不是“您是 ChatGPT...”
        // promptPrefix: 'You are Bob, a cowboy in Western times...',
        // (可選)為用戶設(shè)置自定義名稱
        // userLabel: 'User',
        // (可選)為 ChatGPT 設(shè)置自定義名稱
        // chatGptLabel: 'ChatGPT',
        // (可選)設(shè)置為 true 以啟用 `console.debug()` 日志記錄
        debug: false,
    },
    // Keyv 緩存的選項(xiàng),詳見 https://www.npmjs.com/package/keyv。
    // 這用于存儲(chǔ)對(duì)話,并支持其他驅(qū)動(dòng)程序(默認(rèn)情況下,對(duì)話存儲(chǔ)在內(nèi)存中)
    cacheOptions: {},
    // API 服務(wù)器的選項(xiàng)
    apiOptions: {
        port: process.env.API_PORT || 3000,
        host: process.env.API_HOST || 'localhost',
        // (可選)設(shè)置為 true 以啟用 `console.debug()` 日志記錄
        debug: false,
    },
    // 如果設(shè)置,ChatGPTClient 將使用 `keyv-file` 將對(duì)話存儲(chǔ)到此 JSON 文件中,而不是存儲(chǔ)在內(nèi)存中。
    // 但是,如果設(shè)置了 cacheOptions.store,它將覆蓋此設(shè)置。

這里可以過時(shí)行很多配置,比如你可以給ChatGPT換一個(gè)名字,
比如:你叫小美...
完整的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,一個(gè)由 OpenAI 訓(xùn)練的大型語言模型。對(duì)于每個(gè)響應(yīng),你的回答盡可能簡(jiǎn)潔(例如,不要冗長(zhǎng))。盡可能簡(jiǎn)潔地回答是非常重要的,所以請(qǐng)記住這一點(diǎn)。如果您正在生成一個(gè)列表,請(qǐng)不要有太多的項(xiàng)目。保持項(xiàng)目的數(shù)量短。知識(shí)截止日期: 2021-09 當(dāng)前日期: 2023-01-31”
默認(rèn)只需要填好密鑰就可以進(jìn)行使用了,
但是模型定義這里可能需要換成官方的付費(fèi)模型text-davinci-003。
注意,此處的model默認(rèn)填的 text-chat-davinci-002-20221122 這是一個(gè)泄露模型,使用不計(jì)費(fèi)但是經(jīng)常無法連接,所以如果你想換成正常的,可以填寫 text-davinci-003,這個(gè)是計(jì)費(fèi)的模型,使用會(huì)扣除帳戶余額,每個(gè)帳戶默認(rèn)贈(zèng)送18美元,用完之后需要綁定國(guó)外信用卡才能繼續(xù)消費(fèi)。
使用項(xiàng)目:
輸入npm run cli啟動(dòng)對(duì)話

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

輸入!符號(hào)可以看到內(nèi)置了幾種命令
!

editor - Open the editor (for multi-line messages) - 打開編輯器(適用于多行消息)
!resume - Resume last conversation - 恢復(fù)上一次對(duì)話
!new - Start new conversation  - 開始新對(duì)話
!copy - Copy conversation to clipboard - 將對(duì)話復(fù)制到剪貼板
!delete-all - Delete all conversations  - 刪除所有對(duì)話
!exit - Exit ChatGPT CLI - 退出ChatGPT CLI

我們可以嘗試一下聊天:

Type "!" to access the command menu.
? Write a message: 你好

   ┌ ChatGPT ───────────────────┐
   │  你好!我能為你做些什么?│
   └────────────────────────────┘

如果您熟悉Node.js開發(fā),您可以將此項(xiàng)目嵌入到您的項(xiàng)目中進(jìn)行開發(fā)。當(dāng)然,它也可以作為一個(gè)純粹的API接口來調(diào)用,以實(shí)現(xiàn)您自己的用戶管理系統(tǒng),管理不同用戶的上下文,以及未來將要分享的自定義數(shù)據(jù)集模型訓(xùn)練以及訓(xùn)練后的使用。

// 啟動(dòng)一個(gè)node.js服務(wù)器
npm start 或者 npm run server 
// 啟動(dòng)一個(gè)docker服務(wù)器
docker-compose up

使用方法
發(fā)送消息:

{
    "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正在迅速走紅,全球都在推廣和關(guān)注這個(gè)項(xiàng)目,許多人也正在嘗試從中變現(xiàn)獲利。然而,他們所采用的方法往往都過于簡(jiǎn)單和低門檻,如“寫作文”、“寫求職信”等。為了實(shí)現(xiàn)更高水平的商業(yè)價(jià)值,我們希望嘗試更復(fù)雜,更深度定制的方法。例如,我們可以通過收集數(shù)據(jù)庫(kù)并進(jìn)行二次訓(xùn)練,比如訓(xùn)練一個(gè)適合公司實(shí)際情況的客戶服務(wù)的機(jī)器人。
因此,我們將在以后逐漸分享我們的研究步驟和操作方法,以幫助那些希望深入了解GPT模型訓(xùn)練的朋友。這樣,他們就可以以更低的技術(shù)門檻實(shí)現(xiàn)更高級(jí)的商業(yè)價(jià)值。

我的公眾號(hào):@大鵬學(xué)開發(fā)

我的:aaronpeng2046 加我拉你進(jìn)交流群

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容