-
Notifications
You must be signed in to change notification settings - Fork 446
Expand file tree
/
Copy pathmodel-selection.ts
More file actions
43 lines (38 loc) · 1.52 KB
/
model-selection.ts
File metadata and controls
43 lines (38 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { AgentModelSelection } from "@open-harness/agent";
import { resolveAvailableModelId } from "@/lib/model-availability";
import { type ModelVariant, resolveModelSelection } from "@/lib/model-variants";
import { DEFAULT_MODEL_ID } from "@/lib/models";
interface ResolveChatModelSelectionParams {
selectedModelId: string | null | undefined;
modelVariants: ModelVariant[];
missingVariantLabel: string;
}
export function resolveChatModelSelection({
selectedModelId,
modelVariants,
missingVariantLabel,
}: ResolveChatModelSelectionParams): AgentModelSelection {
const requestedModelId = selectedModelId ?? DEFAULT_MODEL_ID;
const selection = resolveModelSelection(requestedModelId, modelVariants);
if (selection.isMissingVariant) {
console.warn(
`${missingVariantLabel} "${requestedModelId}" was not found. Falling back to default model.`,
);
return { id: DEFAULT_MODEL_ID as AgentModelSelection["id"] };
}
const availableModelId = resolveAvailableModelId(selection.resolvedModelId);
if (availableModelId !== selection.resolvedModelId) {
console.warn(
`${missingVariantLabel} "${requestedModelId}" resolves to disabled model "${selection.resolvedModelId}". Falling back to default model.`,
);
return { id: DEFAULT_MODEL_ID as AgentModelSelection["id"] };
}
return {
id: availableModelId as AgentModelSelection["id"],
...(selection.providerOptionsByProvider
? {
providerOptionsOverrides: selection.providerOptionsByProvider,
}
: {}),
};
}