mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-15 23:55:36 +00:00
feat: admin set share
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { User, Model, Kb } from '../schema.js';
|
||||
import { Model, Kb } from '../schema.js';
|
||||
import { auth } from './system.js';
|
||||
|
||||
export const useAppRoute = (app) => {
|
||||
@@ -8,18 +8,19 @@ export const useAppRoute = (app) => {
|
||||
const start = parseInt(req.query._start) || 0;
|
||||
const end = parseInt(req.query._end) || 20;
|
||||
const order = req.query._order === 'DESC' ? -1 : 1;
|
||||
const sort = req.query._sort || '_id';
|
||||
const userId = req.query.userId || '';
|
||||
const sort = req.query._sort;
|
||||
const name = req.query.name || '';
|
||||
const id = req.query.id || '';
|
||||
|
||||
const where = {
|
||||
...(userId ? { userId: userId } : {}),
|
||||
name
|
||||
...(name && { name: { $regex: name, $options: 'i' } }),
|
||||
...(id && { _id: id })
|
||||
};
|
||||
|
||||
const modelsRaw = await Model.find()
|
||||
const modelsRaw = await Model.find(where)
|
||||
.skip(start)
|
||||
.limit(end - start)
|
||||
.sort({ [sort]: order });
|
||||
.sort({ [sort]: order, 'share.isShare': -1, 'share.collection': -1 });
|
||||
|
||||
const models = [];
|
||||
|
||||
@@ -37,15 +38,19 @@ export const useAppRoute = (app) => {
|
||||
id: model._id.toString(),
|
||||
userId: model.userId,
|
||||
name: model.name,
|
||||
model: model.chat?.chatModel,
|
||||
relatedKbs: kbNames, // 将relatedKbs的id转换为相应的Kb名称
|
||||
searchMode: model.chat?.searchMode,
|
||||
systemPrompt: model.chat?.systemPrompt || '',
|
||||
temperature: model.chat?.temperature
|
||||
'share.topNum': model.share?.topNum || 0,
|
||||
'share.isShare': model.share?.isShare || false,
|
||||
'share.intro': model.share?.intro,
|
||||
'share.collection': model.share?.collection || 0
|
||||
};
|
||||
|
||||
models.push(orderedModel);
|
||||
}
|
||||
const totalCount = await Model.countDocuments();
|
||||
const totalCount = await Model.countDocuments(where);
|
||||
res.header('Access-Control-Expose-Headers', 'X-Total-Count');
|
||||
res.header('X-Total-Count', totalCount);
|
||||
res.json(models);
|
||||
@@ -54,4 +59,28 @@ export const useAppRoute = (app) => {
|
||||
res.status(500).json({ error: 'Error fetching models', details: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// 修改 app 信息
|
||||
app.put('/models/:id', auth(), async (req, res) => {
|
||||
try {
|
||||
const _id = req.params.id;
|
||||
|
||||
let {
|
||||
share: { isShare, intro, topNum }
|
||||
} = req.body;
|
||||
|
||||
await Model.findByIdAndUpdate(_id, {
|
||||
$set: {
|
||||
'share.topNum': Number(topNum),
|
||||
'share.isShare': isShare === 'true',
|
||||
'share.intro': intro
|
||||
}
|
||||
});
|
||||
|
||||
res.json({});
|
||||
} catch (err) {
|
||||
console.log(`Error updating user: ${err}`);
|
||||
res.status(500).json({ error: 'Error updating user' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@@ -69,6 +69,7 @@ const modelSchema = new mongoose.Schema({
|
||||
chatModel: String
|
||||
},
|
||||
share: {
|
||||
topNum: Number,
|
||||
isShare: Boolean,
|
||||
isShareDetail: Boolean,
|
||||
intro: String,
|
||||
|
@@ -54,7 +54,25 @@ function App() {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
<Resource
|
||||
name="models"
|
||||
icon={<IconApps />}
|
||||
label="应用"
|
||||
list={
|
||||
<ListTable
|
||||
filter={[
|
||||
createTextField('id', {
|
||||
label: 'id'
|
||||
}),
|
||||
createTextField('name', {
|
||||
label: 'name'
|
||||
})
|
||||
]}
|
||||
fields={ModelFields}
|
||||
action={{ detail: true, edit: true }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Resource
|
||||
name="pays"
|
||||
label="支付记录"
|
||||
@@ -90,12 +108,7 @@ function App() {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Resource
|
||||
name="models"
|
||||
icon={<IconApps />}
|
||||
label="应用"
|
||||
list={<ListTable fields={ModelFields} action={{ detail: true }} />}
|
||||
/>
|
||||
|
||||
<Resource
|
||||
name="system"
|
||||
label="系统"
|
||||
|
@@ -26,17 +26,21 @@ export const kbFields = [
|
||||
|
||||
export const ModelFields = [
|
||||
createTextField('id', { label: 'ID' }),
|
||||
createTextField('userId', { label: '所属用户' }),
|
||||
createTextField('userId', { label: '所属用户', list: { hidden: true } }),
|
||||
createTextField('name', { label: '名字' }),
|
||||
createTextField('relatedKbs', { label: '引用的知识库' }),
|
||||
createTextField('searchMode', { label: '搜索模式' }),
|
||||
createTextField('model', { label: '模型' }),
|
||||
createTextField('share.collection', { label: '收藏数', list: { sort: true } }),
|
||||
createTextField('share.topNum', { label: '置顶等级', list: { sort: true } }),
|
||||
createTextField('share.isShare', { label: '是否分享(true,false)' }),
|
||||
createTextField('share.intro', { label: '介绍', list: { width: 400 } }),
|
||||
createTextField('relatedKbs', { label: '引用的知识库', list: { hidden: true } }),
|
||||
createTextField('systemPrompt', {
|
||||
label: '提示词',
|
||||
list: {
|
||||
width: 400
|
||||
width: 400,
|
||||
hidden: true
|
||||
}
|
||||
}),
|
||||
createTextField('temperature', { label: '温度' })
|
||||
})
|
||||
];
|
||||
|
||||
export const SystemFields = [
|
||||
|
@@ -77,7 +77,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
}
|
||||
},
|
||||
{
|
||||
$sort: { 'share.collection': -1 }
|
||||
$sort: { 'share.topNum': -1, 'share.collection': -1 }
|
||||
},
|
||||
{
|
||||
$skip: (pageNum - 1) * pageSize
|
||||
|
@@ -344,7 +344,7 @@ ${e.password ? `密码为: ${e.password}` : ''}`;
|
||||
{isOwner && (
|
||||
<>
|
||||
{/* model share setting */}
|
||||
<Card p={4}>
|
||||
{/* <Card p={4}>
|
||||
<Box fontWeight={'bold'}>分享设置</Box>
|
||||
<Box>
|
||||
<Flex mt={5} alignItems={'center'}>
|
||||
@@ -373,7 +373,7 @@ ${e.password ? `密码为: ${e.password}` : ''}`;
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
</Card>
|
||||
</Card> */}
|
||||
<Card p={4}>
|
||||
<Flex justifyContent={'space-between'}>
|
||||
<Box fontWeight={'bold'}>关联的知识库</Box>
|
||||
@@ -411,7 +411,7 @@ ${e.password ? `密码为: ${e.password}` : ''}`;
|
||||
</>
|
||||
)}
|
||||
{/* shareChat */}
|
||||
<Card p={4} gridColumnStart={1} gridColumnEnd={[2, 3]}>
|
||||
<Card p={4}>
|
||||
<Flex justifyContent={'space-between'}>
|
||||
<Box fontWeight={'bold'}>
|
||||
免登录聊天窗口
|
||||
|
@@ -61,6 +61,10 @@ const ModelSchema = new Schema({
|
||||
}
|
||||
},
|
||||
share: {
|
||||
topNum: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
isShare: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
|
Reference in New Issue
Block a user