Spaces:
Running
Running
Sync from felladrin/MiniSearch@79128cb (part 2)
Browse files- scripts/wllama-bench/bench.ts +190 -0
- scripts/wllama-bench/cases.json +374 -0
- scripts/wllama-bench/index.html +9 -0
- scripts/wllama-bench/run.mjs +180 -0
- scripts/wllama-bench/score.mjs +271 -0
- server/configEndpointServerHook.ts +5 -0
- shared/defaultSystemPrompt.ts +8 -1
- shared/serverConfig.ts +4 -0
scripts/wllama-bench/bench.ts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Browser side of the wllama benchmark. Runs inside the page that run.mjs
|
| 2 |
+
// opens, so a model is loaded and prompted through MiniSearch's own modules:
|
| 3 |
+
// the catalog entry, the warmup-then-load in initializeWllama, and the chat
|
| 4 |
+
// messages the search flow builds from results and page excerpts.
|
| 5 |
+
|
| 6 |
+
import {
|
| 7 |
+
getSettings,
|
| 8 |
+
queryPubSub,
|
| 9 |
+
settingsPubSub,
|
| 10 |
+
updateLlmTextSearchResults,
|
| 11 |
+
updatePageContents,
|
| 12 |
+
} from "../../client/modules/pubSub";
|
| 13 |
+
import {
|
| 14 |
+
defaultContextSize,
|
| 15 |
+
getDefaultChatMessages,
|
| 16 |
+
getFormattedSearchResults,
|
| 17 |
+
} from "../../client/modules/textGenerationUtilities";
|
| 18 |
+
import type { TextSearchResults } from "../../client/modules/types";
|
| 19 |
+
import { initializeWllama, wllamaModels } from "../../client/modules/wllama";
|
| 20 |
+
|
| 21 |
+
interface BenchCase {
|
| 22 |
+
name: string;
|
| 23 |
+
query: string;
|
| 24 |
+
results: TextSearchResults;
|
| 25 |
+
pages: Record<string, string>;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
interface BenchOptions {
|
| 29 |
+
/** A catalog id, or `owner/repo/file.gguf` for a model not in the catalog. */
|
| 30 |
+
model: string;
|
| 31 |
+
device: "webgpu" | "cpu";
|
| 32 |
+
/** Defaults to MiniSearch's own `cpuThreads` setting. */
|
| 33 |
+
threads?: number;
|
| 34 |
+
cases: BenchCase[];
|
| 35 |
+
chatTemplateKwargs?: Record<string, unknown>;
|
| 36 |
+
reasoningBudgetTokens?: number;
|
| 37 |
+
/** Seconds before an answer is cut off and marked as timed out. */
|
| 38 |
+
caseTimeoutSeconds: number;
|
| 39 |
+
/** Replaces the default system prompt, to measure a change to it. */
|
| 40 |
+
systemPrompt?: string;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function resolveModel(id: string) {
|
| 44 |
+
const catalogModel = wllamaModels[id];
|
| 45 |
+
if (catalogModel) return catalogModel;
|
| 46 |
+
|
| 47 |
+
const [owner, repo, ...file] = id.split("/");
|
| 48 |
+
if (!owner || !repo || file.length === 0) {
|
| 49 |
+
throw new Error(
|
| 50 |
+
`"${id}" is neither a catalog id nor an owner/repo/file.gguf path`,
|
| 51 |
+
);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Starts from a catalog entry's shared defaults, minus the thinking budget
|
| 55 |
+
// that only some entries set, as a new catalog entry would.
|
| 56 |
+
return {
|
| 57 |
+
...Object.values(wllamaModels)[0],
|
| 58 |
+
reasoningBudgetTokens: undefined,
|
| 59 |
+
label: id,
|
| 60 |
+
hfRepoId: `${owner}/${repo}`,
|
| 61 |
+
hfFilePath: file.join("/"),
|
| 62 |
+
};
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
async function runBench(options: BenchOptions) {
|
| 66 |
+
if (options.device === "webgpu" && !(await navigator.gpu?.requestAdapter())) {
|
| 67 |
+
throw new Error("This browser exposes no WebGPU adapter");
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const catalogModel = resolveModel(options.model);
|
| 71 |
+
const model = {
|
| 72 |
+
...catalogModel,
|
| 73 |
+
chatTemplateKwargs:
|
| 74 |
+
options.chatTemplateKwargs ?? catalogModel.chatTemplateKwargs,
|
| 75 |
+
reasoningBudgetTokens:
|
| 76 |
+
options.reasoningBudgetTokens ?? catalogModel.reasoningBudgetTokens,
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
if (options.systemPrompt) {
|
| 80 |
+
settingsPubSub[0]({ ...getSettings(), systemPrompt: options.systemPrompt });
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
const loadStart = performance.now();
|
| 84 |
+
// Mirrors initializeWllamaInstance in client/modules/textGenerationWithWllama.ts,
|
| 85 |
+
// with the device forced instead of detected.
|
| 86 |
+
const wllama = await initializeWllama(model.hfRepoId, model.hfFilePath, {
|
| 87 |
+
wllama: { suppressNativeLog: false, allowOffline: true },
|
| 88 |
+
chatTemplateKwargs: model.chatTemplateKwargs,
|
| 89 |
+
model: {
|
| 90 |
+
n_threads: options.threads ?? getSettings().cpuThreads,
|
| 91 |
+
n_ctx: model.contextSize,
|
| 92 |
+
n_batch: 512,
|
| 93 |
+
cache_type_k: model.cacheTypeK,
|
| 94 |
+
cache_type_v: model.cacheTypeV,
|
| 95 |
+
flash_attn: model.flash_attn,
|
| 96 |
+
embeddings: false,
|
| 97 |
+
n_gpu_layers: options.device === "webgpu" ? 99999 : 0,
|
| 98 |
+
...(model.reasoningBudgetTokens
|
| 99 |
+
? { reasoning_budget_tokens: model.reasoningBudgetTokens }
|
| 100 |
+
: {}),
|
| 101 |
+
},
|
| 102 |
+
});
|
| 103 |
+
const loadSeconds = (performance.now() - loadStart) / 1000;
|
| 104 |
+
|
| 105 |
+
const cases = [];
|
| 106 |
+
for (const benchCase of options.cases) {
|
| 107 |
+
queryPubSub[0](benchCase.query);
|
| 108 |
+
updateLlmTextSearchResults(benchCase.results);
|
| 109 |
+
updatePageContents(benchCase.pages);
|
| 110 |
+
const messages = getDefaultChatMessages(
|
| 111 |
+
await getFormattedSearchResults(model.shouldIncludeUrlsOnPrompt),
|
| 112 |
+
);
|
| 113 |
+
|
| 114 |
+
const start = performance.now();
|
| 115 |
+
let firstAnswerAt: number | undefined;
|
| 116 |
+
let thinkingTokens = 0;
|
| 117 |
+
let answerTokens = 0;
|
| 118 |
+
let reasoning = "";
|
| 119 |
+
let answer = "";
|
| 120 |
+
let timings: Record<string, number> | undefined;
|
| 121 |
+
const abortController = new AbortController();
|
| 122 |
+
const timeout = setTimeout(
|
| 123 |
+
() => abortController.abort(),
|
| 124 |
+
options.caseTimeoutSeconds * 1000,
|
| 125 |
+
);
|
| 126 |
+
|
| 127 |
+
const stream = await wllama.createChatCompletion({
|
| 128 |
+
messages,
|
| 129 |
+
max_tokens: defaultContextSize,
|
| 130 |
+
stream: true,
|
| 131 |
+
abortSignal: abortController.signal,
|
| 132 |
+
...model.getSampling(),
|
| 133 |
+
...(model.chatTemplateKwargs
|
| 134 |
+
? { chat_template_kwargs: model.chatTemplateKwargs }
|
| 135 |
+
: {}),
|
| 136 |
+
});
|
| 137 |
+
|
| 138 |
+
try {
|
| 139 |
+
for await (const chunk of stream) {
|
| 140 |
+
const delta = chunk.choices[0]?.delta as
|
| 141 |
+
| { content?: string; reasoning_content?: string }
|
| 142 |
+
| undefined;
|
| 143 |
+
if (delta?.reasoning_content) {
|
| 144 |
+
thinkingTokens++;
|
| 145 |
+
reasoning += delta.reasoning_content;
|
| 146 |
+
}
|
| 147 |
+
if (delta?.content) {
|
| 148 |
+
firstAnswerAt ??= performance.now();
|
| 149 |
+
answerTokens++;
|
| 150 |
+
answer += delta.content;
|
| 151 |
+
}
|
| 152 |
+
// The engine's own timings ride on the stream's chunks; the last one
|
| 153 |
+
// covers the whole completion.
|
| 154 |
+
const chunkTimings = (chunk as { timings?: Record<string, number> })
|
| 155 |
+
.timings;
|
| 156 |
+
if (chunkTimings) timings = chunkTimings;
|
| 157 |
+
}
|
| 158 |
+
} catch (error) {
|
| 159 |
+
if (!abortController.signal.aborted) throw error;
|
| 160 |
+
} finally {
|
| 161 |
+
clearTimeout(timeout);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
const end = performance.now();
|
| 165 |
+
cases.push({
|
| 166 |
+
name: benchCase.name,
|
| 167 |
+
promptTokens: timings?.prompt_n,
|
| 168 |
+
promptTokensPerSecond: timings?.prompt_per_second,
|
| 169 |
+
generatedTokensPerSecond: timings?.predicted_per_second,
|
| 170 |
+
thinkingTokens,
|
| 171 |
+
answerTokens,
|
| 172 |
+
secondsToFirstAnswerToken:
|
| 173 |
+
firstAnswerAt === undefined
|
| 174 |
+
? undefined
|
| 175 |
+
: (firstAnswerAt - start) / 1000,
|
| 176 |
+
totalSeconds: (end - start) / 1000,
|
| 177 |
+
timedOut: abortController.signal.aborted,
|
| 178 |
+
// Kept so the scorer can tell an echoed instruction from an answer.
|
| 179 |
+
prompt: messages[0].content,
|
| 180 |
+
reasoning,
|
| 181 |
+
answer,
|
| 182 |
+
});
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
await wllama.exit();
|
| 186 |
+
|
| 187 |
+
return { model: model.label, device: options.device, loadSeconds, cases };
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
Object.assign(window, { runBench, benchReady: true });
|
scripts/wllama-bench/cases.json
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"name": "en",
|
| 4 |
+
"language": "en",
|
| 5 |
+
"facts": ["330", "Koechlin|Nouguier", "1889"],
|
| 6 |
+
"query": "How tall is the Eiffel Tower, who designed it, and why was it built?",
|
| 7 |
+
"results": [
|
| 8 |
+
[
|
| 9 |
+
"Eiffel Tower height and dimensions",
|
| 10 |
+
"Standing 330 metres including its antennas, the tower is the tallest structure in Paris.",
|
| 11 |
+
"https://example.org/eiffel-height"
|
| 12 |
+
],
|
| 13 |
+
[
|
| 14 |
+
"Who designed the Eiffel Tower?",
|
| 15 |
+
"Engineers Maurice Koechlin and Émile Nouguier drew the first design; Gustave Eiffel's company built it.",
|
| 16 |
+
"https://example.org/eiffel-design"
|
| 17 |
+
],
|
| 18 |
+
[
|
| 19 |
+
"The 1889 Exposition Universelle",
|
| 20 |
+
"The tower was the entrance arch to the 1889 World's Fair, marking 100 years since the French Revolution.",
|
| 21 |
+
"https://example.org/expo-1889"
|
| 22 |
+
]
|
| 23 |
+
],
|
| 24 |
+
"pages": {
|
| 25 |
+
"https://example.org/eiffel-design": "The idea for the tower came from Maurice Koechlin and Émile Nouguier, two senior engineers at Gustave Eiffel's firm. Architect Stephen Sauvestre reworked the look of their first sketch. Eiffel bought the rights to the patent from his engineers and promoted the project, so the tower carries his name."
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"name": "pt-from-en",
|
| 30 |
+
"language": "pt",
|
| 31 |
+
"facts": ["330", "1889"],
|
| 32 |
+
"query": "Qual é a altura da Torre Eiffel e por que ela foi construída?",
|
| 33 |
+
"results": [
|
| 34 |
+
[
|
| 35 |
+
"Eiffel Tower height and dimensions",
|
| 36 |
+
"Standing 330 metres including its antennas, the tower is the tallest structure in Paris.",
|
| 37 |
+
"https://example.org/eiffel-height"
|
| 38 |
+
],
|
| 39 |
+
[
|
| 40 |
+
"The 1889 Exposition Universelle",
|
| 41 |
+
"The tower was the entrance arch to the 1889 World's Fair, marking 100 years since the French Revolution.",
|
| 42 |
+
"https://example.org/expo-1889"
|
| 43 |
+
],
|
| 44 |
+
[
|
| 45 |
+
"Eiffel Tower facts",
|
| 46 |
+
"It was the world's tallest man-made structure for 41 years, until New York's Chrysler Building in 1930.",
|
| 47 |
+
"https://example.org/eiffel-facts"
|
| 48 |
+
]
|
| 49 |
+
],
|
| 50 |
+
"pages": {}
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"name": "es",
|
| 54 |
+
"language": "es",
|
| 55 |
+
"facts": ["1914", "82"],
|
| 56 |
+
"query": "¿Cuándo se inauguró el Canal de Panamá y cuánto mide?",
|
| 57 |
+
"results": [
|
| 58 |
+
[
|
| 59 |
+
"Canal de Panamá - Historia",
|
| 60 |
+
"El Canal de Panamá se inauguró el 15 de agosto de 1914, tras diez años de obras dirigidas por Estados Unidos.",
|
| 61 |
+
"https://example.org/canal-historia"
|
| 62 |
+
],
|
| 63 |
+
[
|
| 64 |
+
"Datos del Canal de Panamá",
|
| 65 |
+
"El canal mide unos 82 kilómetros y une el océano Atlántico con el océano Pacífico.",
|
| 66 |
+
"https://example.org/canal-datos"
|
| 67 |
+
],
|
| 68 |
+
[
|
| 69 |
+
"Ampliación del canal",
|
| 70 |
+
"Las nuevas esclusas, abiertas en 2016, permiten el paso de buques mucho más grandes.",
|
| 71 |
+
"https://example.org/canal-ampliacion"
|
| 72 |
+
]
|
| 73 |
+
],
|
| 74 |
+
"pages": {
|
| 75 |
+
"https://example.org/canal-datos": "El Canal de Panamá tiene una longitud aproximada de 82 kilómetros. Un barco tarda entre ocho y diez horas en cruzarlo. El canal utiliza un sistema de esclusas que eleva los barcos hasta el lago Gatún, a 26 metros sobre el nivel del mar."
|
| 76 |
+
}
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
"name": "fr",
|
| 80 |
+
"language": "fr",
|
| 81 |
+
"facts": ["1862", "Bruxelles|Belgique"],
|
| 82 |
+
"query": "Quand et où Les Misérables a-t-il été publié pour la première fois ?",
|
| 83 |
+
"results": [
|
| 84 |
+
[
|
| 85 |
+
"Les Misérables - Publication",
|
| 86 |
+
"Le roman de Victor Hugo paraît pour la première fois en 1862, à Bruxelles, chez l'éditeur Lacroix.",
|
| 87 |
+
"https://example.org/miserables-publication"
|
| 88 |
+
],
|
| 89 |
+
[
|
| 90 |
+
"Victor Hugo en exil",
|
| 91 |
+
"Hugo écrit la fin du roman pendant son exil à Guernesey.",
|
| 92 |
+
"https://example.org/hugo-exil"
|
| 93 |
+
],
|
| 94 |
+
[
|
| 95 |
+
"Les Misérables - Résumé",
|
| 96 |
+
"Le livre suit Jean Valjean, un ancien forçat, de 1815 à 1832.",
|
| 97 |
+
"https://example.org/miserables-resume"
|
| 98 |
+
]
|
| 99 |
+
],
|
| 100 |
+
"pages": {}
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"name": "de",
|
| 104 |
+
"language": "de",
|
| 105 |
+
"facts": ["1989", "155"],
|
| 106 |
+
"query": "Wann fiel die Berliner Mauer und wie lang war sie?",
|
| 107 |
+
"results": [
|
| 108 |
+
[
|
| 109 |
+
"Fall der Berliner Mauer",
|
| 110 |
+
"Am 9. November 1989 öffnete die DDR die Grenzübergänge, und die Berliner Mauer fiel.",
|
| 111 |
+
"https://example.org/mauerfall"
|
| 112 |
+
],
|
| 113 |
+
[
|
| 114 |
+
"Die Berliner Mauer in Zahlen",
|
| 115 |
+
"Die Grenzanlagen rund um West-Berlin waren etwa 155 Kilometer lang.",
|
| 116 |
+
"https://example.org/mauer-zahlen"
|
| 117 |
+
],
|
| 118 |
+
[
|
| 119 |
+
"Bau der Mauer",
|
| 120 |
+
"Mit dem Bau der Mauer begann die DDR am 13. August 1961.",
|
| 121 |
+
"https://example.org/mauerbau"
|
| 122 |
+
]
|
| 123 |
+
],
|
| 124 |
+
"pages": {}
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"name": "zh",
|
| 128 |
+
"language": "zh",
|
| 129 |
+
"facts": ["21[,,\\s\\u202f]?196|2\\.1万|两万一千"],
|
| 130 |
+
"query": "长城的总长度是多少?",
|
| 131 |
+
"results": [
|
| 132 |
+
[
|
| 133 |
+
"长城资源调查结果",
|
| 134 |
+
"2012年,国家文物局公布历代长城总长度为21196.18千米。",
|
| 135 |
+
"https://example.org/changcheng-diaocha"
|
| 136 |
+
],
|
| 137 |
+
[
|
| 138 |
+
"长城简介",
|
| 139 |
+
"长城是中国古代的军事防御工程,修筑历史可上溯到西周时期。",
|
| 140 |
+
"https://example.org/changcheng-jianjie"
|
| 141 |
+
],
|
| 142 |
+
[
|
| 143 |
+
"明长城",
|
| 144 |
+
"现存的长城遗迹主要为明代所修,东起鸭绿江,西至嘉峪关。",
|
| 145 |
+
"https://example.org/ming-changcheng"
|
| 146 |
+
]
|
| 147 |
+
],
|
| 148 |
+
"pages": {}
|
| 149 |
+
},
|
| 150 |
+
{
|
| 151 |
+
"name": "ja",
|
| 152 |
+
"language": "ja",
|
| 153 |
+
"facts": ["3[,,\\s\\u202f]?776|三千七百七十六"],
|
| 154 |
+
"query": "富士山の標高はどのくらいですか?",
|
| 155 |
+
"results": [
|
| 156 |
+
[
|
| 157 |
+
"富士山 - 基本情報",
|
| 158 |
+
"富士山は静岡県と山梨県にまたがる活火山で、標高は3776メートル、日本で最も高い山です。",
|
| 159 |
+
"https://example.org/fujisan-kihon"
|
| 160 |
+
],
|
| 161 |
+
[
|
| 162 |
+
"富士山の世界遺産登録",
|
| 163 |
+
"富士山は2013年に「富士山-信仰の対象と芸術の源泉」として世界文化遺産に登録されました。",
|
| 164 |
+
"https://example.org/fujisan-isan"
|
| 165 |
+
],
|
| 166 |
+
[
|
| 167 |
+
"富士登山の季節",
|
| 168 |
+
"一般的な登山シーズンは7月上旬から9月上旬までです。",
|
| 169 |
+
"https://example.org/fujisan-tozan"
|
| 170 |
+
]
|
| 171 |
+
],
|
| 172 |
+
"pages": {}
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"name": "ko",
|
| 176 |
+
"language": "ko",
|
| 177 |
+
"facts": ["1[,,\\s\\u202f]?947"],
|
| 178 |
+
"query": "한라산의 높이는 얼마인가요?",
|
| 179 |
+
"results": [
|
| 180 |
+
[
|
| 181 |
+
"한라산 - 개요",
|
| 182 |
+
"한라산은 제주도 중앙에 있는 화산으로, 높이는 1,947미터이며 남한에서 가장 높은 산이다.",
|
| 183 |
+
"https://example.org/hallasan-gaeyo"
|
| 184 |
+
],
|
| 185 |
+
[
|
| 186 |
+
"한라산 국립공원",
|
| 187 |
+
"한라산 일대는 1970년에 국립공원으로 지정되었다.",
|
| 188 |
+
"https://example.org/hallasan-gongwon"
|
| 189 |
+
],
|
| 190 |
+
[
|
| 191 |
+
"백록담",
|
| 192 |
+
"정상에는 백록담이라는 화구호가 있다.",
|
| 193 |
+
"https://example.org/baengnokdam"
|
| 194 |
+
]
|
| 195 |
+
],
|
| 196 |
+
"pages": {}
|
| 197 |
+
},
|
| 198 |
+
{
|
| 199 |
+
"name": "ar",
|
| 200 |
+
"language": "ar",
|
| 201 |
+
"facts": ["1869|١٨٦٩"],
|
| 202 |
+
"query": "متى افتتحت قناة السويس؟",
|
| 203 |
+
"results": [
|
| 204 |
+
[
|
| 205 |
+
"قناة السويس - التاريخ",
|
| 206 |
+
"افتتحت قناة السويس للملاحة في 17 نوفمبر 1869 بعد عشر سنوات من الحفر.",
|
| 207 |
+
"https://example.org/suez-tarikh"
|
| 208 |
+
],
|
| 209 |
+
[
|
| 210 |
+
"قناة السويس - الموقع",
|
| 211 |
+
"تربط القناة بين البحر الأبيض المتوسط والبحر الأحمر.",
|
| 212 |
+
"https://example.org/suez-mawqi"
|
| 213 |
+
],
|
| 214 |
+
[
|
| 215 |
+
"تأميم القناة",
|
| 216 |
+
"أمم الرئيس جمال عبد الناصر شركة قناة السويس عام 1956.",
|
| 217 |
+
"https://example.org/suez-tamim"
|
| 218 |
+
]
|
| 219 |
+
],
|
| 220 |
+
"pages": {}
|
| 221 |
+
},
|
| 222 |
+
{
|
| 223 |
+
"name": "hi",
|
| 224 |
+
"language": "hi",
|
| 225 |
+
"facts": [
|
| 226 |
+
"शाहजहाँ|शाहजहां|शाह जहाँ|शाह जहां|Shah ?Jahan",
|
| 227 |
+
"मुमताज़|मुमताज|Mumtaz"
|
| 228 |
+
],
|
| 229 |
+
"query": "ताजमहल किसने और किसकी याद में बनवाया था?",
|
| 230 |
+
"results": [
|
| 231 |
+
[
|
| 232 |
+
"ताजमहल - इतिहास",
|
| 233 |
+
"ताजमहल का निर्माण मुग़ल बादशाह शाहजहाँ ने अपनी पत्नी मुमताज़ महल की याद में करवाया था।",
|
| 234 |
+
"https://example.org/tajmahal-itihas"
|
| 235 |
+
],
|
| 236 |
+
[
|
| 237 |
+
"ताजमहल - स्थान",
|
| 238 |
+
"ताजमहल आगरा में यमुना नदी के किनारे स्थित है।",
|
| 239 |
+
"https://example.org/tajmahal-sthan"
|
| 240 |
+
],
|
| 241 |
+
[
|
| 242 |
+
"विश्व धरोहर",
|
| 243 |
+
"ताजमहल को 1983 में यूनेस्को विश्व धरोहर स्थल घोषित किया गया।",
|
| 244 |
+
"https://example.org/tajmahal-dharohar"
|
| 245 |
+
]
|
| 246 |
+
],
|
| 247 |
+
"pages": {}
|
| 248 |
+
},
|
| 249 |
+
{
|
| 250 |
+
"name": "ru",
|
| 251 |
+
"language": "ru",
|
| 252 |
+
"facts": ["1703", "Пётр|Петр|Петра|Петром|Петру"],
|
| 253 |
+
"query": "Когда и кем был основан Санкт-Петербург?",
|
| 254 |
+
"results": [
|
| 255 |
+
[
|
| 256 |
+
"История Санкт-Петербурга",
|
| 257 |
+
"Санкт-Петербург был основан Петром I 27 мая 1703 года в устье реки Невы.",
|
| 258 |
+
"https://example.org/spb-istoriya"
|
| 259 |
+
],
|
| 260 |
+
[
|
| 261 |
+
"Санкт-Петербург - столица империи",
|
| 262 |
+
"С 1712 по 1918 год город был столицей России.",
|
| 263 |
+
"https://example.org/spb-stolitsa"
|
| 264 |
+
],
|
| 265 |
+
[
|
| 266 |
+
"Петропавловская крепость",
|
| 267 |
+
"Крепость, заложенная в день основания города, стала его п��рвым сооружением.",
|
| 268 |
+
"https://example.org/spb-krepost"
|
| 269 |
+
]
|
| 270 |
+
],
|
| 271 |
+
"pages": {}
|
| 272 |
+
},
|
| 273 |
+
{
|
| 274 |
+
"name": "de-synthesis",
|
| 275 |
+
"language": "de",
|
| 276 |
+
"facts": ["Gro(ß|ss)glockner", "836"],
|
| 277 |
+
"allowNumbers": ["836"],
|
| 278 |
+
"query": "Welcher Berg ist höher, die Zugspitze oder der Großglockner, und um wie viel?",
|
| 279 |
+
"results": [
|
| 280 |
+
[
|
| 281 |
+
"Zugspitze - Steckbrief",
|
| 282 |
+
"Die Zugspitze ist mit 2962 Metern der höchste Berg Deutschlands.",
|
| 283 |
+
"https://example.org/zugspitze"
|
| 284 |
+
],
|
| 285 |
+
[
|
| 286 |
+
"Großglockner - Steckbrief",
|
| 287 |
+
"Der Großglockner ist mit 3798 Metern der höchste Berg Österreichs.",
|
| 288 |
+
"https://example.org/grossglockner"
|
| 289 |
+
],
|
| 290 |
+
[
|
| 291 |
+
"Alpen in Zahlen",
|
| 292 |
+
"Die Alpen erstrecken sich über acht Staaten.",
|
| 293 |
+
"https://example.org/alpen"
|
| 294 |
+
]
|
| 295 |
+
],
|
| 296 |
+
"pages": {}
|
| 297 |
+
},
|
| 298 |
+
{
|
| 299 |
+
"name": "es-distractor",
|
| 300 |
+
"language": "es",
|
| 301 |
+
"facts": ["183|204"],
|
| 302 |
+
"forbidden": ["225", "246"],
|
| 303 |
+
"query": "¿Qué altura tiene la Torre Latinoamericana?",
|
| 304 |
+
"results": [
|
| 305 |
+
[
|
| 306 |
+
"Torre Mayor",
|
| 307 |
+
"La Torre Mayor, en Paseo de la Reforma, mide 225 metros.",
|
| 308 |
+
"https://example.org/torre-mayor"
|
| 309 |
+
],
|
| 310 |
+
[
|
| 311 |
+
"Torre Reforma",
|
| 312 |
+
"Con 246 metros, la Torre Reforma es una de las más altas de la Ciudad de México.",
|
| 313 |
+
"https://example.org/torre-reforma"
|
| 314 |
+
],
|
| 315 |
+
[
|
| 316 |
+
"Torre Latinoamericana",
|
| 317 |
+
"La Torre Latinoamericana, inaugurada en 1956, mide 183 metros, o 204 metros con su antena.",
|
| 318 |
+
"https://example.org/torre-latinoamericana"
|
| 319 |
+
]
|
| 320 |
+
],
|
| 321 |
+
"pages": {}
|
| 322 |
+
},
|
| 323 |
+
{
|
| 324 |
+
"name": "pt-not-covered",
|
| 325 |
+
"language": "pt",
|
| 326 |
+
"allowOwnKnowledge": true,
|
| 327 |
+
"facts": [
|
| 328 |
+
"não[^.]{0,30}(informa|menciona|traz|cont[eé]m|apresenta|fornece|cita|encontr|lista|consta)|não há informaç|nenhum dos resultados|resultados não|sem (essa|esta) informação|(próprio|meu) conhecimento"
|
| 329 |
+
],
|
| 330 |
+
"query": "Qual é a população atual de Curitiba?",
|
| 331 |
+
"results": [
|
| 332 |
+
[
|
| 333 |
+
"Clima de Curitiba",
|
| 334 |
+
"Curitiba tem clima subtropical úmido, com invernos frios e geadas frequentes.",
|
| 335 |
+
"https://example.org/curitiba-clima"
|
| 336 |
+
],
|
| 337 |
+
[
|
| 338 |
+
"Transporte em Curitiba",
|
| 339 |
+
"O sistema de ônibus BRT de Curitiba foi inaugurado em 1974 e inspirou cidades do mundo todo.",
|
| 340 |
+
"https://example.org/curitiba-brt"
|
| 341 |
+
],
|
| 342 |
+
[
|
| 343 |
+
"Ópera de Arame",
|
| 344 |
+
"A Ópera de Arame, teatro de estrutura tubular, foi inaugurada em 1992.",
|
| 345 |
+
"https://example.org/opera-de-arame"
|
| 346 |
+
]
|
| 347 |
+
],
|
| 348 |
+
"pages": {}
|
| 349 |
+
},
|
| 350 |
+
{
|
| 351 |
+
"name": "zh-from-en",
|
| 352 |
+
"language": "zh",
|
| 353 |
+
"facts": ["8[,,\\s\\u202f]?848"],
|
| 354 |
+
"query": "珠穆朗玛峰有多高?",
|
| 355 |
+
"results": [
|
| 356 |
+
[
|
| 357 |
+
"Mount Everest height",
|
| 358 |
+
"A 2020 survey by China and Nepal set Mount Everest's height at 8,848.86 metres above sea level.",
|
| 359 |
+
"https://example.org/everest-height"
|
| 360 |
+
],
|
| 361 |
+
[
|
| 362 |
+
"Climbing Everest",
|
| 363 |
+
"Most climbers attempt the summit in May, when the jet stream moves away.",
|
| 364 |
+
"https://example.org/everest-climbing"
|
| 365 |
+
],
|
| 366 |
+
[
|
| 367 |
+
"Everest in Nepal and Tibet",
|
| 368 |
+
"The mountain sits on the border between Nepal and the Tibet Autonomous Region of China.",
|
| 369 |
+
"https://example.org/everest-border"
|
| 370 |
+
]
|
| 371 |
+
],
|
| 372 |
+
"pages": {}
|
| 373 |
+
}
|
| 374 |
+
]
|
scripts/wllama-bench/index.html
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<title>wllama bench</title>
|
| 6 |
+
<script type="module" src="./bench.ts"></script>
|
| 7 |
+
</head>
|
| 8 |
+
<body></body>
|
| 9 |
+
</html>
|
scripts/wllama-bench/run.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
// Benchmarks wllama models in a real browser, through MiniSearch's own
|
| 3 |
+
// catalog, loading code and prompt builder. Manual tool, not part of
|
| 4 |
+
// `npm run lint`:
|
| 5 |
+
//
|
| 6 |
+
// npm run bench:wllama -- --model qwen-3.5-0.8b
|
| 7 |
+
// npm run bench:wllama -- --model owner/repo/file-00001-of-00003.gguf --device webgpu
|
| 8 |
+
//
|
| 9 |
+
// See docs/development-commands.md#wllama-benchmark for the options.
|
| 10 |
+
|
| 11 |
+
import { readFileSync, writeFileSync } from "node:fs";
|
| 12 |
+
import { tmpdir } from "node:os";
|
| 13 |
+
import path from "node:path";
|
| 14 |
+
import { fileURLToPath } from "node:url";
|
| 15 |
+
import { parseArgs } from "node:util";
|
| 16 |
+
import { chromium } from "@playwright/test";
|
| 17 |
+
import { createServer } from "vite";
|
| 18 |
+
import { scoreResults } from "./score.mjs";
|
| 19 |
+
|
| 20 |
+
const benchDir = path.dirname(fileURLToPath(import.meta.url));
|
| 21 |
+
const repoRoot = path.resolve(benchDir, "../..");
|
| 22 |
+
|
| 23 |
+
const { values } = parseArgs({
|
| 24 |
+
options: {
|
| 25 |
+
model: { type: "string", multiple: true },
|
| 26 |
+
device: { type: "string", default: "both" },
|
| 27 |
+
runs: { type: "string", default: "1" },
|
| 28 |
+
threads: { type: "string" },
|
| 29 |
+
"template-kwargs": { type: "string" },
|
| 30 |
+
"reasoning-budget": { type: "string" },
|
| 31 |
+
chrome: { type: "string" },
|
| 32 |
+
json: { type: "string" },
|
| 33 |
+
"case-timeout": { type: "string", default: "300" },
|
| 34 |
+
"system-prompt": { type: "string" },
|
| 35 |
+
cases: { type: "string", default: path.join(benchDir, "cases.json") },
|
| 36 |
+
profile: {
|
| 37 |
+
type: "string",
|
| 38 |
+
default: path.join(tmpdir(), "minisearch-wllama-bench-profile"),
|
| 39 |
+
},
|
| 40 |
+
verbose: { type: "boolean", default: false },
|
| 41 |
+
},
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
if (!values.model?.length) {
|
| 45 |
+
throw new Error(
|
| 46 |
+
"Pass at least one --model <catalog id | owner/repo/file.gguf>",
|
| 47 |
+
);
|
| 48 |
+
}
|
| 49 |
+
if (!["webgpu", "cpu", "both"].includes(values.device)) {
|
| 50 |
+
throw new Error(
|
| 51 |
+
`--device must be webgpu, cpu or both, not "${values.device}"`,
|
| 52 |
+
);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
const devices = values.device === "both" ? ["webgpu", "cpu"] : [values.device];
|
| 56 |
+
const runs = Number(values.runs);
|
| 57 |
+
const cases = JSON.parse(readFileSync(values.cases, "utf8"));
|
| 58 |
+
|
| 59 |
+
const server = await createServer({
|
| 60 |
+
configFile: false,
|
| 61 |
+
root: repoRoot,
|
| 62 |
+
logLevel: "error",
|
| 63 |
+
server: {
|
| 64 |
+
host: "127.0.0.1",
|
| 65 |
+
// SharedArrayBuffer, which wllama's threads need, requires an
|
| 66 |
+
// isolated page; the app gets the same headers from crossOriginServerHook.
|
| 67 |
+
headers: {
|
| 68 |
+
"Cross-Origin-Opener-Policy": "same-origin",
|
| 69 |
+
"Cross-Origin-Embedder-Policy": "require-corp",
|
| 70 |
+
},
|
| 71 |
+
},
|
| 72 |
+
resolve: {
|
| 73 |
+
alias: { "@shared": path.join(repoRoot, "shared") },
|
| 74 |
+
},
|
| 75 |
+
optimizeDeps: { entries: ["scripts/wllama-bench/index.html"] },
|
| 76 |
+
});
|
| 77 |
+
await server.listen();
|
| 78 |
+
const pageUrl = new URL(
|
| 79 |
+
"scripts/wllama-bench/index.html",
|
| 80 |
+
server.resolvedUrls.local[0],
|
| 81 |
+
).href;
|
| 82 |
+
|
| 83 |
+
// A persistent profile keeps wllama's OPFS model cache between runs, so a
|
| 84 |
+
// model downloads once rather than on every invocation. Two runs at once
|
| 85 |
+
// need two profiles, since Chromium locks the one in use.
|
| 86 |
+
const browser = await chromium.launchPersistentContext(values.profile, {
|
| 87 |
+
headless: true,
|
| 88 |
+
executablePath: values.chrome,
|
| 89 |
+
args: ["--enable-unsafe-webgpu"],
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
const results = [];
|
| 93 |
+
let failures = 0;
|
| 94 |
+
|
| 95 |
+
for (const model of values.model) {
|
| 96 |
+
for (const device of devices) {
|
| 97 |
+
for (let run = 1; run <= runs; run++) {
|
| 98 |
+
const page = await browser.newPage();
|
| 99 |
+
const consoleLines = [];
|
| 100 |
+
page.on("console", (message) => {
|
| 101 |
+
consoleLines.push(message.text());
|
| 102 |
+
if (values.verbose) console.error(`[page] ${message.text()}`);
|
| 103 |
+
});
|
| 104 |
+
page.on("pageerror", (error) => consoleLines.push(error.message));
|
| 105 |
+
|
| 106 |
+
try {
|
| 107 |
+
await page.goto(pageUrl);
|
| 108 |
+
await page.waitForFunction(() => window.benchReady);
|
| 109 |
+
const result = await page.evaluate(
|
| 110 |
+
(options) => window.runBench(options),
|
| 111 |
+
{
|
| 112 |
+
model,
|
| 113 |
+
device,
|
| 114 |
+
cases,
|
| 115 |
+
threads: values.threads ? Number(values.threads) : undefined,
|
| 116 |
+
chatTemplateKwargs: values["template-kwargs"]
|
| 117 |
+
? JSON.parse(values["template-kwargs"])
|
| 118 |
+
: undefined,
|
| 119 |
+
caseTimeoutSeconds: Number(values["case-timeout"]),
|
| 120 |
+
systemPrompt: values["system-prompt"]
|
| 121 |
+
? readFileSync(values["system-prompt"], "utf8")
|
| 122 |
+
: undefined,
|
| 123 |
+
reasoningBudgetTokens: values["reasoning-budget"]
|
| 124 |
+
? Number(values["reasoning-budget"])
|
| 125 |
+
: undefined,
|
| 126 |
+
},
|
| 127 |
+
);
|
| 128 |
+
results.push({ ...result, run });
|
| 129 |
+
printResult(result, run);
|
| 130 |
+
} catch (error) {
|
| 131 |
+
failures++;
|
| 132 |
+
console.error(
|
| 133 |
+
`\n✗ ${model} on ${device}, run ${run}: ${error.message}`,
|
| 134 |
+
);
|
| 135 |
+
console.error(consoleLines.slice(-30).join("\n"));
|
| 136 |
+
} finally {
|
| 137 |
+
await page.close();
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
await browser.close();
|
| 144 |
+
await server.close();
|
| 145 |
+
|
| 146 |
+
if (values.json) writeFileSync(values.json, JSON.stringify(results, null, 2));
|
| 147 |
+
if (cases.some((c) => c.facts) && results.length) {
|
| 148 |
+
console.log("\nScore (see docs/wllama-model-evaluation.md):");
|
| 149 |
+
for (const { model, score, maximum } of scoreResults(cases, results)) {
|
| 150 |
+
console.log(` ${score.toFixed(1)}/${maximum} ${model}`);
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
process.exitCode = failures ? 1 : 0;
|
| 154 |
+
|
| 155 |
+
function printResult(result, run) {
|
| 156 |
+
const round = (value, digits = 1) =>
|
| 157 |
+
value === undefined ? "-" : Number(value.toFixed(digits));
|
| 158 |
+
console.log(
|
| 159 |
+
`\n${result.model} on ${result.device}, run ${run} (load ${round(result.loadSeconds)} s)`,
|
| 160 |
+
);
|
| 161 |
+
console.table(
|
| 162 |
+
Object.fromEntries(
|
| 163 |
+
result.cases.map((c) => [
|
| 164 |
+
c.name,
|
| 165 |
+
{
|
| 166 |
+
"prompt tok": c.promptTokens,
|
| 167 |
+
"prompt tok/s": round(c.promptTokensPerSecond),
|
| 168 |
+
"gen tok/s": round(c.generatedTokensPerSecond),
|
| 169 |
+
"thinking tok": c.thinkingTokens,
|
| 170 |
+
"answer tok": c.answerTokens,
|
| 171 |
+
"first answer s": round(c.secondsToFirstAnswerToken),
|
| 172 |
+
"total s": round(c.totalSeconds),
|
| 173 |
+
},
|
| 174 |
+
]),
|
| 175 |
+
),
|
| 176 |
+
);
|
| 177 |
+
for (const c of result.cases) {
|
| 178 |
+
console.log(` ${c.name}: ${JSON.stringify(c.answer.slice(0, 400))}`);
|
| 179 |
+
}
|
| 180 |
+
}
|
scripts/wllama-bench/score.mjs
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
// Scores bench answers against what the default system prompt asks for:
|
| 3 |
+
// answer from the results, in the question's language, citing each fact with
|
| 4 |
+
// a link to one of the results, never inventing a link. A case that lists
|
| 5 |
+
// `facts` (regular expressions) and a `language` is scored; one without them
|
| 6 |
+
// is only timed.
|
| 7 |
+
//
|
| 8 |
+
// node scripts/wllama-bench/score.mjs <cases.json> <results.json> [...]
|
| 9 |
+
//
|
| 10 |
+
// See docs/wllama-model-evaluation.md for the rules and the latest results.
|
| 11 |
+
|
| 12 |
+
import { readFileSync } from "node:fs";
|
| 13 |
+
|
| 14 |
+
const STOPWORDS = {
|
| 15 |
+
en: "the is was and of it to in by for are with",
|
| 16 |
+
pt: "é foi que da do uma ela para com não são em ao os as",
|
| 17 |
+
es: "es fue que del el la una los se en con las por",
|
| 18 |
+
de: "der die das und ist war wurde am im mit sie ein eine",
|
| 19 |
+
fr: "le la les est été et des du une il en pour par",
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
const SCRIPTS = {
|
| 23 |
+
han: /[一-鿿]/g,
|
| 24 |
+
kana: /[-ヿ]/g,
|
| 25 |
+
hangul: /[가-]/g,
|
| 26 |
+
arabic: /[-ۿ]/g,
|
| 27 |
+
devanagari: /[ऀ-ॿ]/g,
|
| 28 |
+
cyrillic: /[Ѐ-ӿ]/g,
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
/** Non-Latin scripts an answer in each language may use. */
|
| 32 |
+
const ALLOWED_SCRIPTS = {
|
| 33 |
+
zh: ["han"],
|
| 34 |
+
ja: ["han", "kana"],
|
| 35 |
+
ko: ["hangul", "han"],
|
| 36 |
+
ar: ["arabic"],
|
| 37 |
+
hi: ["devanagari"],
|
| 38 |
+
ru: ["cyrillic"],
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
const LINK = /\[([^\]]*)\]\(([^)\s]+)\)/g;
|
| 42 |
+
const URL = /https?:\/\/[^\s)\]>"']+/g;
|
| 43 |
+
// A result line echoed back the way the prompt lists them: `[title](url) | snippet`.
|
| 44 |
+
const ECHOED_RESULT = /\[[^\]]*\]\([^)]*\)\s*\|[^\n]*/g;
|
| 45 |
+
|
| 46 |
+
const count = (text, pattern) => (text.match(pattern) ?? []).length;
|
| 47 |
+
// Digits of each number with three or more of them, thousands separators
|
| 48 |
+
// dropped. A number converted to imperial units ("1,083 ft") is derived, not
|
| 49 |
+
// invented, so it is skipped.
|
| 50 |
+
const NUMBER =
|
| 51 |
+
/(\d{1,3}(?:[,.\u202f ]\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?)(\s*(?:(?:ft|feet|foot|miles?|mi)\b|英尺))?/g;
|
| 52 |
+
const digitsOf = (text) =>
|
| 53 |
+
[...text.matchAll(NUMBER)]
|
| 54 |
+
.filter(([, , imperialUnit]) => !imperialUnit)
|
| 55 |
+
.map(([, number]) => number.replace(/\D/g, ""))
|
| 56 |
+
.filter((digits) => digits.length >= 3);
|
| 57 |
+
|
| 58 |
+
function sourceTexts(spec) {
|
| 59 |
+
return [
|
| 60 |
+
spec.query,
|
| 61 |
+
// Titles and snippets; the URL is not text the answer can copy.
|
| 62 |
+
...spec.results.flatMap((result) => result.slice(0, 2)),
|
| 63 |
+
...Object.values(spec.pages ?? {}),
|
| 64 |
+
];
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
function detectLanguage(text) {
|
| 68 |
+
const plain = text.replace(LINK, " ").replace(URL, " ");
|
| 69 |
+
const scripts = Object.fromEntries(
|
| 70 |
+
Object.entries(SCRIPTS).map(([name, pattern]) => [
|
| 71 |
+
name,
|
| 72 |
+
count(plain, pattern),
|
| 73 |
+
]),
|
| 74 |
+
);
|
| 75 |
+
const latin = count(plain, /[A-Za-zÀ-ÿ]/g);
|
| 76 |
+
if (scripts.hangul >= 5) return "ko";
|
| 77 |
+
if (scripts.arabic >= 10) return "ar";
|
| 78 |
+
if (scripts.devanagari >= 10) return "hi";
|
| 79 |
+
if (scripts.kana >= 3) return "ja";
|
| 80 |
+
if (scripts.han >= 5 && scripts.han > latin / 4) return "zh";
|
| 81 |
+
if (scripts.cyrillic > latin) return "ru";
|
| 82 |
+
const words = plain.toLowerCase().match(/[a-zà-ÿ]+/g) ?? [];
|
| 83 |
+
let best = "?";
|
| 84 |
+
let bestHits = 0;
|
| 85 |
+
for (const [language, list] of Object.entries(STOPWORDS)) {
|
| 86 |
+
const stopwords = new Set(list.split(" "));
|
| 87 |
+
const hits = words.filter((word) => stopwords.has(word)).length;
|
| 88 |
+
if (hits > bestHits) [best, bestHits] = [language, hits];
|
| 89 |
+
}
|
| 90 |
+
return best;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* The language the model wrote in, ignoring what it copied from the
|
| 95 |
+
* results: a snippet quoted in the question's language must not pass for an
|
| 96 |
+
* answer written in it. When the copy is all there is, the copy decides,
|
| 97 |
+
* since reusing the sources' own words is fine in the question's language.
|
| 98 |
+
*/
|
| 99 |
+
function answerLanguage(answer, spec) {
|
| 100 |
+
let own = answer.replace(ECHOED_RESULT, " ");
|
| 101 |
+
for (const source of sourceTexts(spec).slice(1)) {
|
| 102 |
+
for (const fragment of source.split(/[.。!?!?,,;;::|]/)) {
|
| 103 |
+
if (fragment.trim().length >= 10)
|
| 104 |
+
own = own.replaceAll(fragment.trim(), " ");
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
const language = detectLanguage(own);
|
| 108 |
+
return language === "?"
|
| 109 |
+
? detectLanguage(answer.replace(ECHOED_RESULT, " "))
|
| 110 |
+
: language;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/** Sentences of the prompt that are instructions, not search results. */
|
| 114 |
+
function instructionSentences(prompt) {
|
| 115 |
+
return prompt
|
| 116 |
+
.split("\n")
|
| 117 |
+
.filter((line) => !/^\s*(•|>)/.test(line))
|
| 118 |
+
.join("\n")
|
| 119 |
+
.split(/(?<=[.!?:])\s+|\n+/)
|
| 120 |
+
.map((sentence) => sentence.trim())
|
| 121 |
+
.filter((sentence) => sentence.length >= 25);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function scoreCase(spec, answer, prompt = "", timedOut = false) {
|
| 125 |
+
const resultUrls = new Set(spec.results.map(([, , url]) => url));
|
| 126 |
+
const linkedUrls = [...answer.matchAll(LINK)].map(([, , url]) => url);
|
| 127 |
+
const allUrls = answer.match(URL) ?? [];
|
| 128 |
+
const trimUrl = (url) => url.replace(/[.,;:]+$/, "");
|
| 129 |
+
|
| 130 |
+
const facts =
|
| 131 |
+
spec.facts.filter((fact) => new RegExp(fact, "i").test(answer)).length /
|
| 132 |
+
spec.facts.length;
|
| 133 |
+
const language = answer.trim() ? answerLanguage(answer, spec) : "-";
|
| 134 |
+
// When no result answers the question there is nothing to cite, so saying
|
| 135 |
+
// so earns the citation point too.
|
| 136 |
+
const cited = spec.allowOwnKnowledge
|
| 137 |
+
? facts > 0
|
| 138 |
+
: linkedUrls.some((url) => resultUrls.has(trimUrl(url)));
|
| 139 |
+
|
| 140 |
+
const violations = timedOut ? ["timeout"] : [];
|
| 141 |
+
if (
|
| 142 |
+
(spec.forbidden ?? []).some((fact) => new RegExp(fact, "i").test(answer))
|
| 143 |
+
) {
|
| 144 |
+
violations.push("wrong-fact");
|
| 145 |
+
}
|
| 146 |
+
if (allUrls.some((url) => !resultUrls.has(trimUrl(url)))) {
|
| 147 |
+
violations.push("invented-link");
|
| 148 |
+
}
|
| 149 |
+
if (
|
| 150 |
+
instructionSentences(prompt).some((sentence) => answer.includes(sentence))
|
| 151 |
+
) {
|
| 152 |
+
violations.push("echoed-instructions");
|
| 153 |
+
}
|
| 154 |
+
const sentences = answer
|
| 155 |
+
.split(/[.!?。!?\n]+/)
|
| 156 |
+
.map((sentence) => sentence.trim().toLowerCase())
|
| 157 |
+
.filter((sentence) => sentence.length >= 20);
|
| 158 |
+
if (new Set(sentences).size < sentences.length) violations.push("repetition");
|
| 159 |
+
const plain = answer.replace(LINK, " ").replace(URL, " ");
|
| 160 |
+
const allowed = ALLOWED_SCRIPTS[spec.language] ?? [];
|
| 161 |
+
if (
|
| 162 |
+
Object.entries(SCRIPTS).some(
|
| 163 |
+
([name, pattern]) =>
|
| 164 |
+
!allowed.includes(name) && count(plain, pattern) >= 3,
|
| 165 |
+
)
|
| 166 |
+
) {
|
| 167 |
+
violations.push("foreign-script");
|
| 168 |
+
}
|
| 169 |
+
// Numbers the answer must compute (`allowNumbers`) are not invented, and a
|
| 170 |
+
// case whose results cannot answer accepts the model's own knowledge.
|
| 171 |
+
const sourceDigits = [
|
| 172 |
+
...sourceTexts(spec).flatMap(digitsOf),
|
| 173 |
+
...(spec.allowNumbers ?? []),
|
| 174 |
+
];
|
| 175 |
+
if (
|
| 176 |
+
!spec.allowOwnKnowledge &&
|
| 177 |
+
digitsOf(plain).some(
|
| 178 |
+
(digits) => !sourceDigits.some((source) => source.includes(digits)),
|
| 179 |
+
)
|
| 180 |
+
) {
|
| 181 |
+
violations.push("unsupported-number");
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
const points = Math.max(
|
| 185 |
+
0,
|
| 186 |
+
2 * facts +
|
| 187 |
+
(language === spec.language ? 1 : 0) +
|
| 188 |
+
(cited ? 1 : 0) -
|
| 189 |
+
violations.length,
|
| 190 |
+
);
|
| 191 |
+
return {
|
| 192 |
+
facts,
|
| 193 |
+
language,
|
| 194 |
+
cited,
|
| 195 |
+
violations,
|
| 196 |
+
points,
|
| 197 |
+
weight: caseWeight(spec),
|
| 198 |
+
};
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
/** English counts once and every other language twice: MiniSearch takes queries in any language. */
|
| 202 |
+
const caseWeight = (spec) => (spec.language === "en" ? 1 : 2);
|
| 203 |
+
const MAX_CASE_POINTS = 4;
|
| 204 |
+
|
| 205 |
+
/** Mean weighted score per model across its runs, highest first. */
|
| 206 |
+
export function scoreResults(cases, results) {
|
| 207 |
+
const specs = new Map(cases.filter((c) => c.facts).map((c) => [c.name, c]));
|
| 208 |
+
const maximum = [...specs.values()].reduce(
|
| 209 |
+
(sum, spec) => sum + caseWeight(spec) * MAX_CASE_POINTS,
|
| 210 |
+
0,
|
| 211 |
+
);
|
| 212 |
+
// The prompt depends on the case, not the model, so a result saved before
|
| 213 |
+
// prompts were recorded can borrow one from another run of the same case.
|
| 214 |
+
const prompts = new Map(
|
| 215 |
+
results.flatMap((r) =>
|
| 216 |
+
r.cases.filter((c) => c.prompt).map((c) => [c.name, c.prompt]),
|
| 217 |
+
),
|
| 218 |
+
);
|
| 219 |
+
const byModel = new Map();
|
| 220 |
+
for (const result of results) {
|
| 221 |
+
const runs = byModel.get(result.model) ?? [];
|
| 222 |
+
runs.push(
|
| 223 |
+
result.cases
|
| 224 |
+
.filter((c) => specs.has(c.name))
|
| 225 |
+
.map((c) => ({
|
| 226 |
+
name: c.name,
|
| 227 |
+
...scoreCase(
|
| 228 |
+
specs.get(c.name),
|
| 229 |
+
c.answer,
|
| 230 |
+
c.prompt ?? prompts.get(c.name),
|
| 231 |
+
c.timedOut,
|
| 232 |
+
),
|
| 233 |
+
})),
|
| 234 |
+
);
|
| 235 |
+
byModel.set(result.model, runs);
|
| 236 |
+
}
|
| 237 |
+
return [...byModel]
|
| 238 |
+
.map(([model, runs]) => ({
|
| 239 |
+
model,
|
| 240 |
+
runs,
|
| 241 |
+
score:
|
| 242 |
+
runs.reduce(
|
| 243 |
+
(sum, run) => sum + run.reduce((s, c) => s + c.points * c.weight, 0),
|
| 244 |
+
0,
|
| 245 |
+
) / runs.length,
|
| 246 |
+
maximum,
|
| 247 |
+
}))
|
| 248 |
+
.sort((a, b) => b.score - a.score);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
| 252 |
+
const [casesPath, ...resultPaths] = process.argv.slice(2);
|
| 253 |
+
const cases = JSON.parse(readFileSync(casesPath, "utf8"));
|
| 254 |
+
const results = resultPaths.flatMap((path) =>
|
| 255 |
+
JSON.parse(readFileSync(path, "utf8")),
|
| 256 |
+
);
|
| 257 |
+
for (const { model, runs, score, maximum } of scoreResults(cases, results)) {
|
| 258 |
+
const cells = runs[0]
|
| 259 |
+
.map((c) => {
|
| 260 |
+
const notes = runs.map((run) => {
|
| 261 |
+
const r = run.find((x) => x.name === c.name);
|
| 262 |
+
return `${r.points.toFixed(1)}${r.violations.length ? `!${r.violations.map((v) => v[0]).join("")}` : ""}`;
|
| 263 |
+
});
|
| 264 |
+
return `${c.name}=${notes.join(",")}`;
|
| 265 |
+
})
|
| 266 |
+
.join(" ");
|
| 267 |
+
console.log(
|
| 268 |
+
`${score.toFixed(1).padStart(5)}/${maximum} ${model.padEnd(28)} ${cells}`,
|
| 269 |
+
);
|
| 270 |
+
}
|
| 271 |
+
}
|
server/configEndpointServerHook.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { PreviewServer, ViteDevServer } from "vite";
|
|
| 2 |
import {
|
| 3 |
DEFAULT_INFERENCE_TYPE,
|
| 4 |
DEFAULT_INTERNAL_API_NAME,
|
|
|
|
| 5 |
DEFAULT_WLLAMA_MODEL_ID,
|
| 6 |
type ServerConfig,
|
| 7 |
} from "../shared/serverConfig.ts";
|
|
@@ -25,6 +26,10 @@ export function configEndpointServerHook<
|
|
| 25 |
accessKeyTimeoutHours: Number(process.env.ACCESS_KEY_TIMEOUT_HOURS) || 0,
|
| 26 |
wllamaDefaultModelId:
|
| 27 |
process.env.WLLAMA_DEFAULT_MODEL_ID || DEFAULT_WLLAMA_MODEL_ID,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
internalApiEnabled: Boolean(
|
| 29 |
process.env.INTERNAL_OPENAI_COMPATIBLE_API_BASE_URL,
|
| 30 |
),
|
|
|
|
| 2 |
import {
|
| 3 |
DEFAULT_INFERENCE_TYPE,
|
| 4 |
DEFAULT_INTERNAL_API_NAME,
|
| 5 |
+
DEFAULT_WLLAMA_GPU_MODEL_ID,
|
| 6 |
DEFAULT_WLLAMA_MODEL_ID,
|
| 7 |
type ServerConfig,
|
| 8 |
} from "../shared/serverConfig.ts";
|
|
|
|
| 26 |
accessKeyTimeoutHours: Number(process.env.ACCESS_KEY_TIMEOUT_HOURS) || 0,
|
| 27 |
wllamaDefaultModelId:
|
| 28 |
process.env.WLLAMA_DEFAULT_MODEL_ID || DEFAULT_WLLAMA_MODEL_ID,
|
| 29 |
+
// Not a fallback to WLLAMA_DEFAULT_MODEL_ID: `.env.example` sets that
|
| 30 |
+
// one, so most deployments would hand GPUs the CPU default.
|
| 31 |
+
wllamaDefaultGpuModelId:
|
| 32 |
+
process.env.WLLAMA_DEFAULT_GPU_MODEL_ID || DEFAULT_WLLAMA_GPU_MODEL_ID,
|
| 33 |
internalApiEnabled: Boolean(
|
| 34 |
process.env.INTERNAL_OPENAI_COMPATIBLE_API_BASE_URL,
|
| 35 |
),
|
shared/defaultSystemPrompt.ts
CHANGED
|
@@ -8,9 +8,16 @@
|
|
| 8 |
* The {{searchResults}} and {{currentDate}} placeholders are filled by
|
| 9 |
* client/modules/systemPrompt.ts.
|
| 10 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
export const DEFAULT_SYSTEM_PROMPT = `Answer the question using the search results below. Reply in the same language as the question.
|
| 12 |
|
| 13 |
-
Cite each fact with a Markdown link right after it, using the site's domain as the link text. Example:
|
| 14 |
|
| 15 |
If you answer from your own knowledge because the results do not cover it, say so.
|
| 16 |
|
|
|
|
| 8 |
* The {{searchResults}} and {{currentDate}} placeholders are filled by
|
| 9 |
* client/modules/systemPrompt.ts.
|
| 10 |
*/
|
| 11 |
+
/**
|
| 12 |
+
* The citation example inside the prompt, on a placeholder domain: the
|
| 13 |
+
* previous example, a real video link, was copied by small models as if it
|
| 14 |
+
* were one of the sources.
|
| 15 |
+
*/
|
| 16 |
+
export const CITATION_EXAMPLE = "[example.com](https://example.com/page)";
|
| 17 |
+
|
| 18 |
export const DEFAULT_SYSTEM_PROMPT = `Answer the question using the search results below. Reply in the same language as the question.
|
| 19 |
|
| 20 |
+
Cite each fact with a Markdown link right after it, using the site's domain as the link text. Example: ${CITATION_EXAMPLE}.
|
| 21 |
|
| 22 |
If you answer from your own knowledge because the results do not cover it, say so.
|
| 23 |
|
shared/serverConfig.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
export interface ServerConfig {
|
| 2 |
accessKeysEnabled: boolean;
|
| 3 |
accessKeyTimeoutHours: number;
|
|
|
|
| 4 |
wllamaDefaultModelId: string;
|
|
|
|
|
|
|
| 5 |
internalApiEnabled: boolean;
|
| 6 |
internalApiName: string;
|
| 7 |
defaultInferenceType: string;
|
|
@@ -15,5 +18,6 @@ export interface ServerConfig {
|
|
| 15 |
* response and the client-side fallback.
|
| 16 |
*/
|
| 17 |
export const DEFAULT_WLLAMA_MODEL_ID = "littlelamb-290m";
|
|
|
|
| 18 |
export const DEFAULT_INFERENCE_TYPE = "browser";
|
| 19 |
export const DEFAULT_INTERNAL_API_NAME = "Internal API";
|
|
|
|
| 1 |
export interface ServerConfig {
|
| 2 |
accessKeysEnabled: boolean;
|
| 3 |
accessKeyTimeoutHours: number;
|
| 4 |
+
/** Default Wllama model where the browser has no WebGPU, so it runs on the CPU. */
|
| 5 |
wllamaDefaultModelId: string;
|
| 6 |
+
/** Default Wllama model where the browser has WebGPU. */
|
| 7 |
+
wllamaDefaultGpuModelId: string;
|
| 8 |
internalApiEnabled: boolean;
|
| 9 |
internalApiName: string;
|
| 10 |
defaultInferenceType: string;
|
|
|
|
| 18 |
* response and the client-side fallback.
|
| 19 |
*/
|
| 20 |
export const DEFAULT_WLLAMA_MODEL_ID = "littlelamb-290m";
|
| 21 |
+
export const DEFAULT_WLLAMA_GPU_MODEL_ID = "gemma-3-4b";
|
| 22 |
export const DEFAULT_INFERENCE_TYPE = "browser";
|
| 23 |
export const DEFAULT_INTERNAL_API_NAME = "Internal API";
|