This file contains hidden or 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
| """ | |
| ChatGPT-like application for demoing OpenAI-compatible proxies. | |
| Adapted from https://docs.streamlit.io/develop/tutorials/llms/build-conversational-apps | |
| """ | |
| import os | |
| import streamlit as st | |
| from openai import OpenAI |
This file contains hidden or 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
| # pylint: disable=line-too-long | |
| """ | |
| ## Amazon Bedrock... let's go raw! 🥩 | |
| Your mission (if you choose to accept it) is to create a bedrock.invokeModel request from the ground up. | |
| In a nutshell, we have to prepare the request, SigV4-sign it and then send it to the Bedrock Runtime endpoint. | |
| Sounds fun? Then, let's get started... |
This file contains hidden or 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
| #!/bin/bash | |
| [[ -n "${AWS_ACCESS_KEY_ID}" ]] || | |
| { echo "AWS_ACCESS_KEY_ID is required" >&2; exit 1; } | |
| [[ -n "${AWS_SECRET_ACCESS_KEY}" ]] || | |
| { echo "AWS_SECRET_ACCESS_KEY is required" >&2; exit 1; } | |
| [[ -n "${AWS_SESSION_TOKEN}" ]] || | |
| { echo "AWS_SESSION_TOKEN is required" >&2; exit 1; } | |
| # The AWS region |
This file contains hidden or 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
| # pylint: disable=invalid-name | |
| """ | |
| Call Amazon Bedrock via Boto3 with AWS SigV4 | |
| """ | |
| import os | |
| import logging | |
| import http.client as http_client |
This file contains hidden or 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
| # pylint: disable=global-statement,invalid-name | |
| r""" | |
| Play chess with Amazon Bedrock | |
| _:_ | |
| '-.-' | |
| () __.'.__ | |
| .-:--:-. |_______| | |
| () \____/ \=====/ | |
| /\ {====} )___( |
This file contains hidden or 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
| # pylint: disable=invalid-name,line-too-long,missing-function-docstring,redefined-outer-name | |
| """ | |
| Demo: Bedrock Access Gateway with Guardrails | |
| Adapted from | |
| https://aws.amazon.com/blogs/aws/guardrails-for-amazon-bedrock-can-now-detect-hallucinations-and-safeguard-apps-built-using-custom-or-third-party-fms/ | |
| """ | |
| import os | |
| import boto3 |
This file contains hidden or 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
| # pylint: disable=redefined-outer-name | |
| """ | |
| Exploring the modality gap with Amazon Bedrock | |
| References: | |
| https://jina.ai/news/the-what-and-why-of-text-image-modality-gap-in-clip-models/ | |
| """ | |
| import base64 | |
| import json |
This file contains hidden or 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
| # pylint: disable=redefined-outer-name | |
| r""" | |
| Explore the modality gap with Amazon Bedrock 🧭⛰️ | |
| _ . , . . | |
| * / \_ * / \_ _ * * /\'__ * | |
| / \ / \, (( . _/ / \ *'. | |
| . /\/\ /\/ :' __ \_ ` _^/ ^/ `--. | |
| / \/ \ _/ \-'\ * /.' ^_ \_ .'\ * | |
| /\ .- `. \/ \ /==~=-=~=-=-;. _/ \ -. `_/ \ |
This file contains hidden or 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
| # 0a. Download, install and activate Miniconda | |
| # https://docs.anaconda.com/miniconda/ | |
| mkdir -p ~/miniconda3 | |
| wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh | |
| bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 | |
| rm ~/miniconda3/miniconda.sh | |
| ~/miniconda3/bin/conda init bash | |
| source ~/.bashrc | |
| # 0b. Install Llama Stack |
This file contains hidden or 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
| """ | |
| Sends love to Amazon Titan for Embeddings 💖 | |
| and gets a bunch of numbers in return 🔢 | |
| """ | |
| import json | |
| import boto3 | |
| # Initialize Bedrock Runtime client | |
| # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime.html |