refactor: enhance logging details and context

This commit is contained in:
Han Xiao 2025-06-10 13:00:23 -07:00
parent 4b37ec8d04
commit 727767e93b
4 changed files with 11 additions and 8 deletions

View File

@ -694,9 +694,12 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
relatedImages,
};
logInfo('[chat/completions] Response:', {
logInfo(`[chat/completions] Completed!`, {
model: body.model,
usage: context.tokenTracker.getTotalUsageSnakeCase()
usage: context.tokenTracker.getTotalUsageSnakeCase(),
visitedURLs,
readURLs,
numURLs: allURLs.length,
});
res.json(response);

View File

@ -573,7 +573,7 @@ export async function evaluateQuestion(
prompt: prompt.user
});
logInfo('Question Evaluation:', result.object);
// Always include definitive in types
const types: EvaluationType[] = [];
@ -582,7 +582,7 @@ export async function evaluateQuestion(
if (result.object.needsPlurality) types.push('plurality');
if (result.object.needsCompleteness) types.push('completeness');
logInfo('Question Metrics:', { question, types });
logInfo(TOOL_NAME, { question, types });
trackers?.actionTracker.trackThink(result.object.think);
// Always evaluate definitive first, then freshness (if needed), then plurality (if needed)

View File

@ -221,7 +221,7 @@ export class ObjectGeneratorSafe {
private async handleGenerateObjectError<T>(error: unknown): Promise<GenerateObjectResult<T>> {
if (NoObjectGeneratedError.isInstance(error)) {
logWarning('Object not generated according to schema, fallback to manual parsing');
logWarning('Object not generated according to schema, fallback to manual parsing', { error });
try {
// First try standard JSON parsing
const partialResponse = JSON.parse((error as any).text);

View File

@ -9,7 +9,7 @@ import { classifyText } from "../tools/jina-classify-spam";
import { processImage } from "./image-tools";
import { segmentText } from "../tools/segment";
import axiosClient from "./axios-client";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logError, logDebug, logWarning } from '../logging';
export function normalizeUrl(urlString: string, debug = false, options = {
removeAnchors: true,
@ -601,7 +601,7 @@ export async function processURLs(
logError('Error parsing URL for hostname:', { url, error: e });
}
badHostnames.push(hostname);
logInfo(`Added ${hostname} to bad hostnames list`);
logDebug(`Added ${hostname} to bad hostnames list`);
}
return null;
} finally {
@ -630,7 +630,7 @@ export async function processURLs(
Object.keys(allURLs).forEach(url => {
if (badHostnames.includes(extractUrlParts(url).hostname)) {
delete allURLs[url];
logInfo(`Removed ${url} from allURLs`);
logWarning(`Removed ${url} from allURLs because of bad hostname`);
}
}
)