mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 07:12:12 +03:00
feat(logs): show compression tokens in request log UI (#1923)
Integrated into release/v3.7.9
This commit is contained in:
@@ -1437,7 +1437,9 @@ export async function handleChatCore({
|
||||
const cachedUsage =
|
||||
extractUsageFromResponse(cached as Record<string, unknown>, provider) ||
|
||||
((cached as Record<string, unknown>)?.usage as Record<string, unknown> | undefined);
|
||||
const cachedCost = cachedUsage ? await calculateCost(provider, model, cachedUsage as Record<string, number>) : 0;
|
||||
const cachedCost = cachedUsage
|
||||
? await calculateCost(provider, model, cachedUsage as Record<string, number>)
|
||||
: 0;
|
||||
persistAttemptLogs({
|
||||
status: 200,
|
||||
tokens: (cached as Record<string, unknown>)?.usage,
|
||||
|
||||
@@ -216,12 +216,9 @@ function cleanupArtifacts(text: string): string {
|
||||
}
|
||||
|
||||
function recapitalizeSentences(text: string): string {
|
||||
return text.replace(
|
||||
/(^|[.!?]\s+|^\s+)([a-z])/gm,
|
||||
(_match, prefix: string, char: string) => {
|
||||
return `${prefix}${char.toUpperCase()}`;
|
||||
}
|
||||
);
|
||||
return text.replace(/(^|[.!?]\s+|^\s+)([a-z])/gm, (_match, prefix: string, char: string) => {
|
||||
return `${prefix}${char.toUpperCase()}`;
|
||||
});
|
||||
}
|
||||
|
||||
function createCavemanStats(
|
||||
|
||||
@@ -85,7 +85,10 @@ export function validateCompression(original: string, compressed: string): Valid
|
||||
);
|
||||
requireExactPresence(
|
||||
"LaTeX block",
|
||||
collectMatches(original, /\\begin\{[A-Za-z*]{1,50}\}(?:(?!\\end\{)[^])*\\end\{[A-Za-z*]{1,50}\}/g),
|
||||
collectMatches(
|
||||
original,
|
||||
/\\begin\{[A-Za-z*]{1,50}\}(?:(?!\\end\{)[^])*\\end\{[A-Za-z*]{1,50}\}/g
|
||||
),
|
||||
compressed,
|
||||
errors
|
||||
);
|
||||
|
||||
4
src/lib/db/migrations/041_compression_tokens.sql
Normal file
4
src/lib/db/migrations/041_compression_tokens.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
-- Migration 041: Add tokens_compressed to call_logs
|
||||
-- Tracks how many tokens were removed by proactive context compression.
|
||||
-- NULL = compression not applied. N > 0 = tokens eliminated.
|
||||
ALTER TABLE call_logs ADD COLUMN tokens_compressed INTEGER DEFAULT NULL;
|
||||
Reference in New Issue
Block a user