fix(ai): normalize Bedrock model names for profiles
This commit is contained in:
@@ -481,17 +481,17 @@ function handleContentBlockStop(
|
|||||||
* Checks both model ID and model name to support application inference profiles
|
* Checks both model ID and model name to support application inference profiles
|
||||||
* whose ARNs don't contain the model name.
|
* whose ARNs don't contain the model name.
|
||||||
*/
|
*/
|
||||||
|
function getModelMatchCandidates(modelId: string, modelName?: string): string[] {
|
||||||
|
const values = modelName ? [modelId, modelName] : [modelId];
|
||||||
|
return values.flatMap((value) => {
|
||||||
|
const lower = value.toLowerCase();
|
||||||
|
return [lower, lower.replace(/[\s_.:]+/g, "-")];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function supportsAdaptiveThinking(modelId: string, modelName?: string): boolean {
|
function supportsAdaptiveThinking(modelId: string, modelName?: string): boolean {
|
||||||
const candidates = modelName ? [modelId, modelName] : [modelId];
|
const candidates = getModelMatchCandidates(modelId, modelName);
|
||||||
return candidates.some(
|
return candidates.some((s) => s.includes("opus-4-6") || s.includes("opus-4-7") || s.includes("sonnet-4-6"));
|
||||||
(s) =>
|
|
||||||
s.includes("opus-4-6") ||
|
|
||||||
s.includes("opus-4.6") ||
|
|
||||||
s.includes("opus-4-7") ||
|
|
||||||
s.includes("opus-4.7") ||
|
|
||||||
s.includes("sonnet-4-6") ||
|
|
||||||
s.includes("sonnet-4.6"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapThinkingLevelToEffort(
|
function mapThinkingLevelToEffort(
|
||||||
@@ -499,7 +499,7 @@ function mapThinkingLevelToEffort(
|
|||||||
modelId: string,
|
modelId: string,
|
||||||
modelName?: string,
|
modelName?: string,
|
||||||
): "low" | "medium" | "high" | "xhigh" | "max" {
|
): "low" | "medium" | "high" | "xhigh" | "max" {
|
||||||
const candidates = modelName ? [modelId, modelName] : [modelId];
|
const candidates = getModelMatchCandidates(modelId, modelName);
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case "minimal":
|
case "minimal":
|
||||||
case "low":
|
case "low":
|
||||||
@@ -509,10 +509,10 @@ function mapThinkingLevelToEffort(
|
|||||||
case "high":
|
case "high":
|
||||||
return "high";
|
return "high";
|
||||||
case "xhigh":
|
case "xhigh":
|
||||||
if (candidates.some((s) => s.includes("opus-4-6") || s.includes("opus-4.6"))) {
|
if (candidates.some((s) => s.includes("opus-4-6"))) {
|
||||||
return "max";
|
return "max";
|
||||||
}
|
}
|
||||||
if (candidates.some((s) => s.includes("opus-4-7") || s.includes("opus-4.7"))) {
|
if (candidates.some((s) => s.includes("opus-4-7"))) {
|
||||||
return "xhigh";
|
return "xhigh";
|
||||||
}
|
}
|
||||||
return "high";
|
return "high";
|
||||||
@@ -565,10 +565,7 @@ function isAnthropicClaudeModel(model: Model<"bedrock-converse-stream">): boolea
|
|||||||
* Amazon Nova models have automatic caching and don't need explicit cache points.
|
* Amazon Nova models have automatic caching and don't need explicit cache points.
|
||||||
*/
|
*/
|
||||||
function supportsPromptCaching(model: Model<"bedrock-converse-stream">): boolean {
|
function supportsPromptCaching(model: Model<"bedrock-converse-stream">): boolean {
|
||||||
const candidates = [model.id.toLowerCase()];
|
const candidates = getModelMatchCandidates(model.id, model.name);
|
||||||
if (model.name) {
|
|
||||||
candidates.push(model.name.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasClaudeRef = candidates.some((s) => s.includes("claude"));
|
const hasClaudeRef = candidates.some((s) => s.includes("claude"));
|
||||||
if (!hasClaudeRef) {
|
if (!hasClaudeRef) {
|
||||||
@@ -578,7 +575,7 @@ function supportsPromptCaching(model: Model<"bedrock-converse-stream">): boolean
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Claude 4.x models (opus-4, sonnet-4, haiku-4)
|
// Claude 4.x models (opus-4, sonnet-4, haiku-4)
|
||||||
if (candidates.some((s) => s.includes("-4-") || s.includes("-4."))) return true;
|
if (candidates.some((s) => s.includes("-4-"))) return true;
|
||||||
// Claude 3.7 Sonnet
|
// Claude 3.7 Sonnet
|
||||||
if (candidates.some((s) => s.includes("claude-3-7-sonnet"))) return true;
|
if (candidates.some((s) => s.includes("claude-3-7-sonnet"))) return true;
|
||||||
// Claude 3.5 Haiku
|
// Claude 3.5 Haiku
|
||||||
|
|||||||
Reference in New Issue
Block a user