# chatserver_js **Repository Path**: neko_gitee/chatserver_js ## Basic Information - **Project Name**: chatserver_js - **Description**: ChatServer服务端的nodejs实现 - **Primary Language**: JavaScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-12-27 - **Last Updated**: 2023-12-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: chat ## README # chatserver_js #### 介绍 ChatServer服务端的nodejs实现 #### 软件架构 软件架构说明 #### 安装教程 服务器先安装Nodejs和npm 1. 将项目代码上传到服务器 ```bash # 安装依赖 npm install ``` 2. ```bash # 全局安装 pm2 npm install -g pm2 ``` 3. 在`package.json`同级目录新建一个名为`release.json`的`pm2`启动配置文件 ```json # 参考模板 { "apps": [ { "name": "chatserver_js", // 应用的名称 "script": "app.js", // 主应用文件的路径 "args": [], // 传递给应用的命令行参数 "instances": 1, // 应用的实例数量 "autorestart": true, // 应用崩溃时是否自动重启 "watch": true, // 是否监视文件变化并重启应用 "max_memory_restart": "800M", // 内存使用达到多少时自动重启 "env": { // 环境变量配置 "PORT": 7890, // 设置监听端口,默认端口:8888 "OPENAI_API_KEY": "GPT密钥", "TONGYI_API_KEY": "通义千问密钥", "GEMINI_API_KEY": "谷歌Gemini密钥", "XUNFEI_APP_ID": "讯飞星火APP_ID", "XUNFEI_API_KEY": "讯飞星火API_KEY", "XUNFEI_API_SECRET": "讯飞星火API_SECRET", "NODE_ENV": "development" }, "env_production": { // 生产环境下的环境变量配置 "NODE_ENV": "production" } } ] } ``` 4. 运行`package.json`中的启动命令 > 以下命令在`package.json`同级目录下执行 ```json { "name": "chatserver_js", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "stop": "pm2 start ./release.json", //停止命令 "start": "pm2 start ./release.json", //启动命令 "restart": "pm2 restart ./release.json", //重启命令 "status": "pm2 list ./release.json", //查看状态 "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "axios": "^1.6.2", "express": "^4.18.2", "winston": "^3.11.0" } } ``` ```bash # 示例:启动 npm run start # 示例:停止 npm run stop > chatserver_js@1.0.0 stop > pm2 stop ./release.json [PM2] [chatserver_js](0) ✓ ┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐ │ id │ name │ mode │ ↺ │ status │ cpu │ memory │ ├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤ │ 0 │ chatserver_js │ cluster │ 14 │ stopped │ 0% │ 0b │ └────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘ ``` 5. 其他命令 > 以下命令在`package.json`同级目录下执行 ```bash # 查看应用日志 # 日志路径:/root/.pm2/logs/ (以root身份运行) pm2 logs chatserver_js # chatserver_js是启动的应用名 # 删除应用 pm2 delete chatserver_js # chatserver_js是启动的应用名 # pm2 delete chatserver_js [PM2] Applying action deleteProcessId on app [chatserver_js](ids: [ 0 ]) [PM2] [chatserver_js](0) ✓ ┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐ │ id │ name │ mode │ ↺ │ status │ cpu │ memory │ └────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘ ``` #### 接口说明 `URL:http://ip:port/api/` 将`ip`和`port`替换为服务器的公网`ip`和端口号。 角色类型(`roleType`): - `roleType`为1:USER - `roleType`为2:ASSISTANT - `roleType`为3:SYSTEM 响应码(`responseCode`): - 200 Success - 400 Bad Request - 401 Unauthorized - 403 Forbidden - 404 Not Found - 500 Internal Server Error - 429 Too Many Requests 1. ChatGPT ```json // 请求地址:http://ip:port/api/chat/completions // 请求体 { content:"Hello" } // 响应结果 { roleType: 2, data: "Hello!How can I assist you today?" responseCode: 200 } ``` 2. Gemini ```json // 请求地址:http://ip:port/api/chat/gemini_pro // 请求体 { content:"Hello" } // 响应结果 { roleType: 2, data: "Hello!How can I assist you today?" responseCode: 200 } ``` 3. 通义千问 ```json // 请求地址:http://ip:port/api/tyqw/APIKey //get请求 // 响应结果 { roleType: 2, data: "通义千问API秘钥" responseCode: 200 } ``` 4. 讯飞星火 ```json // 请求地址:http://ip:port/api/xfxh/ApiArgs //get请求 // 响应结果 { roleType: 2, data: { //讯飞星火应用参数 XunFeiAppId: "", XunFeiApiKey: "", XunFeiApiSecret: "" } responseCode: 200 } ``` #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request