@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 158 lines 4.49 KB
Raw
1 import type { EnvironmentSpeechModel } from "@t3tools/contracts";
2 import { expect, it } from "vite-plus/test";
3 import { recommendSpeechModels } from "@t3tools/shared/speech";
4
5 import { filterSpeechModels } from "./speechModelBrowser";
6
7 const model: EnvironmentSpeechModel = {
8 id: "active",
9 name: "Active",
10 description: "Local transcription",
11 size: 300,
12 languages: ["en", "fr"],
13 accuracy: 1,
14 speed: 1,
15 recommended: false,
16 supportsStreaming: false,
17 supportsLanguageDetection: false,
18 supportsTranslation: false,
19 active: true,
20 state: "installed",
21 };
22 const models: readonly EnvironmentSpeechModel[] = [
23 model,
24 {
25 ...model,
26 id: "small",
27 name: "Small",
28 size: 100,
29 active: false,
30 state: "downloadable",
31 recommended: true,
32 benchmark: {
33 accuracy: {
34 en: { grade: "A", errorPercent: 3.8 },
35 fr: { grade: "B", errorPercent: 7 },
36 },
37 secondsPer30s: { accelerated: 2, cpu: 1 },
38 },
39 },
40 {
41 ...model,
42 id: "fast",
43 name: "Fast",
44 size: 200,
45 active: false,
46 benchmark: {
47 accuracy: {
48 en: { grade: "A", errorPercent: 3.2 },
49 fr: { grade: "B", errorPercent: 9 },
50 },
51 secondsPer30s: { accelerated: 1, cpu: 3 },
52 },
53 },
54 {
55 ...model,
56 id: "pending",
57 name: "Pending",
58 size: 400,
59 active: false,
60 state: "verifying",
61 languages: ["en"],
62 benchmark: { accuracy: {}, secondsPer30s: { accelerated: null, cpu: null } },
63 },
64 ];
65
66 it.each([
67 ["recommended", "en", ["active", "fast", "pending", "small"]],
68 ["size", "en", ["small", "fast", "active", "pending"]],
69 ["speed", "en", ["fast", "small", "active", "pending"]],
70 ["accuracy", "en", ["fast", "small", "active", "pending"]],
71 ["accuracy", "fr", ["small", "fast", "active", "pending"]],
72 ] as const)(
73 "sorts by %s for %s with missing benchmarks last",
74 (sort, accuracyLanguage, expected) => {
75 expect(
76 filterSpeechModels(models, {
77 search: "",
78 languages: [],
79 downloadedOnly: false,
80 sort,
81 accuracyLanguage,
82 benchmarkTier: "accelerated",
83 }).map((entry) => entry.id),
84 ).toEqual(expected);
85 expect(models[0]?.id).toBe("active");
86 },
87 );
88
89 it("combines text, all selected languages, and completed downloads without retaining the active model", () => {
90 const options = {
91 search: " LOCAL ",
92 languages: ["en", "fr"],
93 downloadedOnly: true,
94 sort: "size",
95 accuracyLanguage: "en",
96 benchmarkTier: "accelerated",
97 } as const;
98 expect(filterSpeechModels(models, options).map((entry) => entry.id)).toEqual(["fast", "active"]);
99 expect(
100 filterSpeechModels(models, { ...options, search: "fast" }).map((entry) => entry.id),
101 ).toEqual(["fast"]);
102 expect(filterSpeechModels(models, { ...options, search: "small" })).toEqual([]);
103 });
104
105 it("ranks language recommendations before the rest without changing explicit sorts or search badges", () => {
106 const catalog = models.map((model) => ({
107 ...model,
108 active: false,
109 state: "downloadable" as const,
110 }));
111 const options = {
112 search: "",
113 languages: ["en"],
114 downloadedOnly: false,
115 sort: "recommended",
116 accuracyLanguage: "en",
117 benchmarkTier: "accelerated",
118 } as const;
119 expect(filterSpeechModels(catalog, options).map(({ id }) => id)).toEqual([
120 "fast",
121 "active",
122 "small",
123 "pending",
124 ]);
125 expect(
126 filterSpeechModels(catalog, { ...options, languages: ["en", "fr"] }).map(({ id }) => id),
127 ).toEqual(["small", "fast", "active"]);
128 expect(filterSpeechModels(catalog, { ...options, languages: [] }).map(({ id }) => id)).toEqual(
129 catalog.map(({ id }) => id),
130 );
131 expect(filterSpeechModels(catalog, { ...options, sort: "size" }).map(({ id }) => id)).toEqual([
132 "small",
133 "fast",
134 "active",
135 "pending",
136 ]);
137 expect(
138 filterSpeechModels(catalog, { ...options, sort: "speed", benchmarkTier: "cpu" }).map(
139 ({ id }) => id,
140 ),
141 ).toEqual(["small", "fast", "active", "pending"]);
142 expect(
143 filterSpeechModels(catalog, { ...options, sort: "accuracy", languages: ["en", "fr"] }).map(
144 ({ id }) => id,
145 ),
146 ).toEqual(["fast", "small", "active"]);
147 expect(
148 filterSpeechModels(catalog, { ...options, sort: "speed", languages: ["en", "fr"] }).map(
149 ({ id }) => id,
150 ),
151 ).toEqual(["fast", "small", "active"]);
152 expect(filterSpeechModels(catalog, { ...options, search: "small" }).map(({ id }) => id)).toEqual([
153 "small",
154 ]);
155 expect(
156 recommendSpeechModels(catalog, options.languages, options.benchmarkTier).has("small"),
157 ).toBe(false);
158 });