Commit dc1599ba by archer

name

parent 53a4d9db
...@@ -4,7 +4,7 @@ import type { InitChatResponse, InitShareChatResponse } from './response/chat'; ...@@ -4,7 +4,7 @@ import type { InitChatResponse, InitShareChatResponse } from './response/chat';
import { RequestPaging } from '../types/index'; import { RequestPaging } from '../types/index';
import type { ShareChatSchema } from '@/types/mongoSchema'; import type { ShareChatSchema } from '@/types/mongoSchema';
import type { ShareChatEditType } from '@/types/app'; import type { ShareChatEditType } from '@/types/app';
import type { QuoteItemType } from '@/pages/api/openapi/modules/kb/search'; import type { QuoteItemType } from '@/pages/api/app/modules/kb/search';
import type { Props as UpdateHistoryProps } from '@/pages/api/chat/history/updateChatHistory'; import type { Props as UpdateHistoryProps } from '@/pages/api/chat/history/updateChatHistory';
/** /**
......
import { sseResponseEventEnum } from '@/constants/chat'; import { sseResponseEventEnum } from '@/constants/chat';
import { getErrText } from '@/utils/tools'; import { getErrText } from '@/utils/tools';
import { parseStreamChunk } from '@/utils/adapt'; import { parseStreamChunk } from '@/utils/adapt';
import { QuoteItemType } from '@/pages/api/openapi/modules/kb/search'; import { QuoteItemType } from '@/pages/api/app/modules/kb/search';
import { rawSearchKey } from '@/constants/chat'; import { rawSearchKey } from '@/constants/chat';
interface StreamFetchProps { interface StreamFetchProps {
......
...@@ -17,7 +17,7 @@ import { useQuery } from '@tanstack/react-query'; ...@@ -17,7 +17,7 @@ import { useQuery } from '@tanstack/react-query';
import { getHistoryQuote, updateHistoryQuote } from '@/api/chat'; import { getHistoryQuote, updateHistoryQuote } from '@/api/chat';
import { useToast } from '@/hooks/useToast'; import { useToast } from '@/hooks/useToast';
import { getErrText } from '@/utils/tools'; import { getErrText } from '@/utils/tools';
import { QuoteItemType } from '@/pages/api/openapi/modules/kb/search'; import { QuoteItemType } from '@/pages/api/app/modules/kb/search';
const QuoteModal = ({ const QuoteModal = ({
historyId, historyId,
......
...@@ -34,7 +34,7 @@ import dynamic from 'next/dynamic'; ...@@ -34,7 +34,7 @@ import dynamic from 'next/dynamic';
const QuoteModal = dynamic(() => import('./QuoteModal')); const QuoteModal = dynamic(() => import('./QuoteModal'));
import styles from './index.module.scss'; import styles from './index.module.scss';
import { QuoteItemType } from '@/pages/api/openapi/modules/kb/search'; import { QuoteItemType } from '@/pages/api/app/modules/kb/search';
const textareaMinH = '22px'; const textareaMinH = '22px';
export type StartChatFnProps = { export type StartChatFnProps = {
......
...@@ -38,7 +38,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -38,7 +38,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'questionInput', flowType: 'questionInput',
url: '/openapi/modules/init/userChatInput', url: '/app/modules/init/userChatInput',
inputs: [ inputs: [
{ {
key: 'userChatInput', key: 'userChatInput',
...@@ -72,7 +72,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -72,7 +72,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: 'AI 大模型对话', intro: 'AI 大模型对话',
flowType: 'chatNode', flowType: 'chatNode',
type: 'http', type: 'http',
url: '/openapi/modules/chat/gpt', url: '/app/modules/chat/gpt',
inputs: [ inputs: [
{ {
key: 'model', key: 'model',
...@@ -203,7 +203,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -203,7 +203,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'historyNode', flowType: 'historyNode',
url: '/openapi/modules/init/history', url: '/app/modules/init/history',
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
...@@ -254,7 +254,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -254,7 +254,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'questionInput', flowType: 'questionInput',
url: '/openapi/modules/init/userChatInput', url: '/app/modules/init/userChatInput',
inputs: [ inputs: [
{ {
key: 'userChatInput', key: 'userChatInput',
...@@ -292,7 +292,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -292,7 +292,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'historyNode', flowType: 'historyNode',
url: '/openapi/modules/init/history', url: '/app/modules/init/history',
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
...@@ -335,7 +335,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -335,7 +335,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: 'AI 大模型对话', intro: 'AI 大模型对话',
flowType: 'chatNode', flowType: 'chatNode',
type: 'http', type: 'http',
url: '/openapi/modules/chat/gpt', url: '/app/modules/chat/gpt',
inputs: [ inputs: [
{ {
key: 'model', key: 'model',
...@@ -466,7 +466,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -466,7 +466,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '去知识库中搜索对应的答案。可作为 AI 对话引用参考。', intro: '去知识库中搜索对应的答案。可作为 AI 对话引用参考。',
flowType: 'kbSearchNode', flowType: 'kbSearchNode',
type: 'http', type: 'http',
url: '/openapi/modules/kb/search', url: '/app/modules/kb/search',
inputs: [ inputs: [
{ {
key: 'kb_ids', key: 'kb_ids',
...@@ -609,7 +609,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -609,7 +609,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'questionInput', flowType: 'questionInput',
url: '/openapi/modules/init/userChatInput', url: '/app/modules/init/userChatInput',
inputs: [ inputs: [
{ {
key: 'userChatInput', key: 'userChatInput',
...@@ -643,7 +643,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -643,7 +643,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: 'OpenAI GPT 大模型对话。', intro: 'OpenAI GPT 大模型对话。',
flowType: 'chatNode', flowType: 'chatNode',
type: 'http', type: 'http',
url: '/openapi/modules/chat/gpt', url: '/app/modules/chat/gpt',
inputs: [ inputs: [
{ {
key: 'model', key: 'model',
...@@ -774,7 +774,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -774,7 +774,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'historyNode', flowType: 'historyNode',
url: '/openapi/modules/init/history', url: '/app/modules/init/history',
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
...@@ -876,7 +876,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -876,7 +876,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
{ {
id: 'CQ', id: 'CQ',
avatar: '/imgs/module/cq.png', avatar: '/imgs/module/cq.png',
name: '意图识别 + 知识库', name: '问题分类 + 知识库',
intro: '先对用户的问题进行分类,再根据不同类型问题,执行不同的操作', intro: '先对用户的问题进行分类,再根据不同类型问题,执行不同的操作',
modules: [ modules: [
{ {
...@@ -885,7 +885,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -885,7 +885,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'questionInput', flowType: 'questionInput',
url: '/openapi/modules/init/userChatInput', url: '/app/modules/init/userChatInput',
inputs: [ inputs: [
{ {
key: 'userChatInput', key: 'userChatInput',
...@@ -927,7 +927,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -927,7 +927,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'historyNode', flowType: 'historyNode',
url: '/openapi/modules/init/history', url: '/app/modules/init/history',
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
...@@ -970,7 +970,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -970,7 +970,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: 'OpenAI GPT 大模型对话。', intro: 'OpenAI GPT 大模型对话。',
flowType: 'chatNode', flowType: 'chatNode',
type: 'http', type: 'http',
url: '/openapi/modules/chat/gpt', url: '/app/modules/chat/gpt',
inputs: [ inputs: [
{ {
key: 'model', key: 'model',
...@@ -1101,7 +1101,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -1101,7 +1101,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '去知识库中搜索对应的答案。可作为 AI 对话引用参考。', intro: '去知识库中搜索对应的答案。可作为 AI 对话引用参考。',
flowType: 'kbSearchNode', flowType: 'kbSearchNode',
type: 'http', type: 'http',
url: '/openapi/modules/kb/search', url: '/app/modules/kb/search',
inputs: [ inputs: [
{ {
key: 'kb_ids', key: 'kb_ids',
...@@ -1208,7 +1208,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -1208,7 +1208,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: 'initInput', type: 'initInput',
flowType: 'historyNode', flowType: 'historyNode',
url: '/openapi/modules/init/history', url: '/app/modules/init/history',
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
...@@ -1303,11 +1303,11 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = ...@@ -1303,11 +1303,11 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] =
}, },
{ {
logo: '/imgs/module/cq.png', logo: '/imgs/module/cq.png',
name: '意图识别', name: '问题分类',
intro: '可以判断用户问题属于哪方面问题,从而执行不同的操作。', intro: '可以判断用户问题属于哪方面问题,从而执行不同的操作。',
type: 'http', type: 'http',
url: '/openapi/modules/agent/recognizeIntention', url: '/app/modules/agent/classifyQuestion',
flowType: 'recognizeIntention', flowType: 'classifyQuestion',
inputs: [ inputs: [
{ {
key: 'systemPrompt', key: 'systemPrompt',
......
...@@ -36,7 +36,7 @@ export const UserInputModule: AppModuleTemplateItemType = { ...@@ -36,7 +36,7 @@ export const UserInputModule: AppModuleTemplateItemType = {
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: AppModuleItemTypeEnum.initInput, type: AppModuleItemTypeEnum.initInput,
flowType: FlowModuleTypeEnum.questionInputNode, flowType: FlowModuleTypeEnum.questionInputNode,
url: '/openapi/modules/init/userChatInput', url: '/app/modules/init/userChatInput',
inputs: [ inputs: [
{ {
key: SystemInputEnum.userChatInput, key: SystemInputEnum.userChatInput,
...@@ -59,7 +59,7 @@ export const HistoryModule: AppModuleTemplateItemType = { ...@@ -59,7 +59,7 @@ export const HistoryModule: AppModuleTemplateItemType = {
intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。', intro: '用户输入的内容。该模块通常作为应用的入口,用户在发送消息后会首先执行该模块。',
type: AppModuleItemTypeEnum.initInput, type: AppModuleItemTypeEnum.initInput,
flowType: FlowModuleTypeEnum.historyNode, flowType: FlowModuleTypeEnum.historyNode,
url: '/openapi/modules/init/history', url: '/app/modules/init/history',
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
...@@ -92,7 +92,7 @@ export const ChatModule: AppModuleTemplateItemType = { ...@@ -92,7 +92,7 @@ export const ChatModule: AppModuleTemplateItemType = {
intro: 'AI 大模型对话', intro: 'AI 大模型对话',
flowType: FlowModuleTypeEnum.chatNode, flowType: FlowModuleTypeEnum.chatNode,
type: AppModuleItemTypeEnum.http, type: AppModuleItemTypeEnum.http,
url: '/openapi/modules/chat/gpt', url: '/app/modules/chat/gpt',
inputs: [ inputs: [
{ {
key: 'model', key: 'model',
...@@ -176,7 +176,7 @@ export const KBSearchModule: AppModuleTemplateItemType = { ...@@ -176,7 +176,7 @@ export const KBSearchModule: AppModuleTemplateItemType = {
intro: '去知识库中搜索对应的答案。可作为 AI 对话引用参考。', intro: '去知识库中搜索对应的答案。可作为 AI 对话引用参考。',
flowType: FlowModuleTypeEnum.kbSearchNode, flowType: FlowModuleTypeEnum.kbSearchNode,
type: AppModuleItemTypeEnum.http, type: AppModuleItemTypeEnum.http,
url: '/openapi/modules/kb/search', url: '/app/modules/kb/search',
inputs: [ inputs: [
{ {
key: 'kb_ids', key: 'kb_ids',
...@@ -283,13 +283,13 @@ export const TFSwitchModule: AppModuleTemplateItemType = { ...@@ -283,13 +283,13 @@ export const TFSwitchModule: AppModuleTemplateItemType = {
} }
] ]
}; };
export const RecognizeIntentionModule: AppModuleTemplateItemType = { export const ClassifyQuestionModule: AppModuleTemplateItemType = {
logo: '/imgs/module/cq.png', logo: '/imgs/module/cq.png',
name: '意图识别', name: '问题分类',
intro: '可以判断用户问题属于哪方面问题,从而执行不同的操作。', intro: '可以判断用户问题属于哪方面问题,从而执行不同的操作。',
type: AppModuleItemTypeEnum.http, type: AppModuleItemTypeEnum.http,
url: '/openapi/modules/agent/recognizeIntention', url: '/app/modules/agent/classifyQuestion',
flowType: FlowModuleTypeEnum.recognizeIntention, flowType: FlowModuleTypeEnum.classifyQuestion,
inputs: [ inputs: [
{ {
key: 'systemPrompt', key: 'systemPrompt',
...@@ -353,6 +353,6 @@ export const ModuleTemplates = [ ...@@ -353,6 +353,6 @@ export const ModuleTemplates = [
}, },
{ {
label: 'Agent', label: 'Agent',
list: [RecognizeIntentionModule] list: [ClassifyQuestionModule]
} }
]; ];
...@@ -26,7 +26,7 @@ export enum FlowModuleTypeEnum { ...@@ -26,7 +26,7 @@ export enum FlowModuleTypeEnum {
kbSearchNode = 'kbSearchNode', kbSearchNode = 'kbSearchNode',
tfSwitchNode = 'tfSwitchNode', tfSwitchNode = 'tfSwitchNode',
answerNode = 'answerNode', answerNode = 'answerNode',
recognizeIntention = 'recognizeIntention' classifyQuestion = 'classifyQuestion'
} }
export const edgeOptions = { export const edgeOptions = {
......
...@@ -6,15 +6,16 @@ import { ChatContextFilter } from '@/service/utils/chat/index'; ...@@ -6,15 +6,16 @@ import { ChatContextFilter } from '@/service/utils/chat/index';
import type { ChatItemType } from '@/types/chat'; import type { ChatItemType } from '@/types/chat';
import { ChatRoleEnum } from '@/constants/chat'; import { ChatRoleEnum } from '@/constants/chat';
import { getOpenAIApi, axiosConfig } from '@/service/ai/openai'; import { getOpenAIApi, axiosConfig } from '@/service/ai/openai';
import type { RecognizeIntentionAgentItemType } from '@/types/app'; import type { ClassifyQuestionAgentItemType } from '@/types/app';
import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill'; import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill';
import { getModel } from '@/service/utils/data'; import { getModel } from '@/service/utils/data';
import { authUser } from '@/service/utils/auth';
export type Props = { export type Props = {
systemPrompt?: string; systemPrompt?: string;
history?: ChatItemType[]; history?: ChatItemType[];
userChatInput: string; userChatInput: string;
agents: RecognizeIntentionAgentItemType[]; agents: ClassifyQuestionAgentItemType[];
billId?: string; billId?: string;
}; };
export type Response = { history: ChatItemType[] }; export type Response = { history: ChatItemType[] };
...@@ -24,6 +25,7 @@ const agentFunName = 'agent_user_question'; ...@@ -24,6 +25,7 @@ const agentFunName = 'agent_user_question';
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try { try {
await authUser({ req, authRoot: true });
let { userChatInput } = req.body as Props; let { userChatInput } = req.body as Props;
if (!userChatInput) { if (!userChatInput) {
...@@ -114,7 +116,7 @@ export async function classifyQuestion({ ...@@ -114,7 +116,7 @@ export async function classifyQuestion({
await pushTaskBillListItem({ await pushTaskBillListItem({
billId, billId,
moduleName: 'Recognize Intention', moduleName: 'Classify Question',
amount: countModelPrice({ model: agentModel, tokens: totalTokens }), amount: countModelPrice({ model: agentModel, tokens: totalTokens }),
model: getModel(agentModel)?.name, model: getModel(agentModel)?.name,
tokenLen: totalTokens tokenLen: totalTokens
......
...@@ -6,12 +6,13 @@ import { ChatContextFilter } from '@/service/utils/chat/index'; ...@@ -6,12 +6,13 @@ import { ChatContextFilter } from '@/service/utils/chat/index';
import type { ChatItemType } from '@/types/chat'; import type { ChatItemType } from '@/types/chat';
import { ChatRoleEnum } from '@/constants/chat'; import { ChatRoleEnum } from '@/constants/chat';
import { getOpenAIApi, axiosConfig } from '@/service/ai/openai'; import { getOpenAIApi, axiosConfig } from '@/service/ai/openai';
import type { RecognizeIntentionAgentItemType } from '@/types/app'; import type { ClassifyQuestionAgentItemType } from '@/types/app';
import { authUser } from '@/service/utils/auth';
export type Props = { export type Props = {
history?: ChatItemType[]; history?: ChatItemType[];
userChatInput: string; userChatInput: string;
agents: RecognizeIntentionAgentItemType[]; agents: ClassifyQuestionAgentItemType[];
description: string; description: string;
}; };
export type Response = { history: ChatItemType[] }; export type Response = { history: ChatItemType[] };
...@@ -21,6 +22,8 @@ const agentFunName = 'agent_extract_data'; ...@@ -21,6 +22,8 @@ const agentFunName = 'agent_extract_data';
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try { try {
await authUser({ req, authRoot: true });
const response = await extract(req.body); const response = await extract(req.body);
jsonRes(res, { jsonRes(res, {
......
...@@ -13,6 +13,7 @@ import { getOpenAIApi, axiosConfig } from '@/service/ai/openai'; ...@@ -13,6 +13,7 @@ import { getOpenAIApi, axiosConfig } from '@/service/ai/openai';
import { SpecificInputEnum } from '@/constants/app'; import { SpecificInputEnum } from '@/constants/app';
import { getChatModel } from '@/service/utils/data'; import { getChatModel } from '@/service/utils/data';
import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill'; import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill';
import { authUser } from '@/service/utils/auth';
export type Props = { export type Props = {
model: `${OpenAiChatEnum}`; model: `${OpenAiChatEnum}`;
...@@ -31,6 +32,8 @@ export type Response = { [SpecificInputEnum.answerText]: string; totalTokens: nu ...@@ -31,6 +32,8 @@ export type Response = { [SpecificInputEnum.answerText]: string; totalTokens: nu
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
let { model, temperature = 0, stream } = req.body as Props; let { model, temperature = 0, stream } = req.body as Props;
try { try {
await authUser({ req, authRoot: true });
const response = await chatCompletion({ const response = await chatCompletion({
...req.body, ...req.body,
res, res,
......
...@@ -5,9 +5,10 @@ import { withNextCors } from '@/service/utils/tools'; ...@@ -5,9 +5,10 @@ import { withNextCors } from '@/service/utils/tools';
import type { ChatItemType } from '@/types/chat'; import type { ChatItemType } from '@/types/chat';
import { ChatRoleEnum, rawSearchKey } from '@/constants/chat'; import { ChatRoleEnum, rawSearchKey } from '@/constants/chat';
import { modelToolMap } from '@/utils/plugin'; import { modelToolMap } from '@/utils/plugin';
import { getVector } from '../../plugin/vector'; import { getVector } from '@/pages/api/openapi/plugin/vector';
import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill'; import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill';
import { getModel } from '@/service/utils/data'; import { getModel } from '@/service/utils/data';
import { authUser } from '@/service/utils/auth';
export type QuoteItemType = { export type QuoteItemType = {
kb_id: string; kb_id: string;
...@@ -34,6 +35,8 @@ type Response = { ...@@ -34,6 +35,8 @@ type Response = {
export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) { export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try { try {
await authUser({ req, authRoot: true });
const { kb_ids = [], userChatInput } = req.body as Props; const { kb_ids = [], userChatInput } = req.body as Props;
if (!userChatInput || !Array.isArray(kb_ids)) { if (!userChatInput || !Array.isArray(kb_ids)) {
......
...@@ -6,7 +6,7 @@ import { FlowModuleItemType } from '@/types/flow'; ...@@ -6,7 +6,7 @@ import { FlowModuleItemType } from '@/types/flow';
import Divider from './modules/Divider'; import Divider from './modules/Divider';
import Container from './modules/Container'; import Container from './modules/Container';
import RenderInput from './render/RenderInput'; import RenderInput from './render/RenderInput';
import type { RecognizeIntentionAgentItemType } from '@/types/app'; import type { ClassifyQuestionAgentItemType } from '@/types/app';
import { Handle, Position } from 'reactflow'; import { Handle, Position } from 'reactflow';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 4); const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 4);
...@@ -30,7 +30,7 @@ const NodeRINode = ({ ...@@ -30,7 +30,7 @@ const NodeRINode = ({
value: agents = [] value: agents = []
}: { }: {
key: string; key: string;
value?: RecognizeIntentionAgentItemType[]; value?: ClassifyQuestionAgentItemType[];
}) => ( }) => (
<Box> <Box>
{agents.map((item, i) => ( {agents.map((item, i) => (
......
...@@ -70,7 +70,7 @@ const nodeTypes = { ...@@ -70,7 +70,7 @@ const nodeTypes = {
[FlowModuleTypeEnum.kbSearchNode]: NodeKbSearch, [FlowModuleTypeEnum.kbSearchNode]: NodeKbSearch,
[FlowModuleTypeEnum.tfSwitchNode]: NodeTFSwitch, [FlowModuleTypeEnum.tfSwitchNode]: NodeTFSwitch,
[FlowModuleTypeEnum.answerNode]: NodeAnswer, [FlowModuleTypeEnum.answerNode]: NodeAnswer,
[FlowModuleTypeEnum.recognizeIntention]: NodeRINode [FlowModuleTypeEnum.classifyQuestion]: NodeRINode
}; };
const edgeTypes = { const edgeTypes = {
buttonedge: ButtonEdge buttonedge: ButtonEdge
......
...@@ -18,8 +18,10 @@ export const moduleFetch = ({ url, data, res }: Props) => ...@@ -18,8 +18,10 @@ export const moduleFetch = ({ url, data, res }: Props) =>
const requestUrl = url.startsWith('/') ? `${baseUrl}${url}` : url; const requestUrl = url.startsWith('/') ? `${baseUrl}${url}` : url;
const response = await fetch(requestUrl, { const response = await fetch(requestUrl, {
method: 'POST', method: 'POST',
// @ts-ignore
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
rootkey: process.env.ROOT_KEY
}, },
body: JSON.stringify(data), body: JSON.stringify(data),
signal: abortSignal.signal signal: abortSignal.signal
......
...@@ -50,6 +50,48 @@ const AppSchema = new Schema({ ...@@ -50,6 +50,48 @@ const AppSchema = new Schema({
modules: { modules: {
type: Array, type: Array,
default: [] default: []
},
chat: {
relatedKbs: {
type: [Schema.Types.ObjectId],
ref: 'kb',
default: []
},
searchSimilarity: {
type: Number,
default: 0.8
},
searchLimit: {
type: Number,
default: 5
},
searchEmptyText: {
type: String,
default: ''
},
systemPrompt: {
type: String,
default: ''
},
limitPrompt: {
type: String,
default: ''
},
maxToken: {
type: Number,
default: 4000,
min: 100
},
temperature: {
type: Number,
min: 0,
max: 10,
default: 0
},
chatModel: {
// 聊天时使用的模型
type: String
}
} }
}); });
......
...@@ -3,7 +3,6 @@ import jwt from 'jsonwebtoken'; ...@@ -3,7 +3,6 @@ import jwt from 'jsonwebtoken';
import Cookie from 'cookie'; import Cookie from 'cookie';
import { App, OpenApi, User, ShareChat, KB } from '../mongo'; import { App, OpenApi, User, ShareChat, KB } from '../mongo';
import type { AppSchema } from '@/types/mongoSchema'; import type { AppSchema } from '@/types/mongoSchema';
import { defaultApp } from '@/constants/model';
import { formatPrice } from '@/utils/user'; import { formatPrice } from '@/utils/user';
import { ERROR_ENUM } from '../errorCode'; import { ERROR_ENUM } from '../errorCode';
......
...@@ -42,7 +42,7 @@ export type ShareChatEditType = { ...@@ -42,7 +42,7 @@ export type ShareChatEditType = {
/* agent */ /* agent */
/* question classify */ /* question classify */
export type RecognizeIntentionAgentItemType = { export type ClassifyQuestionAgentItemType = {
value: string; value: string;
key: string; key: string;
}; };
......
...@@ -44,6 +44,17 @@ export interface AppSchema { ...@@ -44,6 +44,17 @@ export interface AppSchema {
collection: number; collection: number;
}; };
modules: AppModuleItemType[]; modules: AppModuleItemType[];
chat: {
relatedKbs: string[];
searchSimilarity: number;
searchLimit: number;
searchEmptyText: string;
systemPrompt: string;
limitPrompt: string;
temperature: number;
maxToken: number;
chatModel: ChatModelType; // 聊天时用的模型,训练后就是训练的模型
};
} }
export interface CollectionSchema { export interface CollectionSchema {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment