mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-12 09:00:53 +02:00
Fix handling for QA when documents are split into multiple mini-chunks (#110)
This commit is contained in:
parent
5a04df7eb0
commit
785d289c68
@ -52,8 +52,6 @@ const getAssistantMessage = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(searchResponse.suggestedSearchType);
|
|
||||||
console.log(selectedSearchType);
|
|
||||||
if (
|
if (
|
||||||
selectedSearchType !== SearchType.AUTOMATIC &&
|
selectedSearchType !== SearchType.AUTOMATIC &&
|
||||||
searchResponse.suggestedSearchType !== selectedSearchType
|
searchResponse.suggestedSearchType !== selectedSearchType
|
||||||
|
@ -9,10 +9,10 @@ const processSingleChunk = (
|
|||||||
chunk: string,
|
chunk: string,
|
||||||
currPartialChunk: string | null
|
currPartialChunk: string | null
|
||||||
): [{ [key: string]: any } | null, string | null] => {
|
): [{ [key: string]: any } | null, string | null] => {
|
||||||
const completeChunk = chunk + (currPartialChunk || "");
|
const completeChunk = (currPartialChunk || "") + chunk;
|
||||||
try {
|
try {
|
||||||
// every complete chunk should be valid JSON
|
// every complete chunk should be valid JSON
|
||||||
const chunkJson = JSON.parse(chunk);
|
const chunkJson = JSON.parse(completeChunk);
|
||||||
return [chunkJson, null];
|
return [chunkJson, null];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// if it's not valid JSON, then it's probably an incomplete chunk
|
// if it's not valid JSON, then it's probably an incomplete chunk
|
||||||
@ -42,10 +42,12 @@ const processRawChunkString = (
|
|||||||
);
|
);
|
||||||
if (processedChunk) {
|
if (processedChunk) {
|
||||||
parsedChunkSections.push(processedChunk);
|
parsedChunkSections.push(processedChunk);
|
||||||
|
currPartialChunk = null;
|
||||||
} else {
|
} else {
|
||||||
currPartialChunk = partialChunk;
|
currPartialChunk = partialChunk;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return [parsedChunkSections, currPartialChunk];
|
return [parsedChunkSections, currPartialChunk];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,9 +114,7 @@ export const searchRequestStreamed = async ({
|
|||||||
if (!completedChunks.length && !partialChunk) {
|
if (!completedChunks.length && !partialChunk) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (partialChunk) {
|
previousPartialChunk = partialChunk;
|
||||||
previousPartialChunk = partialChunk;
|
|
||||||
}
|
|
||||||
completedChunks.forEach((chunk) => {
|
completedChunks.forEach((chunk) => {
|
||||||
// TODO: clean up response / this logic
|
// TODO: clean up response / this logic
|
||||||
const answerChunk = chunk.answer_data;
|
const answerChunk = chunk.answer_data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user