mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-29 09:44:47 +00:00
feat: http modules
This commit is contained in:
31
client/src/service/moduleDispatch/tools/httpRequest.ts
Normal file
31
client/src/service/moduleDispatch/tools/httpRequest.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { sseResponseEventEnum, TaskResponseKeyEnum } from '@/constants/chat';
|
||||
import { sseResponse } from '@/service/utils/tools';
|
||||
import { textAdaptGptResponse } from '@/utils/adapt';
|
||||
import type { NextApiResponse } from 'next';
|
||||
|
||||
export type AnswerProps = {
|
||||
res: NextApiResponse;
|
||||
text: string;
|
||||
stream: boolean;
|
||||
};
|
||||
export type AnswerResponse = {
|
||||
[TaskResponseKeyEnum.answerText]: string;
|
||||
};
|
||||
|
||||
export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
|
||||
const { res, text = '', stream } = props as AnswerProps;
|
||||
|
||||
if (stream) {
|
||||
sseResponse({
|
||||
res,
|
||||
event: sseResponseEventEnum.answer,
|
||||
data: textAdaptGptResponse({
|
||||
text: text.replace(/\\n/g, '\n')
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
[TaskResponseKeyEnum.answerText]: text
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user