Add citations to the log

This commit is contained in:
ferenci84 2025-03-06 14:05:14 +01:00
parent ceede791bd
commit 6bc0bfc5f1

View file

@ -763,6 +763,7 @@ export abstract class BaseLLM implements ILLM {
}
let completion = "";
let citations: null | string[] = null
try {
if (this.templateMessages) {
@ -790,6 +791,8 @@ export abstract class BaseLLM implements ILLM {
completion = renderChatMessage(msg);
} else {
// Stream true
console.log("Streaming");
const stream = this.openaiAdapter.chatCompletionStream(
{
...body,
@ -802,6 +805,9 @@ export abstract class BaseLLM implements ILLM {
if (result) {
yield result;
}
if (!citations && (chunk as any).citations && Array.isArray((chunk as any).citations)) {
citations = (chunk as any).citations;
}
}
}
} else {
@ -824,6 +830,10 @@ export abstract class BaseLLM implements ILLM {
if (logEnabled && this.writeLog) {
await this.writeLog(`Completion:\n${completion}\n\n`);
if (citations) {
await this.writeLog(`Citations:\n${citations.map((c, i) => `${i + 1}: ${c}`).join("\n")}\n\n`);
}
}
return {