Skip to content

Commit

Permalink
Merge pull request #33 from AirWalk-Digital/bugfix-when-no-relevant-c…
Browse files Browse the repository at this point in the history
…ontent

Fixed a bug when no relevant content found
  • Loading branch information
RemusYu committed Apr 8, 2024
2 parents eb85418 + 7333074 commit 32898be
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions app/api/chat/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,31 +255,32 @@ export async function POST(req) {
async start(controller) {
try {
let jsonList = []; // Initialize an empty list to collect JSON objects

if (updatedDocs.length > 0) {
// Loop through the stream and push chunks to the client
for await (const chunk of stream) {
if (updatedDocs.length > 0) {
// Wrap each chunk in a JSON object before sending it
for await (const chunk of stream) {

// Wrap each chunk in a JSON object before sending it
const jsonChunk = JSON.stringify({
type: 'MessageStream',
content: chunk,
messageId: messageId,
role: 'bot'
});
// jsonList.push(jsonChunk); // Add the JSON object to the list
controller.enqueue(jsonChunk + ','); // Enqueue each JSON object as soon as it's ready
}
} else {
// Wrap each response in a JSON object before sending it
const jsonChunk = JSON.stringify({
type: 'MessageStream',
content: chunk,
content: 'Sorry, no relevant information found',
messageId: messageId,
role: 'bot'
});
// jsonList.push(jsonChunk); // Add the JSON object to the list
controller.enqueue(jsonChunk + ','); // Enqueue each JSON object as soon as it's ready

} else {
// Wrap each response in a JSON object before sending it
const jsonChunk = JSON.stringify({
type: 'MessageStream',
content: chunk,
content: 'Sorry, no relevant information found',
messageId: messageId,
role: 'bot'
});
}
}
});
controller.enqueue(jsonChunk + ','); // Enqueue each JSON object

}

// Send related content
for (const doc of updatedDocs) {
const jsonDoc = JSON.stringify(doc);
Expand Down

0 comments on commit 32898be

Please sign in to comment.