chatbox ui

This commit is contained in:
archer
2023-07-11 23:22:01 +08:00
parent eb768d9c04
commit b2e2f60e0d
46 changed files with 1123 additions and 2817 deletions

View File

@@ -6,14 +6,15 @@ import { sseResponseEventEnum } from '@/constants/chat';
import { sseResponse } from '@/service/utils/tools';
import { type ChatCompletionRequestMessage } from 'openai';
import { AppModuleItemType } from '@/types/app';
import { dispatchModules } from '../openapi/v1/chat/completions2';
import { dispatchModules } from '../openapi/v1/chat/completions';
import { gptMessage2ChatType } from '@/utils/adapt';
export type MessageItemType = ChatCompletionRequestMessage & { _id?: string };
export type Props = {
history: MessageItemType[];
prompt: string;
modules: AppModuleItemType[];
variable: Record<string, any>;
variables: Record<string, any>;
};
export type ChatResponseType = {
newChatId: string;
@@ -29,7 +30,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
res.end();
});
let { modules = [], history = [], prompt, variable = {} } = req.body as Props;
let { modules = [], history = [], prompt, variables = {} } = req.body as Props;
try {
if (!history || !modules || !prompt) {
@@ -48,9 +49,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { responseData } = await dispatchModules({
res,
modules: modules,
variable,
variables,
params: {
history,
history: gptMessage2ChatType(history),
userChatInput: prompt
},
stream: true