|
|
@@ -97,16 +97,19 @@ export async function answerWithContext({ message, conversationId, userId, optio
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-export async function answerWithContextStream({ message, conversationId, userId, options, onChunk, signal }) {
|
|
|
+export async function answerWithContextStream({ message, conversationId, userId, options, onChunk, onSources, onStatus, signal }) {
|
|
|
const searchQuery = config.rag.queryRewrite ? await rewriteQuery(message) : message;
|
|
|
+ onStatus?.("buscando");
|
|
|
const [hits, history] = await Promise.all([
|
|
|
searchDocs({ query: searchQuery, topK: config.rag.topK }),
|
|
|
loadHistory(conversationId, userId)
|
|
|
]);
|
|
|
+ onStatus?.("encontrou", hits.length);
|
|
|
+ const sources = hitsToSources(hits);
|
|
|
+ onSources?.(sources);
|
|
|
const context = buildContextBlock(hits);
|
|
|
const messages = buildMessages(message, context, history);
|
|
|
- const sources = hitsToSources(hits);
|
|
|
-
|
|
|
+ onStatus?.("gerando");
|
|
|
const completion = await chatCompletionStream({ messages, onChunk, signal, options: buildDefaultOptions(options) });
|
|
|
|
|
|
return {
|