FIX: Bedrock uses slightly different model names

* Revert "FIX: We don't need to prepend anthropic. to bedrock models (#308)"

This reverts commit 8a01751991.

* FIX: Bedrock uses slightly different model names
This commit is contained in:
Roman Rizzi 2023-11-23 15:49:24 -03:00 committed by GitHub
parent 8a01751991
commit 02efca162e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -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

View File

@ -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)