mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-03 05:19:51 +00:00
perf: sse response
This commit is contained in:
@@ -54,3 +54,24 @@ export const textAdaptGptResponse = ({
|
||||
choices: [{ delta: text === null ? {} : { content: text }, index: 0, finish_reason }]
|
||||
});
|
||||
};
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
export const parseStreamChunk = (value: BufferSource) => {
|
||||
const chunk = decoder.decode(value);
|
||||
const chunkLines = chunk.split('\n\n').filter((item) => item);
|
||||
const chunkResponse = chunkLines.map((item) => {
|
||||
const splitEvent = item.split('\n');
|
||||
if (splitEvent.length === 2) {
|
||||
return {
|
||||
event: splitEvent[0].replace('event: ', ''),
|
||||
data: splitEvent[1].replace('data: ', '')
|
||||
};
|
||||
}
|
||||
return {
|
||||
event: '',
|
||||
data: splitEvent[0].replace('data: ', '')
|
||||
};
|
||||
});
|
||||
|
||||
return chunkResponse;
|
||||
};
|
||||
|
Reference in New Issue
Block a user