mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-02 12:48:30 +00:00
38 lines
959 B
TypeScript
38 lines
959 B
TypeScript
import { sseResponseEventEnum, TaskResponseKeyEnum } from '@/constants/chat';
|
|
import { sseResponse } from '@/service/utils/tools';
|
|
import { textAdaptGptResponse } from '@/utils/adapt';
|
|
import type { ModuleDispatchProps } from '@/types/core/chat/type';
|
|
export type AnswerProps = ModuleDispatchProps<{
|
|
text: string;
|
|
}>;
|
|
export type AnswerResponse = {
|
|
finish: boolean;
|
|
[TaskResponseKeyEnum.answerText]: string;
|
|
};
|
|
|
|
export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
|
|
const {
|
|
res,
|
|
detail,
|
|
stream,
|
|
inputs: { text = '' }
|
|
} = props as AnswerProps;
|
|
|
|
const formatText = typeof text === 'string' ? text : JSON.stringify(text, null, 2);
|
|
|
|
if (stream) {
|
|
sseResponse({
|
|
res,
|
|
event: detail ? sseResponseEventEnum.answer : undefined,
|
|
data: textAdaptGptResponse({
|
|
text: formatText
|
|
})
|
|
});
|
|
}
|
|
|
|
return {
|
|
finish: true,
|
|
[TaskResponseKeyEnum.answerText]: formatText
|
|
};
|
|
};
|