feat: Implement API key usage for EvalsTab LLM calls, enhance model filtering with provider aliases, and remove the random routing strategy option.

This commit is contained in:
diegosouzapw
2026-02-15 18:56:33 -03:00
parent 0ed7738c7c
commit fa9687ae0d
3 changed files with 26 additions and 8 deletions

View File

@@ -65,7 +65,8 @@ export default function HomePageClient({ machineId }) {
conn.testStatus === "unavailable")
).length;
const providerModels = models.filter((m) => m.provider === providerId);
const providerKeys = new Set([providerId, providerInfo.alias].filter(Boolean));
const providerModels = models.filter((m) => providerKeys.has(m.provider));
return {
id: providerId,
@@ -81,7 +82,10 @@ export default function HomePageClient({ machineId }) {
// Models for selected provider
const selectedProviderModels = useMemo(() => {
if (!selectedProvider) return [];
return models.filter((m) => m.provider === selectedProvider.id);
const providerKeys = new Set(
[selectedProvider.id, selectedProvider.provider?.alias].filter(Boolean)
);
return models.filter((m) => providerKeys.has(m.provider));
}, [selectedProvider, models]);
const quickStartLinks = [

View File

@@ -13,7 +13,6 @@ const STRATEGIES = [
},
{ value: "round-robin", label: "Round Robin", desc: "Cycle through all accounts", icon: "loop" },
{ value: "p2c", label: "P2C", desc: "Pick 2 random, use the healthier one", icon: "balance" },
{ value: "random", label: "Random", desc: "Pick a random account each request", icon: "shuffle" },
];
export default function RoutingTab() {
@@ -77,7 +76,7 @@ export default function RoutingTab() {
<h3 className="text-lg font-semibold">Routing Strategy</h3>
</div>
<div className="grid grid-cols-4 gap-2 mb-4">
<div className="grid grid-cols-3 gap-2 mb-4">
{STRATEGIES.map((s) => (
<button
key={s.value}
@@ -133,8 +132,6 @@ export default function RoutingTab() {
"Using accounts in priority order (Fill First)."}
{settings.fallbackStrategy === "p2c" &&
"Power of Two Choices: picks 2 random accounts and routes to the healthier one."}
{settings.fallbackStrategy === "random" &&
"Picks a random account for each request — simple uniform distribution."}
</p>
</Card>

View File

@@ -14,6 +14,7 @@ import { useNotificationStore } from "@/store/notificationStore";
export default function EvalsTab() {
const [suites, setSuites] = useState([]);
const [apiKey, setApiKey] = useState(null);
const [loading, setLoading] = useState(true);
const [running, setRunning] = useState(null);
const [progress, setProgress] = useState({ current: 0, total: 0 });
@@ -36,9 +37,22 @@ export default function EvalsTab() {
}
}, []);
const fetchApiKey = useCallback(async () => {
try {
const res = await fetch("/api/keys");
if (!res.ok) return;
const data = await res.json();
const firstKey = data?.keys?.[0]?.key || null;
setApiKey(firstKey);
} catch {
// silent
}
}, []);
useEffect(() => {
fetchSuites();
}, [fetchSuites]);
fetchApiKey();
}, [fetchSuites, fetchApiKey]);
/**
* Call the proxy LLM endpoint for a single eval case.
@@ -46,9 +60,12 @@ export default function EvalsTab() {
*/
const callLLM = async (evalCase) => {
try {
const headers = { "Content-Type": "application/json" };
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
const res = await fetch("/v1/chat/completions", {
method: "POST",
headers: { "Content-Type": "application/json" },
headers,
body: JSON.stringify({
model: evalCase.model || "gpt-4o",
messages: evalCase.input?.messages || [],