forked from dyad-sh/dyad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenrouter_free_models.test.ts
More file actions
56 lines (49 loc) · 1.8 KB
/
Copy pathopenrouter_free_models.test.ts
File metadata and controls
56 lines (49 loc) · 1.8 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
import { describe, expect, it } from "vitest";
import { buildOpenRouterFreeModels } from "@/ipc/shared/openrouter_free_models";
describe("buildOpenRouterFreeModels", () => {
it("filters to free models and decorates display names", () => {
const models = [
{
id: "paid/model",
name: "Paid Model",
pricing: { prompt: "0.01", completion: "0.02" },
},
{
id: "free/model",
name: "Awesome Model",
pricing: { prompt: "0", completion: "0" },
context_length: 128_000,
top_provider: { max_completion_tokens: 16_384 },
},
{
id: "free/with-label",
name: "Free Model",
pricing: { prompt: 0, completion: 0, image: 0 },
},
];
const result = buildOpenRouterFreeModels(models);
expect(result).toHaveLength(2);
const awesome = result.find((model) => model.apiName === "free/model");
expect(awesome?.displayName).toBe("Awesome Model");
expect(awesome?.contextWindow).toBe(128_000);
expect(awesome?.maxOutputTokens).toBe(16_384);
expect(awesome?.tag).toBe("Free");
const labeled = result.find((model) => model.apiName === "free/with-label");
expect(labeled?.displayName).toBe("Free Model");
expect(labeled?.dollarSigns).toBe(0);
});
it("sanitizes external model name and description fields", () => {
const models = [
{
id: "free/sanitized",
name: " <img src=x onerror=alert(1)>Safe Name (free) ",
description: "<script>alert(1)</script> Useful model ",
pricing: { prompt: 0, completion: 0 },
},
];
const result = buildOpenRouterFreeModels(models);
expect(result).toHaveLength(1);
expect(result[0]?.displayName).toBe("Safe Name");
expect(result[0]?.description).toBe("alert(1) Useful model");
});
});