You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
46 lines
1.4 KiB
'use strict';
|
|
const superagent = require('superagent');
|
|
|
|
module.exports.imageUnderstanding = async (ctx, next) => {
|
|
try {
|
|
const { externalXiaoshangAppKey } = ctx.app.fs.config.fastGpt;
|
|
const { imageUrl, text } = ctx.request.body;
|
|
if (!imageUrl) { throw '缺少请求参数' };
|
|
const res = await superagent
|
|
.post(`${ctx.app.fs.config.fastGpt.apiUrl}/api/v1/chat/completions`)
|
|
.send({
|
|
"stream": false,
|
|
"detail": false,
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content": [
|
|
{
|
|
"type": "image_url",
|
|
"image_url": {
|
|
"url": imageUrl
|
|
}
|
|
},
|
|
{
|
|
"type": "text",
|
|
"text": text || '请对图像进行理解'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
})
|
|
.set({
|
|
Authorization: `Bearer ${externalXiaoshangAppKey}`,
|
|
"Content-Type": "application/json",
|
|
})
|
|
const contentMd = res.body.choices[0].message.content;
|
|
ctx.body = contentMd;
|
|
ctx.status = 200;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error == 'string' ? error : '图像理解失败'
|
|
};
|
|
}
|
|
}
|