From 884030078d877caffa7d788abe84286a8a3e687d Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 6 Nov 2023 18:00:52 -0800 Subject: [PATCH] (docs) bedrock cookbook --- cookbook/LiteLLM_Bedrock.ipynb | 191 +++++++++++++++++---------------- 1 file changed, 99 insertions(+), 92 deletions(-) diff --git a/cookbook/LiteLLM_Bedrock.ipynb b/cookbook/LiteLLM_Bedrock.ipynb index b47ffef67..eed603639 100644 --- a/cookbook/LiteLLM_Bedrock.ipynb +++ b/cookbook/LiteLLM_Bedrock.ipynb @@ -1,36 +1,25 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, "cells": [ { + "attachments": {}, "cell_type": "markdown", - "source": [ - "# LiteLLM Bedrock Usage" - ], "metadata": { "id": "fNkMBurtxawJ" - } + }, + "source": [ + "# LiteLLM Bedrock Usage\n", + "Important Note: For Bedrock Requests you need to ensure you have `pip install boto3>=1.28.57`, boto3 supports bedrock from `boto3>=1.28.57` and higher " + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "## Pre-Requisites" - ], "metadata": { "id": "htAufI28xeSy" - } + }, + "source": [ + "## Pre-Requisites" + ] }, { "cell_type": "code", @@ -45,57 +34,42 @@ ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "## Set Bedrock/AWS Credentials" - ], "metadata": { "id": "H4Vu4er2xnfI" - } + }, + "source": [ + "## Set Bedrock/AWS Credentials" + ] }, { "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "CtTrBthWxp-t" + }, + "outputs": [], "source": [ "import os\n", "os.environ[\"AWS_ACCESS_KEY_ID\"] = \"\" # Access key\n", "os.environ[\"AWS_SECRET_ACCESS_KEY\"] = \"\" # Secret access key\n", "os.environ[\"AWS_REGION_NAME\"] = \"\"" - ], - "metadata": { - "id": "CtTrBthWxp-t" - }, - "execution_count": 9, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "## Anthropic Requests" - ], "metadata": { "id": "ycRK9NUdx1EI" - } + }, + "source": [ + "## Anthropic Requests" + ] }, { "cell_type": "code", - "source": [ - "from litellm import completion\n", - "\n", - "response = completion(\n", - " model=\"bedrock/anthropic.claude-instant-v1\",\n", - " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}]\n", - ")\n", - "print(\"Claude instant 1, response\")\n", - "print(response)\n", - "\n", - "\n", - "response = completion(\n", - " model=\"bedrock/anthropic.claude-v2\",\n", - " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}]\n", - ")\n", - "print(\"Claude v2, response\")\n", - "print(response)" - ], + "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -103,11 +77,10 @@ "id": "tgkuoHa5uLOy", "outputId": "27a78e86-c6a7-4bcc-8559-0813cb978426" }, - "execution_count": 15, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "Claude instant 1, response\n", "{\n", @@ -159,19 +132,43 @@ "}\n" ] } + ], + "source": [ + "from litellm import completion\n", + "\n", + "response = completion(\n", + " model=\"bedrock/anthropic.claude-instant-v1\",\n", + " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}]\n", + ")\n", + "print(\"Claude instant 1, response\")\n", + "print(response)\n", + "\n", + "\n", + "response = completion(\n", + " model=\"bedrock/anthropic.claude-v2\",\n", + " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}]\n", + ")\n", + "print(\"Claude v2, response\")\n", + "print(response)" ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "## Anthropic Requests - With Streaming" - ], "metadata": { "id": "HnM-HtM3yFMT" - } + }, + "source": [ + "## Anthropic Requests - With Streaming" + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "_JZvg2yovRsU" + }, + "outputs": [], "source": [ "from litellm import completion\n", "\n", @@ -194,39 +191,21 @@ "print(response)\n", "for chunk in response:\n", " print(chunk)" - ], - "metadata": { - "id": "_JZvg2yovRsU" - }, - "execution_count": null, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", - "source": [ - "## A121 Requests" - ], "metadata": { "id": "zj1U1mh9zEhP" - } + }, + "source": [ + "## A121 Requests" + ] }, { "cell_type": "code", - "source": [ - "response = completion(\n", - " model=\"bedrock/ai21.j2-ultra\",\n", - " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}],\n", - ")\n", - "print(\"J2 ultra response\")\n", - "print(response)\n", - "\n", - "response = completion(\n", - " model=\"bedrock/ai21.j2-mid\",\n", - " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}],\n", - ")\n", - "print(\"J2 mid response\")\n", - "print(response)" - ], + "execution_count": 19, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -234,11 +213,10 @@ "id": "6wK6MZLovU7r", "outputId": "4cf80c04-f15d-4066-b4c7-113b551538de" }, - "execution_count": 19, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "J2 ultra response\n", "{\n", @@ -288,16 +266,45 @@ "}\n" ] } + ], + "source": [ + "response = completion(\n", + " model=\"bedrock/ai21.j2-ultra\",\n", + " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}],\n", + ")\n", + "print(\"J2 ultra response\")\n", + "print(response)\n", + "\n", + "response = completion(\n", + " model=\"bedrock/ai21.j2-mid\",\n", + " messages=[{ \"content\": \"Hello, how are you?\",\"role\": \"user\"}],\n", + ")\n", + "print(\"J2 mid response\")\n", + "print(response)" ] }, { "cell_type": "code", - "source": [], + "execution_count": null, "metadata": { "id": "Y5gGZIwzzSON" }, - "execution_count": null, - "outputs": [] + "outputs": [], + "source": [] } - ] -} \ No newline at end of file + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}