This commit is contained in:
archer
2023-07-17 22:05:45 +08:00
parent 509ca92f0a
commit ecce182a20
16 changed files with 1395 additions and 1422 deletions

View File

@@ -3,7 +3,6 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { authUser } from '@/service/utils/auth';
import { connectToDatabase, App } from '@/service/mongo';
import { appTemplates } from '@/constants/app';
import { rawSearchKey } from '@/constants/chat';
const chatTemplate = ({
@@ -85,7 +84,7 @@ const chatTemplate = ({
},
{
key: 'temperature',
type: 'slider',
type: 'custom',
label: '温度',
value: temperature,
min: 0,
@@ -105,10 +104,10 @@ const chatTemplate = ({
},
{
key: 'maxToken',
type: 'slider',
type: 'custom',
label: '回复上限',
value: maxToken,
min: 0,
min: 100,
max: 16000,
step: 50,
markList: [
@@ -328,8 +327,8 @@ const kbTemplate = ({
}
],
position: {
x: 211.58250540918442,
y: 611.8700401034965
x: -196.84632684738483,
y: 797.3401378431948
},
moduleId: 'k9y3jm'
},
@@ -364,7 +363,7 @@ const kbTemplate = ({
},
{
key: 'temperature',
type: 'slider',
type: 'custom',
label: '温度',
value: temperature,
min: 0,
@@ -384,10 +383,10 @@ const kbTemplate = ({
},
{
key: 'maxToken',
type: 'slider',
type: 'custom',
label: '回复上限',
value: maxToken,
min: 0,
min: 100,
max: 16000,
step: 50,
markList: [
@@ -459,8 +458,8 @@ const kbTemplate = ({
}
],
position: {
x: 830.725790038998,
y: 201.0790739617387
x: 745.484449528062,
y: 259.9361900288137
},
moduleId: 'qbf8td'
},
@@ -482,7 +481,7 @@ const kbTemplate = ({
},
{
key: 'similarity',
type: 'slider',
type: 'custom',
label: '相似度',
value: searchSimilarity,
min: 0,
@@ -502,8 +501,9 @@ const kbTemplate = ({
},
{
key: 'limit',
type: 'slider',
type: 'custom',
label: '单次搜索上限',
description: '最多取 n 条记录作为本次问题引用',
value: searchLimit,
min: 1,
max: 20,
@@ -575,7 +575,7 @@ const kbTemplate = ({
},
moduleId: 'q9v14m'
},
searchEmptyText
...(searchEmptyText
? [
{
logo: '/imgs/module/reply.png',
@@ -600,13 +600,13 @@ const kbTemplate = ({
],
outputs: [],
position: {
x: 827.8570503787319,
y: -63.837994077710675
x: 673.6108151684664,
y: -84.13355134221933
},
moduleId: 'w8av9y'
}
]
: []
: [])
];
};
@@ -619,13 +619,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const apps = await App.find(
{
chat: { $ne: null },
modules: { $ne: null }
modules: { $exists: false }
// userId: '63f9a14228d2a688d8dc9e1b'
},
'_id chat'
).limit(2);
);
const result = await Promise.all(
await Promise.all(
apps.map(async (app) => {
if (!app.chat) return app;
const modules = (() => {
if (app.chat.relatedKbs.length === 0) {
return chatTemplate({
@@ -650,17 +652,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
})();
await App.findByIdAndUpdate(app.id, {
modules
});
return modules;
})
);
console.log(apps);
jsonRes(res, {
data: {
apps,
result
}
data: apps.length
});
} catch (error) {
jsonRes(res, {

View File

@@ -30,7 +30,7 @@ export type Props = {
export type Response = { [SpecificInputEnum.answerText]: string; totalTokens: number };
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
let { model, temperature = 0, stream } = req.body as Props;
let { model, stream } = req.body as Props;
try {
await authUser({ req, authRoot: true });
@@ -54,7 +54,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
} catch (err) {
if (stream) {
res.status(500);
sseErrRes(res, err);
res.end();
} else {

View File

@@ -9,6 +9,8 @@ import RenderOutput from './render/RenderOutput';
import { FlowOutputItemTypeEnum } from '@/constants/flow';
import MySelect from '@/components/Select';
import { chatModelList } from '@/store/static';
import MySlider from '@/components/Slider';
import { Box } from '@chakra-ui/react';
const NodeChat = ({
data: { moduleId, inputs, outputs, onChangeNode, ...props }
@@ -47,7 +49,7 @@ const NodeChat = ({
key: 'maxToken',
valueKey: 'markList',
value: [
{ label: '0', value: 0 },
{ label: '100', value: 100 },
{ label: `${model.contextMaxToken}`, value: model.contextMaxToken }
]
});
@@ -65,7 +67,35 @@ const NodeChat = ({
});
}}
/>
)
),
maxToken: (inputItem) => {
const model = inputs.find((item) => item.key === 'model')?.value;
const modelData = chatModelList.find((item) => item.model === model);
const maxToken = modelData ? modelData.contextMaxToken : 4000;
const markList = [
{ label: '100', value: 100 },
{ label: `${maxToken}`, value: maxToken }
];
return (
<Box pt={5} pb={4} px={2}>
<MySlider
markList={markList}
width={'100%'}
min={inputItem.min || 100}
max={maxToken}
step={inputItem.step || 1}
value={inputItem.value}
onChange={(e) => {
onChangeNode({
moduleId,
key: inputItem.key,
value: e
});
}}
/>
</Box>
);
}
}}
/>
</Container>

View File

@@ -84,6 +84,7 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
const { x, y, zoom } = useViewport();
const [nodes, setNodes, onNodesChange] = useNodesState<FlowModuleItemType>([]);
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const [loaded, setLoaded] = useState(false);
const {
isOpen: isOpenTemplate,
onOpen: onOpenTemplate,
@@ -255,6 +256,9 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
})
)
);
setLoaded(true);
onFixView();
},
[onDelConnect, setEdges, setNodes, onChangeNode, onDelNode]
);
@@ -377,14 +381,15 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
isOpenTemplate ? onCloseTemplate() : onOpenTemplate();
}}
/>
<ReactFlow
ref={reactFlowWrapper}
className={styles.panel}
fitView
nodes={nodes}
edges={edges}
minZoom={0.4}
maxZoom={1.5}
fitView
defaultEdgeOptions={edgeOptions}
connectionLineStyle={connectionLineStyle}
nodeTypes={nodeTypes}

View File

@@ -21,9 +21,8 @@ import { getErrText } from '@/utils/tools';
import { useToast } from '@/hooks/useToast';
import { postCreateApp } from '@/api/app';
import { useRouter } from 'next/router';
import { appTemplates } from '@/constants/app';
import { appTemplates } from '@/constants/flow/ModuleTemplate';
import Avatar from '@/components/Avatar';
import MyIcon from '@/components/Icon';
type FormType = {
avatar: string;

View File

@@ -30,7 +30,8 @@ const ChatHistorySlider = ({
activeHistoryId,
onChangeChat,
onDelHistory,
onSetHistoryTop
onSetHistoryTop,
onUpdateTitle
}: {
appId?: string;
appName: string;
@@ -40,6 +41,7 @@ const ChatHistorySlider = ({
onChangeChat: (historyId?: string) => void;
onDelHistory: (historyId: string) => void;
onSetHistoryTop?: (e: { historyId: string; top: boolean }) => void;
onUpdateTitle?: (e: { historyId: string; title: string }) => void;
}) => {
const theme = useTheme();
const router = useRouter();
@@ -159,6 +161,20 @@ const ChatHistorySlider = ({
{item.top ? '取消置顶' : '置顶'}
</MenuItem>
)}
{/* {onUpdateTitle && (
<MenuItem
onClick={(e) => {
e.stopPropagation();
onUpdateTitle({
historyId: item.id,
title: '是是是'
});
}}
>
<MyIcon mr={2} name={'customTitle'} w={'16px'}></MyIcon>
自定义标题
</MenuItem>
)} */}
<MenuItem
_hover={{ color: 'red.500' }}
onClick={(e) => {

View File

@@ -24,7 +24,7 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
},
{ icon: 'pdf', label: 'PDF导出', onClick: () => onExportChat({ type: 'pdf', history }) }
]);
return (
return history.length > 0 ? (
<Menu autoSelect={false} isLazy>
<MenuButton
_hover={{ bg: 'myWhite.600 ' }}
@@ -45,7 +45,7 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
))}
</MenuList>
</Menu>
);
) : null;
};
export default ToolMenu;

View File

@@ -260,6 +260,20 @@ const Chat = () => {
});
} catch (error) {}
}}
onUpdateTitle={async (e) => {
try {
await putChatHistory({
historyId: e.historyId,
customTitle: e.title
});
const historyItem = history.find((item) => item._id === e.historyId);
if (!historyItem) return;
updateHistory({
...historyItem,
title: e.title
});
} catch (error) {}
}}
/>
)}
{/* chat container */}