mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
feat: show RAG query results as citations
This commit is contained in:
committed by
Timothy J. Baek
parent
ba09fcd548
commit
0872bea790
@@ -4,6 +4,8 @@ import type { ParsedEvent } from 'eventsource-parser';
|
||||
type TextStreamUpdate = {
|
||||
done: boolean;
|
||||
value: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
citations?: any;
|
||||
};
|
||||
|
||||
// createOpenAITextStream takes a responseBody with a SSE response,
|
||||
@@ -45,6 +47,11 @@ async function* openAIStreamToIterator(
|
||||
const parsedData = JSON.parse(data);
|
||||
console.log(parsedData);
|
||||
|
||||
if (parsedData.citations) {
|
||||
yield { done: false, value: '', citations: parsedData.citations };
|
||||
continue;
|
||||
}
|
||||
|
||||
yield { done: false, value: parsedData.choices?.[0]?.delta?.content ?? '' };
|
||||
} catch (e) {
|
||||
console.error('Error extracting delta from SSE event:', e);
|
||||
@@ -62,6 +69,10 @@ async function* streamLargeDeltasAsRandomChunks(
|
||||
yield textStreamUpdate;
|
||||
return;
|
||||
}
|
||||
if (textStreamUpdate.citations) {
|
||||
yield textStreamUpdate;
|
||||
continue;
|
||||
}
|
||||
let content = textStreamUpdate.value;
|
||||
if (content.length < 5) {
|
||||
yield { done: false, value: content };
|
||||
|
||||
Reference in New Issue
Block a user