q-koa 11.0.4 → 11.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/config.js
CHANGED
|
@@ -134,6 +134,9 @@ module.exports = {
|
|
|
134
134
|
cacheModel: [],
|
|
135
135
|
disabledFindAllList: [],
|
|
136
136
|
defaultRouter: (router) => (app) => {
|
|
137
|
+
if (app.controller.setting.html) {
|
|
138
|
+
router.get('/setting/html', app.controller.setting.html)
|
|
139
|
+
}
|
|
137
140
|
if (app.controller.cache) {
|
|
138
141
|
router.get('/cache/get', app.controller.cache.get)
|
|
139
142
|
router.get('/cache/clear', app.controller.cache.clear)
|
|
@@ -563,3 +563,15 @@ exports.sql = async (ctx) => {
|
|
|
563
563
|
|
|
564
564
|
ctx.SUCCESS(result)
|
|
565
565
|
}
|
|
566
|
+
|
|
567
|
+
exports.gpt = async (ctx) => {
|
|
568
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
569
|
+
const appConfig = getConfig(app)
|
|
570
|
+
const { content } = ctx.request.body
|
|
571
|
+
if (!content) return ctx.ERROR('?content')
|
|
572
|
+
if (!app.service.common) throw new Error(`common可能没有service.js`)
|
|
573
|
+
const result = await app.service.common.gpt({
|
|
574
|
+
content,
|
|
575
|
+
})
|
|
576
|
+
return ctx.SUCCESS(result)
|
|
577
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const axios = require('axios')
|
|
2
|
+
exports.gpt = async ({ content }) => {
|
|
3
|
+
let result = ''
|
|
4
|
+
let messages = [
|
|
5
|
+
{
|
|
6
|
+
content,
|
|
7
|
+
role: 'user',
|
|
8
|
+
},
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < 1000; i++) {
|
|
12
|
+
try {
|
|
13
|
+
const { choices } = await axios
|
|
14
|
+
.post('https://gpt.likangjian.cn:3001/gpt/chat', {
|
|
15
|
+
messages,
|
|
16
|
+
})
|
|
17
|
+
.then((res) => res.data)
|
|
18
|
+
result += choices[0].message.content
|
|
19
|
+
if (choices.finish_reason === 'stop') {
|
|
20
|
+
break
|
|
21
|
+
}
|
|
22
|
+
messages = [
|
|
23
|
+
...messages,
|
|
24
|
+
choices[0].message,
|
|
25
|
+
{
|
|
26
|
+
content: '还有呢',
|
|
27
|
+
role: 'user',
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new Error('ai开小差了')
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return result
|
|
36
|
+
}
|
|
@@ -128,3 +128,27 @@ exports.init = async (ctx) => {
|
|
|
128
128
|
|
|
129
129
|
ctx.SUCCESS(list)
|
|
130
130
|
}
|
|
131
|
+
|
|
132
|
+
exports.html = async (ctx) => {
|
|
133
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
134
|
+
const { code } = ctx.request.query
|
|
135
|
+
if (!code) {
|
|
136
|
+
ctx.body = `没有code`
|
|
137
|
+
}
|
|
138
|
+
const target = await app.model.setting.findOne({
|
|
139
|
+
where: {
|
|
140
|
+
code,
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
ctx.body = `<!DOCTYPE html>
|
|
144
|
+
<html lang="en">
|
|
145
|
+
<head>
|
|
146
|
+
<meta charset="UTF-8">
|
|
147
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
148
|
+
<title>${target.name}</title>
|
|
149
|
+
</head>
|
|
150
|
+
<body>
|
|
151
|
+
${target.value}
|
|
152
|
+
</body>
|
|
153
|
+
</html>`
|
|
154
|
+
}
|