Skip to content

Commit 1f5b797

Browse files
authored
Remove prefixes for ids of aws inferences profiles (#945)
1 parent 9353b54 commit 1f5b797

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/langchain/llm/aws_bedrock.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def chat(params = {}, &block)
167167

168168
def parse_model_id(model_id)
169169
model_id
170-
.gsub("us.", "") # Meta append "us." to their model ids
170+
.gsub(/^(us|eu|apac|us-gov)\./, "") # Meta append "us." to their model ids, and AWS region prefixes are used by Bedrock cross-region model IDs.
171171
.split(".")
172172
end
173173

spec/langchain/llm/aws_bedrock_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,4 +605,36 @@
605605
end
606606
end
607607
end
608+
609+
describe "#parse_model_id" do
610+
it "strips the 'us.' prefix" do
611+
input = "us.anthropic.claude-3-5-sonnet-20240620-v1:0"
612+
result = subject.send(:parse_model_id, input)
613+
expect(result).to eq(["anthropic", "claude-3-5-sonnet-20240620-v1:0"])
614+
end
615+
616+
it "strips the 'eu.' prefix" do
617+
input = "eu.anthropic.claude-3-5-sonnet-20240620-v1:0"
618+
result = subject.send(:parse_model_id, input)
619+
expect(result).to eq(["anthropic", "claude-3-5-sonnet-20240620-v1:0"])
620+
end
621+
622+
it "strips the 'apac.' prefix" do
623+
input = "apac.anthropic.claude-3-5-sonnet-20240620-v1:0"
624+
result = subject.send(:parse_model_id, input)
625+
expect(result).to eq(["anthropic", "claude-3-5-sonnet-20240620-v1:0"])
626+
end
627+
628+
it "strips the 'us-gov.' prefix" do
629+
input = "us-gov.anthropic.claude-3-5-sonnet-20240620-v1:0"
630+
result = subject.send(:parse_model_id, input)
631+
expect(result).to eq(["anthropic", "claude-3-5-sonnet-20240620-v1:0"])
632+
end
633+
634+
it "returns the correct output when no region prefix is present" do
635+
input = "anthropic.claude-3-5-sonnet-20240620-v1:0"
636+
result = subject.send(:parse_model_id, input)
637+
expect(result).to eq(["anthropic", "claude-3-5-sonnet-20240620-v1:0"])
638+
end
639+
end
608640
end

0 commit comments

Comments
 (0)