-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Meta models support for AWS Bedrock LLM (#764)
* Update aws_bedrock.rb * Revert "Update aws_bedrock.rb" This reverts commit 34ac330. * Add Aws Bedrock Meta support * Update complete.json * Fix bedrock renaming of response * Fix specs
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module Langchain::LLM | ||
class AwsBedrockMetaResponse < BaseResponse | ||
def completion | ||
completions.first | ||
end | ||
|
||
def completions | ||
[raw_response.dig("generation")] | ||
end | ||
|
||
def stop_reason | ||
raw_response.dig("stop_reason") | ||
end | ||
|
||
def prompt_tokens | ||
raw_response.dig("prompt_token_count").to_i | ||
end | ||
|
||
def completion_tokens | ||
raw_response.dig("generation_token_count").to_i | ||
end | ||
|
||
def total_tokens | ||
prompt_tokens + completion_tokens | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"generation": "The sky has no definitive", | ||
"prompt_token_count": 792, | ||
"generation_token_count": 300, | ||
"stop_reason": "length" | ||
} |
15 changes: 15 additions & 0 deletions
15
spec/langchain/llm/response/aws_bedrock_meta_response_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Langchain::LLM::AwsBedrockMetaResponse do | ||
let(:raw_chat_completions_response) { | ||
JSON.parse File.read("spec/fixtures/llm/aws_bedrock_meta/complete.json") | ||
} | ||
|
||
subject { described_class.new(raw_chat_completions_response) } | ||
|
||
describe "#complete" do | ||
it "returns completion" do | ||
expect(subject.completion).to eq("The sky has no definitive") | ||
end | ||
end | ||
end |