chore: improve logging for formatters

This commit is contained in:
haritabh-z01 2025-12-16 11:31:09 +05:30
parent 9e913f3046
commit 7e3551caa3
2 changed files with 22 additions and 0 deletions

View file

@ -17,6 +17,12 @@ export class OllamaFormatter implements FormattingProvider {
// Construct the formatter prompt using the same function as OpenRouter
const { systemPrompt } = constructFormatterPrompt(context);
logger.pipeline.debug("Formatting request", {
model: this.model,
systemPrompt,
userPrompt: text,
});
// Use Ollama's chat endpoint for system/user message structure
const response = await fetch(`${this.ollamaUrl}/api/chat`, {
method: "POST",
@ -42,6 +48,11 @@ export class OllamaFormatter implements FormattingProvider {
const data = await response.json();
const aiResponse = data.message?.content ?? "";
logger.pipeline.debug("Formatting raw response", {
model: this.model,
rawResponse: aiResponse,
});
// Extract formatted text from XML tags (same as OpenRouter)
const match = aiResponse.match(
/<formatted_text>([\s\S]*?)<\/formatted_text>/,

View file

@ -31,6 +31,12 @@ export class OpenRouterProvider implements FormattingProvider {
// Build user prompt with context
const userPrompt = text;
logger.pipeline.info("Formatting request", {
model: this.model,
systemPrompt,
userPrompt,
});
const { text: aiResponse } = await generateText({
model: this.provider(this.model),
messages: [
@ -47,6 +53,11 @@ export class OpenRouterProvider implements FormattingProvider {
maxTokens: 2000,
});
logger.pipeline.debug("Formatting raw response", {
model: this.model,
rawResponse: aiResponse,
});
// Extract formatted text from XML tags
const match = aiResponse.match(
/<formatted_text>([\s\S]*?)<\/formatted_text>/,