From 02efca162ee7adc48fc9d42c11a24269660b979d Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Thu, 23 Nov 2023 15:49:24 -0300 Subject: [PATCH] FIX: Bedrock uses slightly different model names * Revert "FIX: We don't need to prepend anthropic. to bedrock models (#308)" This reverts commit 8a01751991178f7636030eb99e7f75c035707ffd. * FIX: Bedrock uses slightly different model names --- lib/completions/endpoints/aws_bedrock.rb | 9 +++++++-- spec/lib/completions/endpoints/aws_bedrock_spec.rb | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/completions/endpoints/aws_bedrock.rb b/lib/completions/endpoints/aws_bedrock.rb index 4fb3ae27..aadeb401 100644 --- a/lib/completions/endpoints/aws_bedrock.rb +++ b/lib/completions/endpoints/aws_bedrock.rb @@ -21,8 +21,13 @@ module DiscourseAi private def model_uri + # Bedrock uses slightly different names + bedrock_model_id = model.split("-") + bedrock_model_id[-1] = "v#{bedrock_model_id.last}" + bedrock_model_id = bedrock_model_id.join("-") + api_url = - "https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/#{model}/invoke" + "https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/anthropic.#{bedrock_model_id}/invoke" api_url = @streaming_mode ? (api_url + "-with-response-stream") : api_url @@ -45,7 +50,7 @@ module DiscourseAi ) Net::HTTP::Post - .new(model_uri, headers) + .new(model_uri) .tap do |r| r.body = payload diff --git a/spec/lib/completions/endpoints/aws_bedrock_spec.rb b/spec/lib/completions/endpoints/aws_bedrock_spec.rb index f637b9ad..c0938709 100644 --- a/spec/lib/completions/endpoints/aws_bedrock_spec.rb +++ b/spec/lib/completions/endpoints/aws_bedrock_spec.rb @@ -6,6 +6,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do subject(:model) { described_class.new(model_name, DiscourseAi::Tokenizer::AnthropicTokenizer) } let(:model_name) { "claude-2" } + let(:bedrock_name) { "claude-v2" } let(:prompt) { "Human: write 3 words\n\n" } let(:request_body) { model.default_options.merge(prompt: prompt).to_json } @@ -66,7 +67,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do WebMock .stub_request( :post, - "https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/#{model_name}/invoke", + "https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/anthropic.#{bedrock_name}/invoke", ) .with(body: request_body) .to_return(status: 200, body: JSON.dump(response(response_text))) @@ -112,7 +113,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do WebMock .stub_request( :post, - "https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/#{model_name}/invoke-with-response-stream", + "https://bedrock-runtime.#{SiteSetting.ai_bedrock_region}.amazonaws.com/model/anthropic.#{bedrock_name}/invoke-with-response-stream", ) .with(body: stream_request_body) .to_return(status: 200, body: chunks)