mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
feat(compression/phase6): integrate caching-aware strategy into strategySelector
This commit is contained in:
@@ -1272,7 +1272,12 @@ export async function handleChatCore({
|
||||
try {
|
||||
const compressionConfig = getCompressionSettings();
|
||||
estimatedTokens = estimateCompressionTokens(body);
|
||||
const mode = selectCompressionStrategy(compressionConfig, comboName ?? null, estimatedTokens);
|
||||
const mode = selectCompressionStrategy(
|
||||
compressionConfig,
|
||||
comboName ?? null,
|
||||
estimatedTokens,
|
||||
body as Record<string, unknown>
|
||||
);
|
||||
if (mode !== "off") {
|
||||
const compressionResult = applyCompression(body as Record<string, unknown>, mode, {
|
||||
model: effectiveModel,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { cavemanCompress } from "./caveman.ts";
|
||||
import { compressAggressive } from "./aggressive.ts";
|
||||
import { ultraCompress } from "./ultra.ts";
|
||||
import { createCompressionStats } from "./stats.ts";
|
||||
import { detectCachingContext, getCacheAwareStrategy } from "./cachingAware.ts";
|
||||
|
||||
export function checkComboOverride(
|
||||
config: CompressionConfig,
|
||||
@@ -35,9 +36,19 @@ export function getEffectiveMode(
|
||||
export function selectCompressionStrategy(
|
||||
config: CompressionConfig,
|
||||
comboId: string | null,
|
||||
estimatedTokens: number
|
||||
estimatedTokens: number,
|
||||
body?: Record<string, unknown>
|
||||
): CompressionMode {
|
||||
return getEffectiveMode(config, comboId, estimatedTokens);
|
||||
const selectedMode = getEffectiveMode(config, comboId, estimatedTokens);
|
||||
|
||||
// Apply caching-aware adjustments if body is provided
|
||||
if (body) {
|
||||
const ctx = detectCachingContext(body);
|
||||
const cacheAware = getCacheAwareStrategy(selectedMode, ctx);
|
||||
return cacheAware.strategy as CompressionMode;
|
||||
}
|
||||
|
||||
return selectedMode;
|
||||
}
|
||||
|
||||
export async function applyCompression(
|
||||
|
||||
14
src/lib/db/migrations/033_compression_cache_stats.sql
Normal file
14
src/lib/db/migrations/033_compression_cache_stats.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS compression_cache_stats (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
provider TEXT NOT NULL,
|
||||
model TEXT NOT NULL DEFAULT '',
|
||||
compression_mode TEXT NOT NULL,
|
||||
cache_control_present INTEGER NOT NULL DEFAULT 0,
|
||||
estimated_cache_hit INTEGER NOT NULL DEFAULT 0,
|
||||
tokens_saved_compression INTEGER NOT NULL DEFAULT 0,
|
||||
tokens_saved_caching INTEGER NOT NULL DEFAULT 0,
|
||||
net_savings INTEGER NOT NULL DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_compression_cache_stats_provider ON compression_cache_stats(provider);
|
||||
CREATE INDEX IF NOT EXISTS idx_compression_cache_stats_created ON compression_cache_stats(created_at);
|
||||
@@ -79,6 +79,8 @@ export {
|
||||
deleteCombo,
|
||||
} from "./db/combos";
|
||||
|
||||
export * from "./db/compressionCacheStats";
|
||||
|
||||
export {
|
||||
// API Keys
|
||||
getApiKeys,
|
||||
|
||||
Reference in New Issue
Block a user