ChatGPT 快速部署体验版本
前端

开发接口
使用的 Eggjs 进行开发
async chatgpt() { const { text, model, conversationId, parentMessageId } = this.ctx.request.body; const { ctx, app } = this; const { user } = ctx; const { ChatGPTClient } = await import('@waylaidwanderer/chatgpt-api'); const clientOptions = { // (Optional) Support for a reverse proxy for the completions endpoint (private API server). // Warning: This will expose your `openaiApiKey` to a third-party. Consider the risks before using this. // reverseProxyUrl: 'https://chatgpt.hato.ai/completions', // (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: model || 'text-davinci-002', // text-davinci-003(生成更复杂和多样化的完成) text-curie-001(可能不太准确或) }, // (Optional) Set custom instructions instead of "You are ChatGPT...". promptPrefix: '你好,我是智能助手', // (Optional) Set a custom name for the user // userLabel: 'User', // (Optional) Set a custom name for ChatGPT chatGptLabel: '智能助手', // (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: process.env.STORAGE_FILE_PATH || './cache.json', }; const chatGptClient = new ChatGPTClient( process.env.OPENAI_API_KEY, clientOptions, cacheOptions, ); const res = await chatGptClient.sendMessage(text, { conversationId, parentMessageId, // onProgress: (token) => console.log(token), }); console.log('A:', text, 'Q:', res.response); this.success({ data: { text: res.response, parentMessageId: res.messageId, conversationId: res.conversationId, }, }); }
下面的是参考的资料:
Nodejs 能力
官方对node 的支持
chatgpt-api:
使用方式
node >=18,或者 安装 fetch polyfill, 例如:isomorphic-fetch
npm install chatgpt import { ChatGPTAPI } from 'chatgpt' const api = new ChatGPTAPI({ process.env.OPENAI_API_KEY }) const arg = process.argv.splice(2)[0] console.log('输入的内容是:',arg); const res = await api.sendMessage(arg) console.log('ChatGPT 的答案是:',res.text)
node-chatgpt-api
1、安装
Follow the same setup instructions for the API server, creating settings.js
1 2 3 4 5 6 7 | npm i @waylaidwanderer/chatgpt-api // 全局安装执行 chatgpt-api // 本地安装执行 npm run cli |
添加 settings.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | export default { // Your OpenAI API key (for `ChatGPTClient`) 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-davinci-003' , }, // (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). // Does not apply when using `BingAIClient`. cacheOptions: {}, // Options for the Bing client bingAiClient: { // The "_U" cookie value from bing.com userToken: '' , // (Optional) Set to true to enable `console.debug()` logging debug: false , }, // 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 , // (Optional) Set to "bing" to use `BingAIClient` instead of `ChatGPTClient`. // clientToUse: 'bing', }, // 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' , }; |
如果觉得文章不错,可以给小编发个红包给予鼓励.
你要觉得这篇文章比较好,记得点推荐!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
2020-02-19 /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found的解决办法
2019-02-19 面试题集锦(一)
2018-02-19 Vue之九数据劫持实现MVVM的数据双向绑定
2018-02-19 Object的方法