q-koa 11.0.5 → 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.
|
@@ -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
|
+
}
|