-
Notifications
You must be signed in to change notification settings - Fork 405
Expand file tree
/
Copy pathtest-profiles.mjs
More file actions
118 lines (102 loc) · 4.41 KB
/
test-profiles.mjs
File metadata and controls
118 lines (102 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* Internal test for routing profiles
* Tests free/eco/auto/premium with real-world prompts
*/
import { route, DEFAULT_ROUTING_CONFIG, BLOCKRUN_MODELS } from "./dist/index.js";
// Build model pricing map
function buildModelPricing() {
const map = new Map();
for (const m of BLOCKRUN_MODELS) {
if (m.id === "auto" || m.id === "free" || m.id === "eco" || m.id === "premium") continue;
map.set(m.id, { inputPrice: m.inputPrice, outputPrice: m.outputPrice });
}
return map;
}
// Test prompts with varying complexity
const testPrompts = [
{
name: "Simple Q&A",
prompt: "What is the capital of France?",
systemPrompt: undefined,
maxTokens: 100,
},
{
name: "Code explanation",
prompt: "Explain how async/await works in JavaScript",
systemPrompt: "You are a helpful programming assistant.",
maxTokens: 500,
},
{
name: "Complex code task",
prompt:
"Write a TypeScript function that implements a LRU cache with generics, proper error handling, and thread safety",
systemPrompt: "You are an expert TypeScript developer.",
maxTokens: 2000,
},
{
name: "Reasoning task",
prompt:
"If a train leaves New York at 3pm traveling 60mph, and another leaves Boston at 4pm traveling 80mph, when will they meet? Show your reasoning step by step.",
systemPrompt: undefined,
maxTokens: 1000,
},
{
name: "Multi-step agentic task",
prompt:
"Research the latest trends in AI agents, analyze the top 3 frameworks, compare their features, and create a recommendation report",
systemPrompt: "You are an AI research analyst with access to web search and analysis tools.",
maxTokens: 4000,
},
];
const profiles = ["free", "eco", "auto", "premium"];
console.log("╔════════════════════════════════════════════════════════════╗");
console.log("║ ClawRouter Routing Profile Internal Test ║");
console.log("╠════════════════════════════════════════════════════════════╣");
console.log("");
const modelPricing = buildModelPricing();
const config = DEFAULT_ROUTING_CONFIG;
// Test each prompt with each profile
for (const test of testPrompts) {
console.log(`\n📝 Test: ${test.name}`);
console.log(` Prompt: "${test.prompt.slice(0, 60)}${test.prompt.length > 60 ? "..." : ""}"`);
console.log("");
const results = [];
for (const profile of profiles) {
const routerOpts = {
config,
modelPricing,
routingProfile: profile,
};
const decision = route(test.prompt, test.systemPrompt, test.maxTokens, routerOpts);
results.push({
profile,
model: decision.model,
tier: decision.tier,
cost: decision.costEstimate,
baseline: decision.baselineCost,
savings: decision.savings,
reasoning: decision.reasoning,
});
}
// Display results in a table
console.log(" Profile Tier Model Cost Savings");
console.log(" ───────── ───────── ────────────────────────────── ──────── ───────");
for (const r of results) {
const profileStr = r.profile.padEnd(9);
const tierStr = r.tier.padEnd(9);
const modelStr = r.model.slice(0, 30).padEnd(30);
const costStr = `$${r.cost.toFixed(6)}`.padStart(8);
const savingsStr = `${(r.savings * 100).toFixed(1)}%`.padStart(6);
console.log(` ${profileStr} ${tierStr} ${modelStr} ${costStr} ${savingsStr}`);
}
console.log("");
console.log(` 💡 Reasoning examples:`);
results.forEach((r) => {
if (r.profile === "auto" || r.profile === "eco") {
console.log(` [${r.profile}] ${r.reasoning}`);
}
});
}
console.log("\n╔════════════════════════════════════════════════════════════╗");
console.log("║ Test Complete ║");
console.log("╚════════════════════════════════════════════════════════════╝");