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

@@ -3,6 +3,7 @@ import { getErrText } from '@/utils/tools';
import { parseStreamChunk } from '@/utils/adapt';
import { NextApiResponse } from 'next';
import { sseResponse } from '../utils/tools';
import { SpecificInputEnum } from '@/constants/app';
interface Props {
res: NextApiResponse; // 用于流转发
@@ -13,7 +14,7 @@ export const moduleFetch = ({ url, data, res }: Props) =>
new Promise<Record<string, any>>(async (resolve, reject) => {
try {
const abortSignal = new AbortController();
const baseUrl = `http://localhost:3000/api`;
const baseUrl = `http://localhost:${process.env.PORT || 3000}/api`;
const requestUrl = url.startsWith('/') ? `${baseUrl}${url}` : url;
const response = await fetch(requestUrl, {
method: 'POST',
@@ -41,7 +42,9 @@ export const moduleFetch = ({ url, data, res }: Props) =>
const reader = response.body?.getReader();
let chatResponse: Record<string, any> = {};
let chatResponse: Record<string, any> = {
[SpecificInputEnum.answerText]: ''
};
const read = async () => {
try {
@@ -80,7 +83,8 @@ export const moduleFetch = ({ url, data, res }: Props) =>
if (answer) {
chatResponse = {
...chatResponse,
answer: chatResponse.answer ? chatResponse.answer + answer : answer
[SpecificInputEnum.answerText]:
chatResponse[SpecificInputEnum.answerText] + answer
};
}