Giter VIP home page Giter VIP logo

lambda_bedrock_streaming's Introduction

Overview

This repository implemented a Lambda function URL with streaming responses from Bedrock. The code implements the Anthropic Claude v2 model and the Amazon Titan Embeddings G1 text model.

Pre-requisites

Copy etc/environment.template to etc/environment.sh and update accordingly.

  • PROFILE: your AWS CLI profile with the appropriate credentials to deploy
  • REGION: your AWS region
  • BUCKET: your configuration bucket

For the Lambda stack, update the following accordingly.

  • P_FN_MEMORY: amount of memory in MB for the Lambda function
  • P_FN_TIMEOUT: timeout in seconds for the Lambda function

Deployment

To deploy the stack, run the following command: make lambda.

After completing the deployment, capture the following outputs in your etc/environment.sh file.

  • O_FN: output function name
  • O_FURL: output function url fqdn

Configuration

The etc/bedrock.json event payload file has been setup to simplify invocation of the Bedrock API while giving you flexibility to try different code paths.

  • lambdaParams.isStreaming: true | false
  • lambdaParams.sdk: anthropicClaude | awsClaude | awsTitan
  • modelParams.prompt: update this to whatever prompt you want to initially use

Testing

In order to use the curl commands with IAM authentication enabled, you can use the --user access_key:secret_access_key parameter but this is insecure as it exposes your credentials to the command line history. Alternatively, you can configure a ~/.netrc file and setup your credentials there. This allows you to instead use --netrc which then retrieves the credentials from that file. More details can be found in the curl documentation.

You can do some initial Lambda response streaming testing with the etc/streaming.json event payload and the following commands:

  • If you set AuthType: NONE, you can curl your endpoint with make curl.
  • If you set AuthType: AWS_IAM, you can curl your endpoint with make curl.auth.

You can now test Bedrock with response streaming with the etc/bedrock.json event payload with the make curl.bedrock.

Local testing

SAM local does not support streaming responses, so sam local invoke command will end in a function timeout:

An unexpected error was encountered while executing "sam local invoke".
Function 'Fn' timed out after 30 seconds

lambda_bedrock_streaming's People

Contributors

heeki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.