mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 23:24:30 +00:00
refactor(models): share param-B inference
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
|||||||
type Tool,
|
type Tool,
|
||||||
} from "@mariozechner/pi-ai";
|
} from "@mariozechner/pi-ai";
|
||||||
import { Type } from "@sinclair/typebox";
|
import { Type } from "@sinclair/typebox";
|
||||||
|
import { inferParamBFromIdOrName } from "../shared/model-param-b.js";
|
||||||
|
|
||||||
const OPENROUTER_MODELS_URL = "https://openrouter.ai/api/v1/models";
|
const OPENROUTER_MODELS_URL = "https://openrouter.ai/api/v1/models";
|
||||||
const DEFAULT_TIMEOUT_MS = 12_000;
|
const DEFAULT_TIMEOUT_MS = 12_000;
|
||||||
@@ -97,26 +98,6 @@ function normalizeCreatedAtMs(value: unknown): number | null {
|
|||||||
return Math.round(value * 1000);
|
return Math.round(value * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function inferParamBFromIdOrName(text: string): number | null {
|
|
||||||
const raw = text.toLowerCase();
|
|
||||||
const matches = raw.matchAll(/(?:^|[^a-z0-9])[a-z]?(\d+(?:\.\d+)?)b(?:[^a-z0-9]|$)/g);
|
|
||||||
let best: number | null = null;
|
|
||||||
for (const match of matches) {
|
|
||||||
const numRaw = match[1];
|
|
||||||
if (!numRaw) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const value = Number(numRaw);
|
|
||||||
if (!Number.isFinite(value) || value <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (best === null || value > best) {
|
|
||||||
best = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return best;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseModality(modality: string | null): Array<"text" | "image"> {
|
function parseModality(modality: string | null): Array<"text" | "image"> {
|
||||||
if (!modality) {
|
if (!modality) {
|
||||||
return ["text"];
|
return ["text"];
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { resolveBrowserConfig } from "../browser/config.js";
|
|||||||
import { formatCliCommand } from "../cli/command-format.js";
|
import { formatCliCommand } from "../cli/command-format.js";
|
||||||
import { resolveGatewayAuth } from "../gateway/auth.js";
|
import { resolveGatewayAuth } from "../gateway/auth.js";
|
||||||
import { resolveNodeCommandAllowlist } from "../gateway/node-command-policy.js";
|
import { resolveNodeCommandAllowlist } from "../gateway/node-command-policy.js";
|
||||||
|
import { inferParamBFromIdOrName } from "../shared/model-param-b.js";
|
||||||
|
|
||||||
export type SecurityAuditFinding = {
|
export type SecurityAuditFinding = {
|
||||||
checkId: string;
|
checkId: string;
|
||||||
@@ -142,26 +143,6 @@ const WEAK_TIER_MODEL_PATTERNS: Array<{ id: string; re: RegExp; label: string }>
|
|||||||
{ id: "anthropic.haiku", re: /\bhaiku\b/i, label: "Haiku tier (smaller model)" },
|
{ id: "anthropic.haiku", re: /\bhaiku\b/i, label: "Haiku tier (smaller model)" },
|
||||||
];
|
];
|
||||||
|
|
||||||
function inferParamBFromIdOrName(text: string): number | null {
|
|
||||||
const raw = text.toLowerCase();
|
|
||||||
const matches = raw.matchAll(/(?:^|[^a-z0-9])[a-z]?(\d+(?:\.\d+)?)b(?:[^a-z0-9]|$)/g);
|
|
||||||
let best: number | null = null;
|
|
||||||
for (const match of matches) {
|
|
||||||
const numRaw = match[1];
|
|
||||||
if (!numRaw) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const value = Number(numRaw);
|
|
||||||
if (!Number.isFinite(value) || value <= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (best === null || value > best) {
|
|
||||||
best = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return best;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isGptModel(id: string): boolean {
|
function isGptModel(id: string): boolean {
|
||||||
return /\bgpt-/i.test(id);
|
return /\bgpt-/i.test(id);
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/shared/model-param-b.ts
Normal file
19
src/shared/model-param-b.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
export function inferParamBFromIdOrName(text: string): number | null {
|
||||||
|
const raw = text.toLowerCase();
|
||||||
|
const matches = raw.matchAll(/(?:^|[^a-z0-9])[a-z]?(\d+(?:\.\d+)?)b(?:[^a-z0-9]|$)/g);
|
||||||
|
let best: number | null = null;
|
||||||
|
for (const match of matches) {
|
||||||
|
const numRaw = match[1];
|
||||||
|
if (!numRaw) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const value = Number(numRaw);
|
||||||
|
if (!Number.isFinite(value) || value <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (best === null || value > best) {
|
||||||
|
best = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user