q-koa 13.0.3 → 13.0.5
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.
|
@@ -594,12 +594,11 @@ exports.sql = async (ctx) => {
|
|
|
594
594
|
|
|
595
595
|
exports.gpt = async (ctx) => {
|
|
596
596
|
const { app, appName } = getAppByCtx(ctx)
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
if (!content) return ctx.ERROR('
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
return ctx.SUCCESS(result)
|
|
597
|
+
const { content = '' } = ctx.request.body
|
|
598
|
+
|
|
599
|
+
if (!content) return ctx.ERROR('没有内容')
|
|
600
|
+
|
|
601
|
+
const res = await app.service.common.gpt({ app, content })
|
|
602
|
+
|
|
603
|
+
ctx.SUCCESS(res)
|
|
605
604
|
}
|
|
@@ -1,42 +1,36 @@
|
|
|
1
|
+
const { getConfig, ServiceError } = require('q-koa')
|
|
1
2
|
const axios = require('axios')
|
|
2
3
|
const XLSX = require('xlsx')
|
|
3
4
|
const moment = require('moment')
|
|
4
5
|
|
|
5
|
-
exports.gpt = async ({ content }) => {
|
|
6
|
-
|
|
7
|
-
let messages = [
|
|
8
|
-
{
|
|
9
|
-
content,
|
|
10
|
-
role: 'user',
|
|
11
|
-
},
|
|
12
|
-
]
|
|
6
|
+
exports.gpt = async ({ app, content }) => {
|
|
7
|
+
if (!content) throw new ServiceError('?content')
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...messages,
|
|
28
|
-
choices[0].message,
|
|
29
|
-
{
|
|
30
|
-
content: '继续',
|
|
31
|
-
role: 'user',
|
|
9
|
+
const appConfig = getConfig(app)
|
|
10
|
+
const { ai_key } = await appConfig.getObject('base')
|
|
11
|
+
const url =
|
|
12
|
+
'https://dashscope.aliyuncs.com/api/v1/apps/69c314f8f87e4a2080af950e5997bdc6/completion'
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
output: { text },
|
|
16
|
+
} = await axios
|
|
17
|
+
.post(
|
|
18
|
+
url,
|
|
19
|
+
{
|
|
20
|
+
input: {
|
|
21
|
+
prompt: content,
|
|
32
22
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: `Bearer ${ai_key}`,
|
|
27
|
+
'Content-Type': 'application/json',
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
.then((res) => res.data)
|
|
38
32
|
|
|
39
|
-
return
|
|
33
|
+
return text
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
exports.formatXLSX = ({ header, data, fileName: _fileName }) => {
|
|
@@ -38,11 +38,12 @@ module.exports = class Singleton {
|
|
|
38
38
|
throw new Error(result.msg)
|
|
39
39
|
}
|
|
40
40
|
} catch (e) {
|
|
41
|
+
const message = ` ${no} ${e.message || '物流服务暂不可用'}`
|
|
41
42
|
push({
|
|
42
43
|
appName: 'express',
|
|
43
|
-
message
|
|
44
|
+
message,
|
|
44
45
|
})
|
|
45
|
-
throw new Error(
|
|
46
|
+
throw new Error(message)
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|