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 ( if (
selectedSearchType !== SearchType.AUTOMATIC && selectedSearchType !== SearchType.AUTOMATIC &&
searchResponse.suggestedSearchType !== selectedSearchType searchResponse.suggestedSearchType !== selectedSearchType

View File

@ -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;