Instead of treating LLM logging as simply writing lines of text sequentially, emit a stream of typed data objects that include rich information about the interaction, such as timestamps, message types, tool calls, etc. These are then collected by a new custom webview in the vscode extension (the "Continue Console"), allowing a user or developer to browse through the different interactions and view them in detail. In progress interactions are now streamed live, instead of being held back to avoid concurrency issues. This webview could be also exposed for IntelliJ or file logging could be reimplemented on top of the new framework.
43 lines
971 B
TypeScript
43 lines
971 B
TypeScript
import {
|
|
ILLMLogger,
|
|
ILLMInteractionLog,
|
|
LLMInteractionItem,
|
|
LLMInteractionItemDetails,
|
|
} from "..";
|
|
|
|
type LLMLogItemFunction = (item: LLMInteractionItem) => void;
|
|
|
|
export class LLMLogger implements ILLMLogger {
|
|
private nextId = 0;
|
|
|
|
public createInteractionLog(): LLMInteractionLog {
|
|
return new LLMInteractionLog(this, (this.nextId++).toString());
|
|
}
|
|
|
|
private logItemListeners: LLMLogItemFunction[] = [];
|
|
|
|
onLogItem(listener: LLMLogItemFunction) {
|
|
this.logItemListeners.push(listener);
|
|
}
|
|
|
|
public _logItem(item: LLMInteractionItem) {
|
|
for (const listener of this.logItemListeners) {
|
|
listener(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class LLMInteractionLog implements ILLMInteractionLog {
|
|
constructor(
|
|
private logger: LLMLogger,
|
|
public interactionId: string,
|
|
) {}
|
|
|
|
logItem(item: LLMInteractionItemDetails) {
|
|
this.logger._logItem({
|
|
...item,
|
|
interactionId: this.interactionId,
|
|
timestamp: Date.now(),
|
|
});
|
|
}
|
|
}
|