Fix handling for QA when documents are split into multiple mini-chunks (#110)

This commit is contained in:
Chris Weaver 2023-06-21 22:46:04 -06:00 committed by GitHub
parent 5a04df7eb0
commit 785d289c68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -52,8 +52,6 @@ const getAssistantMessage = ({
);
}
console.log(searchResponse.suggestedSearchType);
console.log(selectedSearchType);
if (
selectedSearchType !== SearchType.AUTOMATIC &&
searchResponse.suggestedSearchType !== selectedSearchType

View File

@ -9,10 +9,10 @@ const processSingleChunk = (
chunk: string,
currPartialChunk: string | null
): [{ [key: string]: any } | null, string | null] => {
const completeChunk = chunk + (currPartialChunk || "");
const completeChunk = (currPartialChunk || "") + chunk;
try {
// every complete chunk should be valid JSON
const chunkJson = JSON.parse(chunk);
const chunkJson = JSON.parse(completeChunk);
return [chunkJson, null];
} catch (err) {
// if it's not valid JSON, then it's probably an incomplete chunk
@ -42,10 +42,12 @@ const processRawChunkString = (
);
if (processedChunk) {
parsedChunkSections.push(processedChunk);
currPartialChunk = null;
} else {
currPartialChunk = partialChunk;
}
});
return [parsedChunkSections, currPartialChunk];
};
@ -112,9 +114,7 @@ export const searchRequestStreamed = async ({
if (!completedChunks.length && !partialChunk) {
break;
}
if (partialChunk) {
previousPartialChunk = partialChunk;
}
previousPartialChunk = partialChunk;
completedChunks.forEach((chunk) => {
// TODO: clean up response / this logic
const answerChunk = chunk.answer_data;