forked from phoenix/litellm-mirror
(docs) bedrock cookbook
This commit is contained in:
parent
2498d95dc5
commit
884030078d
1 changed files with 99 additions and 92 deletions
189
cookbook/LiteLLM_Bedrock.ipynb
vendored
189
cookbook/LiteLLM_Bedrock.ipynb
vendored
|
@ -1,36 +1,25 @@
|
||||||
{
|
{
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 0,
|
|
||||||
"metadata": {
|
|
||||||
"colab": {
|
|
||||||
"provenance": []
|
|
||||||
},
|
|
||||||
"kernelspec": {
|
|
||||||
"name": "python3",
|
|
||||||
"display_name": "Python 3"
|
|
||||||
},
|
|
||||||
"language_info": {
|
|
||||||
"name": "python"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
|
||||||
"# LiteLLM Bedrock Usage"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "fNkMBurtxawJ"
|
"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",
|
"cell_type": "markdown",
|
||||||
"source": [
|
|
||||||
"## Pre-Requisites"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "htAufI28xeSy"
|
"id": "htAufI28xeSy"
|
||||||
}
|
},
|
||||||
|
"source": [
|
||||||
|
"## Pre-Requisites"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
@ -45,57 +34,42 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
|
||||||
"## Set Bedrock/AWS Credentials"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "H4Vu4er2xnfI"
|
"id": "H4Vu4er2xnfI"
|
||||||
}
|
},
|
||||||
|
"source": [
|
||||||
|
"## Set Bedrock/AWS Credentials"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
"execution_count": 9,
|
||||||
|
"metadata": {
|
||||||
|
"id": "CtTrBthWxp-t"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import os\n",
|
"import os\n",
|
||||||
"os.environ[\"AWS_ACCESS_KEY_ID\"] = \"\" # Access key\n",
|
"os.environ[\"AWS_ACCESS_KEY_ID\"] = \"\" # Access key\n",
|
||||||
"os.environ[\"AWS_SECRET_ACCESS_KEY\"] = \"\" # Secret access key\n",
|
"os.environ[\"AWS_SECRET_ACCESS_KEY\"] = \"\" # Secret access key\n",
|
||||||
"os.environ[\"AWS_REGION_NAME\"] = \"\""
|
"os.environ[\"AWS_REGION_NAME\"] = \"\""
|
||||||
],
|
]
|
||||||
"metadata": {
|
|
||||||
"id": "CtTrBthWxp-t"
|
|
||||||
},
|
|
||||||
"execution_count": 9,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
|
||||||
"## Anthropic Requests"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "ycRK9NUdx1EI"
|
"id": "ycRK9NUdx1EI"
|
||||||
}
|
},
|
||||||
|
"source": [
|
||||||
|
"## Anthropic Requests"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"execution_count": 15,
|
||||||
"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)"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
|
@ -103,11 +77,10 @@
|
||||||
"id": "tgkuoHa5uLOy",
|
"id": "tgkuoHa5uLOy",
|
||||||
"outputId": "27a78e86-c6a7-4bcc-8559-0813cb978426"
|
"outputId": "27a78e86-c6a7-4bcc-8559-0813cb978426"
|
||||||
},
|
},
|
||||||
"execution_count": 15,
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"output_type": "stream",
|
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"Claude instant 1, response\n",
|
"Claude instant 1, response\n",
|
||||||
"{\n",
|
"{\n",
|
||||||
|
@ -159,19 +132,43 @@
|
||||||
"}\n"
|
"}\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",
|
"cell_type": "markdown",
|
||||||
"source": [
|
|
||||||
"## Anthropic Requests - With Streaming"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "HnM-HtM3yFMT"
|
"id": "HnM-HtM3yFMT"
|
||||||
}
|
},
|
||||||
|
"source": [
|
||||||
|
"## Anthropic Requests - With Streaming"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "_JZvg2yovRsU"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from litellm import completion\n",
|
"from litellm import completion\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -194,39 +191,21 @@
|
||||||
"print(response)\n",
|
"print(response)\n",
|
||||||
"for chunk in response:\n",
|
"for chunk in response:\n",
|
||||||
" print(chunk)"
|
" print(chunk)"
|
||||||
],
|
]
|
||||||
"metadata": {
|
|
||||||
"id": "_JZvg2yovRsU"
|
|
||||||
},
|
|
||||||
"execution_count": null,
|
|
||||||
"outputs": []
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
|
||||||
"## A121 Requests"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "zj1U1mh9zEhP"
|
"id": "zj1U1mh9zEhP"
|
||||||
}
|
},
|
||||||
|
"source": [
|
||||||
|
"## A121 Requests"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"execution_count": 19,
|
||||||
"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)"
|
|
||||||
],
|
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"base_uri": "https://localhost:8080/"
|
"base_uri": "https://localhost:8080/"
|
||||||
|
@ -234,11 +213,10 @@
|
||||||
"id": "6wK6MZLovU7r",
|
"id": "6wK6MZLovU7r",
|
||||||
"outputId": "4cf80c04-f15d-4066-b4c7-113b551538de"
|
"outputId": "4cf80c04-f15d-4066-b4c7-113b551538de"
|
||||||
},
|
},
|
||||||
"execution_count": 19,
|
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"output_type": "stream",
|
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"J2 ultra response\n",
|
"J2 ultra response\n",
|
||||||
"{\n",
|
"{\n",
|
||||||
|
@ -288,16 +266,45 @@
|
||||||
"}\n"
|
"}\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",
|
"cell_type": "code",
|
||||||
"source": [],
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "Y5gGZIwzzSON"
|
"id": "Y5gGZIwzzSON"
|
||||||
},
|
},
|
||||||
"execution_count": null,
|
"outputs": [],
|
||||||
"outputs": []
|
"source": []
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"provenance": []
|
||||||
|
},
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"name": "python"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 0
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue