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:
parent
8a01751991
commit
02efca162e
|
@ -21,8 +21,13 @@ module DiscourseAi
|
||||||
private
|
private
|
||||||
|
|
||||||
def model_uri
|
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 =
|
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
|
api_url = @streaming_mode ? (api_url + "-with-response-stream") : api_url
|
||||||
|
|
||||||
|
@ -45,7 +50,7 @@ module DiscourseAi
|
||||||
)
|
)
|
||||||
|
|
||||||
Net::HTTP::Post
|
Net::HTTP::Post
|
||||||
.new(model_uri, headers)
|
.new(model_uri)
|
||||||
.tap do |r|
|
.tap do |r|
|
||||||
r.body = payload
|
r.body = payload
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
|
||||||
subject(:model) { described_class.new(model_name, DiscourseAi::Tokenizer::AnthropicTokenizer) }
|
subject(:model) { described_class.new(model_name, DiscourseAi::Tokenizer::AnthropicTokenizer) }
|
||||||
|
|
||||||
let(:model_name) { "claude-2" }
|
let(:model_name) { "claude-2" }
|
||||||
|
let(:bedrock_name) { "claude-v2" }
|
||||||
let(:prompt) { "Human: write 3 words\n\n" }
|
let(:prompt) { "Human: write 3 words\n\n" }
|
||||||
|
|
||||||
let(:request_body) { model.default_options.merge(prompt: prompt).to_json }
|
let(:request_body) { model.default_options.merge(prompt: prompt).to_json }
|
||||||
|
@ -66,7 +67,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
|
||||||
WebMock
|
WebMock
|
||||||
.stub_request(
|
.stub_request(
|
||||||
:post,
|
: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)
|
.with(body: request_body)
|
||||||
.to_return(status: 200, body: JSON.dump(response(response_text)))
|
.to_return(status: 200, body: JSON.dump(response(response_text)))
|
||||||
|
@ -112,7 +113,7 @@ RSpec.describe DiscourseAi::Completions::Endpoints::AwsBedrock do
|
||||||
WebMock
|
WebMock
|
||||||
.stub_request(
|
.stub_request(
|
||||||
:post,
|
: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)
|
.with(body: stream_request_body)
|
||||||
.to_return(status: 200, body: chunks)
|
.to_return(status: 200, body: chunks)
|
||||||
|
|
Loading…
Reference in New Issue