/ex_aws_bedrock

Elixir library for AWS Bedrock

Primary LanguageElixir

ExAws.Bedrock

The easiest way to build and scale generative AI applications with foundation models -- https://aws.amazon.com/bedrock/

Service module for Elixir AWS.

This library supports listing and invoking models of text and images and streaming of responses. Agents are not yet supported.

ci Hex.pm API Docs

Installation

The package can be installed by adding :ex_aws_bedrock to your list of dependencies in mix.exs along with :ex_aws, and your preferred HTTP client and JSON codec.

def deps do
  [
    {:ex_aws, ">= 2.5.1"},
    {:ex_aws_bedrock, "~> 2.5"},
    {:hackney, "~> 1.9"},
    {:jason, "~> 1.1"},
    {:poison, "~> 3.0"}
  ]
end

NOTE:

  • this requires a minimum ex_aws version of 2.5.1.
  • if you wish to stream responses, please include hackney and jason.

Unit tests

The default suite of unit tests verify the requests generated by this library. If you wish to test against AWS with live requests then you need to configure ExAws in the standard way as described in it's README.

For example you could create an .env file:

export AWS_ACCESS_KEY_ID="AK..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_REGION="us-east-1"

Then set the variables and run the tests with:

source .env && mix test --only aws

Usage

The AWS bedrock actions and operations are defined in ExAws.Bedrock module.

Each model takes their inference parameters as JSON documents which are defined in the model parameters section of the AWS user guide. You can pass plain Elixir maps which are then JSON encoded, or define structs which implement the encoder protocol of your chosen JSON codec. This library has an example under ExAws.Bedrock.Titan.TextModel.

The Meta models can be invoked with a pure map input:

%{
    "prompt" => "What is the best AWS client library for the Elixir programming language?",
    "temperature" => 0.5,
    "top_p" => 0.9,
    "max_gen_len" => 80
}

Example

Run the example script to sample the models and their quality of responses:

source .env && mix run examples.exs    

Outputs:

Asking meta.llama2-70b-chat-v1 "Complete this riddle. Ruby is to Yukihiro Matsumoto as Elixir is to" with temperature=0.8

Answer: José Valim.
Explanation:
Ruby is a programming language created by Yukihiro Matsumoto, also known as Matz.
Elixir is a programming language created by José Valim, also known as José.

Therefore, the answer to the riddle is "José Valim".


Asking meta.llama2-70b-chat-v1 "What is the best AWS client library for the Elixir programming language?" with temperature=0.8

Answer: The best AWS client library for the Elixir programming language is the `ex_aws` library. It is a lightweight, idiomatic Elixir client for AWS services, providing a simple and intuitive API for interacting with AWS.

License

The MIT License (MIT).