From 8336de741f1b80c681b80bc6c0af31fbf02aef2b Mon Sep 17 00:00:00 2001 From: jianershisan <15832251721@163.com> Date: Sun, 10 Nov 2024 18:53:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/jwh.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/routes/jwh.js b/routes/jwh.js index b5982b1..2c97eda 100644 --- a/routes/jwh.js +++ b/routes/jwh.js @@ -1,36 +1,36 @@ const express = require('express'); const router = express.Router(); -let {myroomModel,maint_jdModel,maintModel} = require('../models/model') +let { myroomModel, maint_jdModel, maintModel } = require('../models/model') //获取租住信息 router.get('/getMyRoom', async (req, res) => { let myRooms = await myroomModel.find(); res.send({ - code:200, + code: 200, myRooms }) }) //设置默认信息 -router.post('/setDefault',async (req,res)=>{ - let {_id} = req.body; +router.post('/setDefault', async (req, res) => { + let { _id } = req.body; console.log(_id) - await myroomModel.updateMany({},{def_Status:0}); + await myroomModel.updateMany({}, { def_Status: 0 }); - await myroomModel.findByIdAndUpdate(_id,{def_Status:1}); + await myroomModel.findByIdAndUpdate(_id, { def_Status: 1 }); res.send({ - code:200, - msg:'设置成功' + code: 200, + msg: '设置成功' }) }) //添加住户信息 -router.post('/addMyRoom',async (req,res)=>{ - let {isObj} = req.body; +router.post('/addMyRoom', async (req, res) => { + let { isObj } = req.body; console.log(isObj) await myroomModel.create(isObj); res.send({ - code:200, - msg:'添加成功' + code: 200, + msg: '添加成功' }) }) @@ -39,19 +39,19 @@ router.post('/addMyRoom',async (req,res)=>{ router.get('/getMaint', async (req, res) => { let maints = await maintModel.find(); res.send({ - code:200, + code: 200, maints }) }) //添加维修信息 -router.post('/addMaint',async (req,res)=>{ - let {MaintInfo} = req.body; +router.post('/addMaint', async (req, res) => { + let { MaintInfo } = req.body; console.log(MaintInfo) await maintModel.create(MaintInfo); res.send({ - code:200, - msg:'添加成功' + code: 200, + msg: '添加成功' }) }) module.exports = router; \ No newline at end of file -- Gitee From fafe97055d72907542ca9b2a69966e42e6ef8fb6 Mon Sep 17 00:00:00 2001 From: jianershisan <15832251721@163.com> Date: Sun, 10 Nov 2024 21:12:37 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ai=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node_modules/debug/package.json | 5 ++++- package.json | 3 +-- routes/jwh.js | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/node_modules/debug/package.json b/node_modules/debug/package.json index dc787ba..606ff22 100644 --- a/node_modules/debug/package.json +++ b/node_modules/debug/package.json @@ -45,5 +45,8 @@ "debug/index.js": "browser.js", "debug/debug.js": "debug.js" } - } + }, + "__npminstall_done": true, + "_from": "debug@2.6.9", + "_resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz" } diff --git a/package.json b/package.json index 5e6072a..cb62402 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ }, "dependencies": { "@alicloud/sms-sdk": "^1.1.6", + "@baiducloud/qianfan": "^0.2.0", "cookie-parser": "~1.4.4", "cors": "^2.8.5", "debug": "~2.6.9", @@ -14,8 +15,6 @@ "http-errors": "~1.6.3", "jade": "~1.11.0", "jsonwebtoken": "^9.0.2", - "morgan": "~1.9.1", - "mount-routes": "^1.0.8", "mongoose": "^8.7.3", "morgan": "~1.9.1", "mount-routes": "^1.0.8", diff --git a/routes/jwh.js b/routes/jwh.js index 2c97eda..9f28873 100644 --- a/routes/jwh.js +++ b/routes/jwh.js @@ -54,4 +54,27 @@ router.post('/addMaint', async (req, res) => { msg: '添加成功' }) }) + +const {ChatCompletion, setEnvVariable} = require("@baiducloud/qianfan"); + +// 设置百度云千帆的 API Key 和 Secret Key +setEnvVariable('QIANFAN_AK', '9lFqOXYm08vIooie9OpaiUIO'); +setEnvVariable('QIANFAN_SK', 'ZW4BlEcjgHhTZDOxXtmsbiNVzB5irdxV'); + +const client = new ChatCompletion({Endpoint: 'completions_pro'}); + +// 处理聊天请求的路由 +router.post('/chat', async (req, res) => { + try { + const { messages } = req.body; + const resp = await client.chat({ + messages + }); + res.json({ result: resp.result }); + } catch (error) { + console.error('Error in chat:', error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}); + module.exports = router; \ No newline at end of file -- Gitee From 1e97d5f40b1a768de28a3ab199cdff6bf7eeaa1b Mon Sep 17 00:00:00 2001 From: jianershisan <15832251721@163.com> Date: Sun, 10 Nov 2024 21:17:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0ai=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app.js b/app.js index 2467e39..3c44dba 100644 --- a/app.js +++ b/app.js @@ -20,12 +20,8 @@ app.use(express.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, "public"))); -<<<<<<< HEAD mount(app, path.join(__dirname, '/routes'), true); // app.use('/api', require('./routes/lx')); -======= -mount(app, path.join(__dirname, "/routes"), true); ->>>>>>> 2bcad5652efdaeb163929fe15e3ce00c8558d383 // mount(app, path.join(__dirname, '/'), true); // catch 404 and forward to error handler -- Gitee