Docs: Update benchmark for moonshotai/kimi-k2-thinking

This commit is contained in:
github-actions[bot]
2025-11-15 00:13:33 +00:00
parent da087e9ca0
commit 0d5effb238
10 changed files with 176 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
async function findShortestPath(graph, start, end) {
let PriorityQueue;
try {
const mod = await import('https://esm.sh/js-priority-queue@1.0.0');
PriorityQueue = mod.default || mod;
} catch {
throw new Error('Failed to load priority queue library');
}
if (!(start in graph) || !(end in graph)) return Infinity;
if (start === end) return 0;
const dist = { [start]: 0 };
const pq = new PriorityQueue({
comparator: (a, b) => a[1] - b[1],
initialValues: [[start, 0]]
});
while (pq.length) {
const [node, d] = pq.dequeue();
if (node === end) return d;
if (d > (dist[node] ?? Infinity)) continue;
for (const [neighbor, weight] of Object.entries(graph[node])) {
const newDist = d + weight;
if (newDist < (dist[neighbor] ?? Infinity)) {
dist[neighbor] = newDist;
pq.queue([neighbor, newDist]);
}
}
}
return Infinity;
}
export default findShortestPath;

View File

@@ -0,0 +1,24 @@
async function findConvexHull(points) {
const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4/esm/lodash.js');
if (!points || points.length < 3) return [...(points || [])];
const pts = _.sortBy(_.uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']);
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const build = arr => {
const h = [];
for (const p of arr) {
while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop();
h.push(p);
}
return h;
};
const lower = build(pts);
const upper = build([...pts].reverse());
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
}
export default findConvexHull;

View File

@@ -0,0 +1,7 @@
async function findLISLength(nums){
const{bisectLeft}=await import('https://cdn.skypack.dev/d3-array');
const tails=[];
for(const n of nums)tails[bisectLeft(tails,n)]=n;
return tails.length;
}
export default findLISLength;

View File

@@ -0,0 +1,8 @@
let math;
async function calculateDeterminant(m) {
const n = m?.length;
if (!n || m.some(r => !Array.isArray(r) || r.length !== n)) throw new Error('Invalid matrix');
math ||= await import('https://cdn.jsdelivr.net/npm/mathjs@11.11.0/+esm');
return math.det(m);
}
export default calculateDeterminant;

View File

@@ -0,0 +1,9 @@
const parseMarkdown = async m => {
try {
const {marked} = await import('https://esm.sh/marked');
return marked.parse(m);
} catch (e) {
return `<pre>${e.message}</pre>`;
}
};
export default parseMarkdown;

View File

@@ -0,0 +1,19 @@
async function processCSV(csv, cfg) {
const [{ default: Papa }, { default: _ }] = await Promise.all([
import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'),
import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm')
]);
const filtered = Papa.parse(csv, { header: true, dynamicTyping: true }).data
.filter(r => r[cfg.filterColumn] == cfg.filterValue);
return Object.entries(_.groupBy(filtered, cfg.groupBy)).map(([k, v]) => {
const sum = v.reduce((s, r) => s + (Number(r[cfg.aggregateColumn]) || 0), 0);
return {
[cfg.groupBy]: k,
result: cfg.operation === 'count' ? v.length :
cfg.operation === 'avg' ? sum / v.length : sum
};
});
}
export default processCSV;

View File

@@ -0,0 +1,37 @@
export async function findAvailableSlots(a, b, { durationMinutes: d, searchRange: r, workHours: h }) {
const { parseISO, addMinutes, isWithinInterval, compareAsc, startOfDay, setHours, setMinutes } = await import('https://esm.sh/date-fns');
const toDate = (s) => parseISO(s);
const all = [...a, ...b].map(({ start: s, end: e }) => ({ s: toDate(s), e: toDate(e) }));
all.sort((a, b) => compareAsc(a.s, b.s));
const busy = [];
for (const i of all) {
if (!busy.length || compareAsc(i.s, busy.at(-1).e) > 0) busy.push({ s: i.s, e: i.e });
else if (compareAsc(i.e, busy.at(-1).e) > 0) busy.at(-1).e = i.e;
}
const range = { s: toDate(r.start), e: toDate(r.end) };
const [[sh, sm], [eh, em]] = [h.start, h.end].map(t => t.split(':').map(Number));
const slots = [];
let cur = range.s;
while (compareAsc(cur, range.e) < 0) {
const end = addMinutes(cur, d);
if (compareAsc(end, range.e) > 0) break;
const day = startOfDay(cur);
const work = { s: setHours(setMinutes(day, sm), sh), e: setHours(setMinutes(day, em), eh) };
const inWork = isWithinInterval(cur, work) && isWithinInterval(end, work);
const isFree = !busy.some(b => compareAsc(cur, b.e) < 0 && compareAsc(end, b.s) > 0);
if (inWork && isFree) slots.push({ start: cur.toISOString(), end: end.toISOString() });
cur = end;
}
return slots;
}
export default findAvailableSlots;

View File

@@ -0,0 +1,17 @@
const cache = new WeakMap();
let ajv;
async function validateJSON(json, schema) {
try {
if (!ajv) {
const { default: Ajv } = await import('https://cdn.jsdelivr.net/npm/ajv@8/dist/ajv.mjs');
ajv = new Ajv({ allErrors: true, strict: false });
}
const validator = cache.get(schema) || (cache.set(schema, ajv.compile(schema)), cache.get(schema));
const valid = validator(json);
return { valid, errors: valid ? [] : validator.errors.map(e => `${e.instancePath} ${e.message}`.trim()) };
} catch (error) {
return { valid: false, errors: [error.message] };
}
}
export default validateJSON;

View File

@@ -0,0 +1,9 @@
export async function createStreamVisualizer(i,o){
const d=await import('d3'),{maxPoints:m,alpha:a,width:w,height:h,yDomain:y}=o,p=[],c=d.scaleLinear,f=d.line;
let e;
for await(const{timestamp:t,value:v}of i){e=e===undefined?v:a*v+(1-a)*e;p.push({timestamp:t,value:v,ema:e});p.length>m&&p.shift()}
if(!p.length)return{data:[],path:''};
const x=c().domain([p[0].timestamp,p.at(-1).timestamp]).range([0,w]),z=c().domain(y).range([h,0]),g=f().x(d=>x(d.timestamp)).y(d=>z(d.ema)).curve(d.curveLinear);
return{data:p,path:g(p)}
}
export default createStreamVisualizer;