ruby-amazon-bedrock 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +57 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +28 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.txt +21 -0
- data/README.md +329 -0
- data/Rakefile +12 -0
- data/bin/console +12 -0
- data/bin/setup +8 -0
- data/lib/bedrock/version.rb +9 -0
- data/lib/bedrock.rb +10 -0
- data/lib/bedrock_runtime/client.rb +41 -0
- data/lib/bedrock_runtime/payload_builders/ai_21_labs/base.rb +55 -0
- data/lib/bedrock_runtime/payload_builders/ai_21_labs/j2_mid_v1.rb +22 -0
- data/lib/bedrock_runtime/payload_builders/ai_21_labs/j2_ultra_v1.rb +22 -0
- data/lib/bedrock_runtime/payload_builders/amazon/base.rb +51 -0
- data/lib/bedrock_runtime/payload_builders/amazon/titan_image_generator_v1.rb +45 -0
- data/lib/bedrock_runtime/payload_builders/amazon/titan_text_express_v1.rb +23 -0
- data/lib/bedrock_runtime/payload_builders/amazon/titan_text_lite_v1.rb +31 -0
- data/lib/bedrock_runtime/payload_builders/anthropic/base.rb +55 -0
- data/lib/bedrock_runtime/payload_builders/anthropic/claude_instant_v1.rb +21 -0
- data/lib/bedrock_runtime/payload_builders/anthropic/claude_v1.rb +23 -0
- data/lib/bedrock_runtime/payload_builders/anthropic/claude_v2.rb +21 -0
- data/lib/bedrock_runtime/payload_builders/base.rb +33 -0
- data/lib/bedrock_runtime/payload_builders/cohere/command_base.rb +46 -0
- data/lib/bedrock_runtime/payload_builders/cohere/command_light_text_v14.rb +23 -0
- data/lib/bedrock_runtime/payload_builders/cohere/command_text_v14.rb +21 -0
- data/lib/bedrock_runtime/payload_builders/cohere/embed_base.rb +41 -0
- data/lib/bedrock_runtime/payload_builders/cohere/embed_english_v3.rb +23 -0
- data/lib/bedrock_runtime/payload_builders/cohere/embed_multilingual_v3.rb +21 -0
- data/lib/bedrock_runtime/payload_builders/meta/base.rb +45 -0
- data/lib/bedrock_runtime/payload_builders/meta/llama213b_chat_v1.rb +23 -0
- data/lib/bedrock_runtime/payload_builders/meta/llama270b_chat_v1.rb +21 -0
- data/lib/bedrock_runtime/payload_builders/stability_ai/base.rb +48 -0
- data/lib/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v0.rb +23 -0
- data/lib/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v1.rb +23 -0
- data/lib/bedrock_runtime/payload_factory.rb +72 -0
- data/ruby-amazon-bedrock.gemspec +39 -0
- data/sig/ruby/amazon/bedrock.rbs +8 -0
- data/spec/bedrock_runtime/client_spec.rb +51 -0
- data/spec/bedrock_runtime/payload_builders/ai_21_labs/base_spec.rb +32 -0
- data/spec/bedrock_runtime/payload_builders/ai_21_labs/j2_mid_v1_spec.rb +33 -0
- data/spec/bedrock_runtime/payload_builders/ai_21_labs/j2_ultra_v1_spec.rb +33 -0
- data/spec/bedrock_runtime/payload_builders/amazon/base_spec.rb +31 -0
- data/spec/bedrock_runtime/payload_builders/amazon/titan_image_generator_v1_spec.rb +38 -0
- data/spec/bedrock_runtime/payload_builders/amazon/titan_text_express_v1_spec.rb +32 -0
- data/spec/bedrock_runtime/payload_builders/amazon/titan_text_lite_v1_spec.rb +32 -0
- data/spec/bedrock_runtime/payload_builders/anthropic/base_spec.rb +33 -0
- data/spec/bedrock_runtime/payload_builders/anthropic/claude_instant_v1_spec.rb +34 -0
- data/spec/bedrock_runtime/payload_builders/anthropic/claude_v1_spec.rb +34 -0
- data/spec/bedrock_runtime/payload_builders/anthropic/claude_v2_spec.rb +34 -0
- data/spec/bedrock_runtime/payload_builders/base_spec.rb +34 -0
- data/spec/bedrock_runtime/payload_builders/cohere/command_base_spec.rb +27 -0
- data/spec/bedrock_runtime/payload_builders/cohere/command_light_text_v14_spec.rb +28 -0
- data/spec/bedrock_runtime/payload_builders/cohere/command_text_v14_spec.rb +28 -0
- data/spec/bedrock_runtime/payload_builders/cohere/embed_base_spec.rb +26 -0
- data/spec/bedrock_runtime/payload_builders/cohere/embed_english_v3_spec.rb +27 -0
- data/spec/bedrock_runtime/payload_builders/cohere/embed_multilingual_v3_spec.rb +27 -0
- data/spec/bedrock_runtime/payload_builders/meta/base_spec.rb +28 -0
- data/spec/bedrock_runtime/payload_builders/meta/llama213b_chat_v1_spec.rb +29 -0
- data/spec/bedrock_runtime/payload_builders/meta/llama270b_chat_v1_spec.rb +29 -0
- data/spec/bedrock_runtime/payload_builders/stability_ai/base_spec.rb +30 -0
- data/spec/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v0_spec.rb +31 -0
- data/spec/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v1_spec.rb +31 -0
- data/spec/bedrock_runtime/payload_factory_spec.rb +56 -0
- data/spec/bedrock_spec.rb +7 -0
- data/spec/cassettes/models/amazon_titan-text-express-v1.yml +59 -0
- data/spec/cassettes/models/amazon_titan-text-lite-v1.yml +54 -0
- data/spec/cassettes/models/anthropic_claude-instant-v1.yml +62 -0
- data/spec/cassettes/models/anthropic_claude-v1.yml +61 -0
- data/spec/cassettes/models/anthropic_claude-v2.yml +59 -0
- data/spec/cassettes/models/cohere_command-light-text-v14.yml +54 -0
- data/spec/cassettes/models/cohere_command-text-v14.yml +55 -0
- data/spec/cassettes/models/cohere_embed-english-v3.yml +47 -0
- data/spec/cassettes/models/cohere_embed-multilingual-v3.yml +47 -0
- data/spec/cassettes/models/errors/bad_request.yml +45 -0
- data/spec/cassettes/models/errors/not_found.yml +45 -0
- data/spec/cassettes/models/meta_llama2-13b-chat-v1.yml +73 -0
- data/spec/cassettes/models/meta_llama2-70b-chat-v1.yml +55 -0
- data/spec/cassettes/models/stability_stable-diffusion-xl-v0.yml +51 -0
- data/spec/cassettes/models/stability_stable-diffusion-xl-v1.yml +45 -0
- data/spec/spec_helper.rb +29 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1c8f8ffaf1d4ab3dfb6f3d9bea9ff268083fa6d3ec28b4a57fa0f72ece9a4332
|
4
|
+
data.tar.gz: 85f389809a582617cf3aeeb6c3192b441065543528976abfd04a53c71dc881db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3a25aeed7e53880b7d928ab8f0a9a880036ef0d3d9c60374e62e9151f5027e8b7222abce410880c8a6776b0641da9e17ee330193d159f5cc130d5111a0f4f92
|
7
|
+
data.tar.gz: 238acca742747349d8f3a15ae376a89d63d0eb69355625abd2f556e28c629a20c4f32aa263004b5f19c38bcc44cdf7854f871094148f4efbc96c8e4a0f7f8ff5
|
@@ -0,0 +1,57 @@
|
|
1
|
+
version: 2.1 # Use 2.1 to enable using orbs and other features.
|
2
|
+
|
3
|
+
# Declare the orbs that we'll use in our config.
|
4
|
+
orbs:
|
5
|
+
ruby: circleci/ruby@1.0
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
rubocop:
|
9
|
+
parallelism: 1
|
10
|
+
docker:
|
11
|
+
- image: cimg/ruby:3.1-node
|
12
|
+
steps:
|
13
|
+
- checkout
|
14
|
+
- ruby/install-deps
|
15
|
+
- run:
|
16
|
+
name: Run Rubocop
|
17
|
+
command: bundle exec rubocop
|
18
|
+
|
19
|
+
bundle-audit:
|
20
|
+
parallelism: 1
|
21
|
+
docker:
|
22
|
+
- image: cimg/ruby:3.1-node
|
23
|
+
steps:
|
24
|
+
- checkout
|
25
|
+
- ruby/install-deps
|
26
|
+
- run:
|
27
|
+
name: Run Bundler Audit
|
28
|
+
command: bundle exec bundle-audit
|
29
|
+
test:
|
30
|
+
parameters:
|
31
|
+
ruby-image:
|
32
|
+
type: string
|
33
|
+
parallelism: 1
|
34
|
+
docker:
|
35
|
+
- image: << parameters.ruby-image >>
|
36
|
+
steps:
|
37
|
+
- checkout
|
38
|
+
- ruby/install-deps
|
39
|
+
- run:
|
40
|
+
name: Run tests
|
41
|
+
command: bundle exec rspec -fd
|
42
|
+
|
43
|
+
workflows:
|
44
|
+
version: 2
|
45
|
+
checks:
|
46
|
+
jobs:
|
47
|
+
- rubocop
|
48
|
+
- bundle-audit
|
49
|
+
- test:
|
50
|
+
matrix:
|
51
|
+
parameters:
|
52
|
+
ruby-image:
|
53
|
+
- cimg/ruby:2.6-node
|
54
|
+
- cimg/ruby:2.7-node
|
55
|
+
- cimg/ruby:3.0-node
|
56
|
+
- cimg/ruby:3.1-node
|
57
|
+
- cimg/ruby:3.2-node
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
SuggestExtensions: false
|
4
|
+
TargetRubyVersion: 2.6
|
5
|
+
|
6
|
+
Layout/LineLength:
|
7
|
+
Max: 120
|
8
|
+
Exclude:
|
9
|
+
- 'spec/**/*'
|
10
|
+
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics/BlockLength:
|
15
|
+
Exclude:
|
16
|
+
- 'ruby-amazon-bedrock.gemspec'
|
17
|
+
- 'spec/**/*'
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Max: 20
|
21
|
+
|
22
|
+
Style/StringLiterals:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/StringLiteralsInInterpolation:
|
26
|
+
Enabled: true
|
27
|
+
EnforcedStyle: double_quotes
|
28
|
+
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
## [0.1.1] - 2023-12-13
|
2
|
+
|
3
|
+
- Add documentation to README.md
|
4
|
+
|
5
|
+
## [0.1.0] - 2023-12-01
|
6
|
+
|
7
|
+
- Initial release.
|
8
|
+
- Add AmazonBedrock::Client to connect to AWS Bedrock GenAI models.
|
9
|
+
- Add unit tests, test coverage, bundle-audit for vulnerability checks and rubocop for code style checks.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
- Using welcoming and inclusive language
|
18
|
+
- Being respectful of differing viewpoints and experiences
|
19
|
+
- Gracefully accepting constructive criticism
|
20
|
+
- Focusing on what is best for the community
|
21
|
+
- Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
- The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
- Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
- Public or private harassment
|
29
|
+
- Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at hola@alvarodelgado.dev. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/AAlvAAro/ruby-amazon-bedrock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/AAlvAAro/ruby-amazon-bedrock/blob/main/CODE_OF_CONDUCT.md).
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in ruby-amazon-bedrock.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "bundler-audit", "~> 0.8"
|
9
|
+
gem "dotenv", "~> 2.7"
|
10
|
+
gem "pry", "~> 0.13"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "rspec", "~> 3.0"
|
13
|
+
gem "rubocop", "~> 1.21"
|
14
|
+
gem "simplecov", "~> 0.21"
|
15
|
+
gem "vcr", "~> 6.0"
|
16
|
+
gem "webmock", "~> 3.12"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruby-amazon-bedrock (0.1.1)
|
5
|
+
aws-sdk-bedrockruntime (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.5)
|
11
|
+
public_suffix (>= 2.0.2, < 6.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
aws-eventstream (1.3.0)
|
14
|
+
aws-partitions (1.860.0)
|
15
|
+
aws-sdk-bedrockruntime (1.4.0)
|
16
|
+
aws-sdk-core (~> 3, >= 3.188.0)
|
17
|
+
aws-sigv4 (~> 1.1)
|
18
|
+
aws-sdk-core (3.189.0)
|
19
|
+
aws-eventstream (~> 1, >= 1.3.0)
|
20
|
+
aws-partitions (~> 1, >= 1.651.0)
|
21
|
+
aws-sigv4 (~> 1.8)
|
22
|
+
jmespath (~> 1, >= 1.6.1)
|
23
|
+
aws-sigv4 (1.8.0)
|
24
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
25
|
+
bundler-audit (0.9.1)
|
26
|
+
bundler (>= 1.2.0, < 3)
|
27
|
+
thor (~> 1.0)
|
28
|
+
coderay (1.1.3)
|
29
|
+
crack (0.4.5)
|
30
|
+
rexml
|
31
|
+
diff-lcs (1.5.0)
|
32
|
+
docile (1.4.0)
|
33
|
+
dotenv (2.8.1)
|
34
|
+
hashdiff (1.0.1)
|
35
|
+
jmespath (1.6.2)
|
36
|
+
json (2.6.3)
|
37
|
+
language_server-protocol (3.17.0.3)
|
38
|
+
method_source (1.0.0)
|
39
|
+
parallel (1.23.0)
|
40
|
+
parser (3.2.2.4)
|
41
|
+
ast (~> 2.4.1)
|
42
|
+
racc
|
43
|
+
pry (0.14.2)
|
44
|
+
coderay (~> 1.1)
|
45
|
+
method_source (~> 1.0)
|
46
|
+
public_suffix (5.0.4)
|
47
|
+
racc (1.7.3)
|
48
|
+
rainbow (3.1.1)
|
49
|
+
rake (13.1.0)
|
50
|
+
regexp_parser (2.8.2)
|
51
|
+
rexml (3.2.6)
|
52
|
+
rspec (3.12.0)
|
53
|
+
rspec-core (~> 3.12.0)
|
54
|
+
rspec-expectations (~> 3.12.0)
|
55
|
+
rspec-mocks (~> 3.12.0)
|
56
|
+
rspec-core (3.12.2)
|
57
|
+
rspec-support (~> 3.12.0)
|
58
|
+
rspec-expectations (3.12.3)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.12.0)
|
61
|
+
rspec-mocks (3.12.6)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.12.0)
|
64
|
+
rspec-support (3.12.1)
|
65
|
+
rubocop (1.57.2)
|
66
|
+
json (~> 2.3)
|
67
|
+
language_server-protocol (>= 3.17.0)
|
68
|
+
parallel (~> 1.10)
|
69
|
+
parser (>= 3.2.2.4)
|
70
|
+
rainbow (>= 2.2.2, < 4.0)
|
71
|
+
regexp_parser (>= 1.8, < 3.0)
|
72
|
+
rexml (>= 3.2.5, < 4.0)
|
73
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
74
|
+
ruby-progressbar (~> 1.7)
|
75
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
76
|
+
rubocop-ast (1.30.0)
|
77
|
+
parser (>= 3.2.1.0)
|
78
|
+
ruby-progressbar (1.13.0)
|
79
|
+
simplecov (0.22.0)
|
80
|
+
docile (~> 1.1)
|
81
|
+
simplecov-html (~> 0.11)
|
82
|
+
simplecov_json_formatter (~> 0.1)
|
83
|
+
simplecov-html (0.12.3)
|
84
|
+
simplecov_json_formatter (0.1.4)
|
85
|
+
thor (1.3.0)
|
86
|
+
unicode-display_width (2.5.0)
|
87
|
+
vcr (6.2.0)
|
88
|
+
webmock (3.19.1)
|
89
|
+
addressable (>= 2.8.0)
|
90
|
+
crack (>= 0.3.2)
|
91
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
92
|
+
|
93
|
+
PLATFORMS
|
94
|
+
arm64-darwin-22
|
95
|
+
|
96
|
+
DEPENDENCIES
|
97
|
+
bundler-audit (~> 0.8)
|
98
|
+
dotenv (~> 2.7)
|
99
|
+
pry (~> 0.13)
|
100
|
+
rake (~> 13.0)
|
101
|
+
rspec (~> 3.0)
|
102
|
+
rubocop (~> 1.21)
|
103
|
+
ruby-amazon-bedrock!
|
104
|
+
simplecov (~> 0.21)
|
105
|
+
vcr (~> 6.0)
|
106
|
+
webmock (~> 3.12)
|
107
|
+
|
108
|
+
BUNDLED WITH
|
109
|
+
2.4.22
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Alvaro Delgado
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,329 @@
|
|
1
|
+
# Ruby Amazon Bedrock
|
2
|
+
|
3
|
+
[![CircleCI Build Status](https://circleci.com/gh/AAlvAAro/ruby-amazon-bedrock.svg?style=shield)](https://circleci.com/gh/AAlvAAro/ruby-amazon-bedrock)
|
4
|
+
|
5
|
+
Seamless Integration with Amazon Bedrock API for AI-Powered Text and Image Generation in Ruby 🤖 + 💎. [Amazon Bedrock API](https://aws.amazon.com/es/bedrock/).
|
6
|
+
|
7
|
+
Amazon Bedrock is a fully managed service that makes FMs from leading AI startups and Amazon available via an API, so you can choose from a wide range of FMs to find the model that is best suited for your use case.
|
8
|
+
|
9
|
+
## Bundler
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "ruby-amazon-bedrock"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
## Gem install
|
24
|
+
|
25
|
+
Or install with:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
$ gem install ruby-amazon-bedrock
|
29
|
+
```
|
30
|
+
|
31
|
+
and require with:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require "amazon-bedrock"
|
35
|
+
```
|
36
|
+
|
37
|
+
## Credentials
|
38
|
+
|
39
|
+
In order to use Amazon Bedrock, you'll need your secure credentials just as any other AWS service. Get your keys from AWS IAM (Identity and Access Management) [https://us-east-1.console.aws.amazon.com/iam](https://us-east-1.console.aws.amazon.com/iam)
|
40
|
+
|
41
|
+
## Quickstart
|
42
|
+
|
43
|
+
For a quick test you can pass your token directly to a new client:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
client = RubyAmazonBedrock::Client.new(region: "your_aws_region", access_key_id: "your_access_key_id", access_token: "your_access_token")
|
47
|
+
```
|
48
|
+
|
49
|
+
## Models Providers
|
50
|
+
|
51
|
+
Amazon Bedrock is a fully managed service that makes FMs from leading AI startups and Amazon available via an API, so you can choose from a wide range of FMs to find the model that is best suited for your use case.
|
52
|
+
|
53
|
+
<!-- ### AI21 Labs
|
54
|
+
|
55
|
+
Businesses use AI21's Jurassic family of leading LLMs to build generative AI-driven applications and services leveraging existing organizational data. Jurassic supports cross-industry use cases including long and short-form text generation, contextual question answering, summarization, and classification. Designed to follow natural language instructions, Jurassic is trained on a massive corpus of web text and supports six languages in addition to English. [See more ...](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=ai21.j2-ultra-v1)
|
56
|
+
|
57
|
+
How to call AI21 models:
|
58
|
+
|
59
|
+
Jurassic-2 Ultra
|
60
|
+
|
61
|
+
Supported use cases: Open book question answering, summarization, draft generation, information extraction, ideation
|
62
|
+
|
63
|
+
Languages: English, Spanish, French, German, Portuguese, Italian, Dutch
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
client.invoke_model('ai21.j2-ultra-v1', 'Your prompt goes here ...')
|
67
|
+
```
|
68
|
+
|
69
|
+
Jurassic-2 Mid
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
client.invoke_model('ai21.j2-mid-v1', 'Your prompt goes here ...')
|
73
|
+
``` -->
|
74
|
+
|
75
|
+
### Amazon Titan
|
76
|
+
|
77
|
+
Amazon Titan Foundation Models are pre-trained on large datasets, making them powerful, general-purpose models. Use them as is, or customize them by fine tuning the models with your own data for a particular task without annotating large volumes of data. [See more ...](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=amazon.titan-embed-text-v1)
|
78
|
+
|
79
|
+
How to call Amazon Titan text models:
|
80
|
+
|
81
|
+
_Titan Text G1 - Lite_
|
82
|
+
|
83
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=amazon.titan-text-lite-v1](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=amazon.titan-text-lite-v1)
|
84
|
+
|
85
|
+
Supports: Text generation, Code generation, Rich text formatting, Orchestration (Agents), Fine Tuning.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
client.invoke_model(id: 'amazon.titan-text-lite-v1', input: 'Generate a story about rubies and gems')
|
89
|
+
|
90
|
+
# Response
|
91
|
+
{:inputTextTokenCount=>8,
|
92
|
+
:results=>
|
93
|
+
[{:tokenCount=>294,
|
94
|
+
:outputText=>
|
95
|
+
"\nOnce upon a time, there was a king who was very fond of rubies and gems. He had a collection of the most beautiful rubies and gems ...",
|
96
|
+
:completionReason=>"FINISH"}]}
|
97
|
+
```
|
98
|
+
|
99
|
+
<br>
|
100
|
+
|
101
|
+
_Titan Text G1 - Express_
|
102
|
+
|
103
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=amazon.titan-text-express-v1](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=amazon.titan-text-express-v1)
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
client.invoke_model(id: 'amazon.titan-text-express-v1', input: 'Generate a post about cats formatted with HTML tags')
|
107
|
+
|
108
|
+
# Response
|
109
|
+
{:inputTextTokenCount=>9,
|
110
|
+
:results=>
|
111
|
+
[{:tokenCount=>330,
|
112
|
+
:outputText=>
|
113
|
+
"\n<h1>Cats</h1>\n\nCats are small, furry, carnivorous mammals that are loved by many people around the world. They come in a variety of colors, shapes, and sizes, and have unique personalities that make them great companions.\n\n",
|
114
|
+
:completionReason=>"FINISH"}]}
|
115
|
+
```
|
116
|
+
|
117
|
+
Supports: Text generation, Code generation, Rich text formatting, Orchestration (Agents), Fine Tuning
|
118
|
+
|
119
|
+
### Anthropic
|
120
|
+
|
121
|
+
Anthropic offers the Claude family of large language models purpose built for conversations, summarization, Q&A, workflow automation, coding and more. Early customers report that Claude is much less likely to produce harmful outputs, easier to converse with, and more steerable - so you can get your desired output with less effort. Claude can also take direction on personality, tone, and behavior.
|
122
|
+
|
123
|
+
How to call Anthropic models:
|
124
|
+
|
125
|
+
_Claude Instant 1.2_
|
126
|
+
|
127
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=anthropic.claude-instant-v1](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=anthropic.claude-instant-v1)
|
128
|
+
|
129
|
+
Supports: Question answering, information extraction, removing PII, content generation, multiple choice classification, Roleplay, comparing text, summarization, document Q&A with citation
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
client.invoke_model('anthropic.claude-instant-v1', 'What is a neural network?')
|
133
|
+
|
134
|
+
# Response
|
135
|
+
{:completion=>
|
136
|
+
" A neural network is a type of machine learning model inspired by the human brain. The key elements of neural networks are:\n\n- Neurons..."
|
137
|
+
:stop_reason=>"stop_sequence",
|
138
|
+
:stop=>"\n\nHuman:"}
|
139
|
+
```
|
140
|
+
|
141
|
+
<br>
|
142
|
+
|
143
|
+
_Claude 1.3_
|
144
|
+
|
145
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=anthropic.claude-v1](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=anthropic.claude-v1)
|
146
|
+
|
147
|
+
Supports: Question answering, [information extraction](https://docs.anthropic.com/claude/docs/text-processing), removing PII, content generation, [multiple choice classification](https://docs.anthropic.com/claude/docs/multiple-choice-and-classification), [Roleplay](https://docs.anthropic.com/claude/docs/roleplay-dialogue), comparing text, summarization, [document Q&A with citation](https://docs.anthropic.com/claude/docs/advanced-text-analysis)
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
client.invoke_model(id: 'anthropic.claude-instant-v1', input: "You will be acting as a AI customer success agent for a company called Acme Dynamics.")
|
151
|
+
|
152
|
+
# Response
|
153
|
+
{:completion=>
|
154
|
+
" Okay, thanks for providing the context. My name is Claude, I'm an AI assistant created by Anthropic to be helpful, harmless, and honest. How can I assist you as a customer success agent for Acme Dynamics today?",
|
155
|
+
:stop_reason=>"stop_sequence",
|
156
|
+
:stop=>"\n\nHuman:"}
|
157
|
+
```
|
158
|
+
|
159
|
+
<br>
|
160
|
+
|
161
|
+
_Claude 2_
|
162
|
+
|
163
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=anthropic.claude-v2](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=anthropic.claude-v2)
|
164
|
+
|
165
|
+
Supports: Question answering, [information extraction](https://docs.anthropic.com/claude/docs/text-processing), removing PII, content generation, [multiple choice classification](https://docs.anthropic.com/claude/docs/multiple-choice-and-classification), [Roleplay](https://docs.anthropic.com/claude/docs/roleplay-dialogue), comparing text, summarization, [document Q&A with citation](https://docs.anthropic.com/claude/docs/advanced-text-analysis)
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
client.invoke_model(id: 'anthropic.claude-v2', input: "I'm going to provide some text. I want to remove all person
|
169
|
+
ally identifying information from this text and replace it with XXX. It's very important that PII such as names, phone numbers,
|
170
|
+
and home and email addresses, get replaced with XXX.")
|
171
|
+
|
172
|
+
# Response
|
173
|
+
{:completion=>
|
174
|
+
" Here is the text with personally identifying information replaced with XXX:\n\nXXX lives at XXX in the city of XXX. XXX can be reached at phone...",
|
175
|
+
:stop_reason=>"stop_sequence",
|
176
|
+
:stop=>"\n\nHuman:"}
|
177
|
+
```
|
178
|
+
|
179
|
+
### Cohere
|
180
|
+
|
181
|
+
Cohere models are text generation models for business use cases. Cohere models are trained on data that supports reliable business applications, like text generation, summarization, copywriting, dialogue, extraction, and question answering.
|
182
|
+
|
183
|
+
How to call Cohere command models:
|
184
|
+
|
185
|
+
_Command_
|
186
|
+
|
187
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.command-text-v14](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.command-text-v14)
|
188
|
+
|
189
|
+
Supports: Summarization, copywriting, dialogue, extraction, and question answering.
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
client.invoke_model(id: 'cohere.command-text-v14', input: 'Generate a twit about why Ruby on Rails is a great tool for building a startup. Write a few hashtags')
|
193
|
+
|
194
|
+
# Response
|
195
|
+
{:generations=>
|
196
|
+
[{:finish_reason=>"COMPLETE",
|
197
|
+
:id=>"b82658a5-8f36-4a94-a1f1-7802aa418904",
|
198
|
+
:text=>
|
199
|
+
" Sure! Here's a tweet:\n\nRuby on Rails is a powerful framework for building web applications. It is highly scalable, has robust community support, and is the perfect choice for startups looking to build fast and ship often. #RoR #RubyOnRails #Startup #Tech #Efficient \n\nWhat do you think?"}],
|
200
|
+
:id=>"d5d5149f-ea5a-47ae-ae37-8324882b06c7",
|
201
|
+
:prompt=>"Generate a twit about why Ruby on Rails is a great tool for building a startup. Write a few hashtags:"}
|
202
|
+
```
|
203
|
+
|
204
|
+
<br>
|
205
|
+
|
206
|
+
_Command Light_
|
207
|
+
|
208
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.command-light-text-v14](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.command-light-text-v14)
|
209
|
+
|
210
|
+
Supports: Summarization, copywriting, dialogue, extraction, and question answering.
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
client.invoke_model(id: 'cohere.command-light-text-v14', input: 'Generate a facebook post about GenAI models available at Amazon Bedrock')
|
214
|
+
|
215
|
+
# Response
|
216
|
+
{:generations=>
|
217
|
+
[{:finish_reason=>"MAX_TOKENS",
|
218
|
+
:id=>"b58eaa37-915e-4f26-b37c-6b4875516648",
|
219
|
+
:text=>
|
220
|
+
" Introducing the latest innovation at Amazon Bedrock - our state-of-the-art GenAI models! 🤖💡\n\nOur team has been working tirelessly to bring you the best in artificial intelligence, and we're excited to share the results with you. With our GenAI models, you can now:\n\n- Develop applications that can understand and respond to human language with incredible accuracy, thanks to our state-of-the-art Large Language Models (LLMs).\n-"}],
|
221
|
+
:id=>"0d2f2c74-cae9-434b-b5d5-f44aaeb1a587",
|
222
|
+
:prompt=>"Generate a facebook post about GenAI models available at Amazon Bedrock:"}
|
223
|
+
```
|
224
|
+
|
225
|
+
How to call Cohere embed models:
|
226
|
+
|
227
|
+
_Embed English_
|
228
|
+
|
229
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.embed-english-v3](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.embed-english-v3)
|
230
|
+
|
231
|
+
Supports: Semantic search, retrieval-augmented generation (RAG), classification, clustering.
|
232
|
+
|
233
|
+
```ruby
|
234
|
+
# WIP
|
235
|
+
# client.invoke_model(id: 'cohere.embed-english-v3', input: 'Your prompt goes here ...')
|
236
|
+
```
|
237
|
+
|
238
|
+
<br>
|
239
|
+
|
240
|
+
_Embed Multilingual_
|
241
|
+
|
242
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.embed-multilingual-v3](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=cohere.embed-multilingual-v3)
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
# WIP
|
246
|
+
# client.invoke_model(id: 'cohere.embed-multilingual-v3', input: 'Your prompt goes here ...')
|
247
|
+
```
|
248
|
+
|
249
|
+
### Meta
|
250
|
+
|
251
|
+
Meta is looking to unlock the power of large language models. Our latest version of Llama is now accessible to individuals, creators, researchers and businesses of all sizes so that they can experiment, innovate and scale their ideas responsibly.
|
252
|
+
|
253
|
+
How to call Meta models:
|
254
|
+
|
255
|
+
_Llama 2 Chat 13B_
|
256
|
+
|
257
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=meta.llama2-13b-chat-v1](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=meta.llama2-13b-chat-v1)
|
258
|
+
|
259
|
+
Supports: Llama 2 is intended for commercial and research use in English. Fine-tuned chat models are intended for chat based applications.
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
client.invoke_model(id: 'meta.llama2-13b-chat-v1', input: 'Generate an Instagram Post about the Metaverse')
|
263
|
+
|
264
|
+
# Resopnse
|
265
|
+
{:generation=>
|
266
|
+
"\n\nHey #Instagram community! 👋 I'm super excited to share my latest discovery with you all - the #Metaverse! 🤯🌐\n\nHave you heard of it? It's like a virtual world where you can be anyone and do anything! 😍 From exploring new planets to attending virtual concerts, the possibilities are endless! 🎉\n\nI've been spending some time in the #Metaverse lately, and let me tell you, it's a game changer! 🔥 Not only is it a ton of fun, but it's also a great way to connect with people from all over the world. 🌎\n\nI've made some amazing friends in the #Metaverse, and we've had some incredible adventures together! 🤝🌟\n\nSo, what are you waiting for? Come join me in the #Metaverse and let's explore this amazing virtual world together! 😄👋\n\n#Metaverse #VirtualReality #VR #Gaming #Adventure #Fun #Community #Friends #Instagram #SocialMedia",
|
267
|
+
:prompt_token_count=>11,
|
268
|
+
:generation_token_count=>275,
|
269
|
+
:stop_reason=>"stop"}
|
270
|
+
```
|
271
|
+
|
272
|
+
<br>
|
273
|
+
|
274
|
+
_Llama 2 Chat 70B_
|
275
|
+
|
276
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=meta.llama2-70b-chat-v1](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=meta.llama2-70b-chat-v1)
|
277
|
+
|
278
|
+
Supports: Llama 2 is intended for commercial and research use in English. Fine-tuned chat models are intended for chat based applications.
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
client.invoke_model(id: 'meta.llama2-70b-chat-v1', input: 'Generate a Facebook add to promote a new website that is selling Ruby on Rails and AI courses')
|
282
|
+
|
283
|
+
# Response
|
284
|
+
{:generation=>
|
285
|
+
".\n\nThe ad should be targeted at people who are interested in learning Ruby on Rails and AI, and should highlight the benefits of taking the courses on the website.\n\nHere is a sample ad that could be used to promote the website:\n\nHeadline: Unlock Your Potential with Ruby on Rails and AI Courses\n\nBody: Are you interested in learning Ruby on Rails and AI? Look no further! Our website offers a range of courses that will teach you everything you need to know to get started with these exciting technologies.\n\nOur Ruby on Rails courses will show you how to build powerful web applications using the popular framework, while our AI courses will teach you the fundamentals of machine learning and deep learning. ...",
|
286
|
+
:prompt_token_count=>22,
|
287
|
+
:generation_token_count=>512,
|
288
|
+
:stop_reason=>"length"}
|
289
|
+
```
|
290
|
+
|
291
|
+
### Stability AI
|
292
|
+
|
293
|
+
Stability AI is the world's leading open-source generative artificial intelligence company, collaborating with public and private sector partners to bring next generation infrastructure to a global audience.
|
294
|
+
|
295
|
+
How to call Stability AI models:
|
296
|
+
|
297
|
+
_SDXL 0.8_
|
298
|
+
|
299
|
+
[https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=stability.stable-diffusion-xl-v0](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/providers?model=stability.stable-diffusion-xl-v0)
|
300
|
+
|
301
|
+
Supports: image generation, image editing
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
client.invoke_model(id: 'stability.stable-diffusion-xl-v0', input: 'Generate an image of a hamster flying a helicopter')
|
305
|
+
|
306
|
+
# TODO: save the response into an image file
|
307
|
+
```
|
308
|
+
|
309
|
+
<br>
|
310
|
+
|
311
|
+
_SDXL 1.0_
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
client.invoke_model(id: 'stability.stable-diffusion-xl-v1', input: 'Generate an image of a hamster driving an F1 car')
|
315
|
+
|
316
|
+
# TODO: save the response into an image file
|
317
|
+
```
|
318
|
+
|
319
|
+
<!-- ## Contributing
|
320
|
+
|
321
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/AAlvAAro/ruby-amazon-bedrock>. -->
|
322
|
+
|
323
|
+
## License
|
324
|
+
|
325
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
326
|
+
|
327
|
+
<!-- ## Code of Conduct
|
328
|
+
|
329
|
+
Everyone interacting in the Ruby Amazon Bedrock project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/AAlvAAro/ruby-amazon-bedrock/blob/main/CODE_OF_CONDUCT.md). -->
|