fix docs hierarchy

This commit is contained in:
ishaan-jaff 2023-08-15 15:28:34 -07:00
parent b49583893c
commit 408b9a4e22
2 changed files with 58 additions and 55 deletions

View file

@ -1,72 +1,56 @@
{ {
"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",
"metadata": {
"id": "WemkFEdDAnJL"
},
"source": [ "source": [
"## liteLLM Together AI Tutorial\n", "## liteLLM Together AI Tutorial\n",
"https://together.ai/\n" "https://together.ai/\n"
], ]
"metadata": {
"id": "WemkFEdDAnJL"
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "execution_count": null,
"!pip install litellm==0.1.371"
],
"metadata": { "metadata": {
"id": "pc6IO4V99O25" "id": "pc6IO4V99O25"
}, },
"execution_count": null, "outputs": [],
"outputs": [] "source": [
"!pip install litellm==0.1.371"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "TMI3739_9q97"
},
"outputs": [],
"source": [ "source": [
"import os\n", "import os\n",
"from litellm import completion\n", "from litellm import completion\n",
"os.environ[\"TOGETHER_AI_TOKEN\"] = \"\" #@param\n", "os.environ[\"TOGETHER_AI_TOKEN\"] = \"\" #@param\n",
"user_message = \"Hello, whats the weather in San Francisco??\"\n", "user_message = \"Hello, whats the weather in San Francisco??\"\n",
"messages = [{ \"content\": user_message,\"role\": \"user\"}]" "messages = [{ \"content\": user_message,\"role\": \"user\"}]"
], ]
"metadata": {
"id": "TMI3739_9q97"
},
"execution_count": 5,
"outputs": []
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {
"id": "bEqJ2HHjBJqq"
},
"source": [ "source": [
"## Calling togethercomputer/llama-2-70b-chat\n", "## Calling togethercomputer/llama-2-70b-chat\n",
"https://api.together.xyz/playground/chat?model=togethercomputer%2Fllama-2-70b-chat" "https://api.together.xyz/playground/chat?model=togethercomputer%2Fllama-2-70b-chat"
], ]
"metadata": {
"id": "bEqJ2HHjBJqq"
}
}, },
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "execution_count": 6,
"model_name = \"togethercomputer/llama-2-70b-chat\"\n",
"response = completion(model=model_name, messages=messages, together_ai=True)\n",
"print(response)"
],
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -74,34 +58,34 @@
"id": "Jrrt8puj523f", "id": "Jrrt8puj523f",
"outputId": "5a5b5beb-cda3-413e-8e83-4423d392cb44" "outputId": "5a5b5beb-cda3-413e-8e83-4423d392cb44"
}, },
"execution_count": 6,
"outputs": [ "outputs": [
{ {
"output_type": "stream",
"name": "stdout", "name": "stdout",
"output_type": "stream",
"text": [ "text": [
"{'choices': [{'finish_reason': 'stop', 'index': 0, 'message': {'role': 'assistant', 'content': \"\\n\\nI'm not able to provide real-time weather information. However, I can suggest\"}}], 'created': 1691629657.9288375, 'model': 'togethercomputer/llama-2-70b-chat', 'usage': {'prompt_tokens': 9, 'completion_tokens': 17, 'total_tokens': 26}}\n" "{'choices': [{'finish_reason': 'stop', 'index': 0, 'message': {'role': 'assistant', 'content': \"\\n\\nI'm not able to provide real-time weather information. However, I can suggest\"}}], 'created': 1691629657.9288375, 'model': 'togethercomputer/llama-2-70b-chat', 'usage': {'prompt_tokens': 9, 'completion_tokens': 17, 'total_tokens': 26}}\n"
] ]
} }
],
"source": [
"model_name = \"togethercomputer/llama-2-70b-chat\"\n",
"response = completion(model=model_name, messages=messages, custom_llm_provider=\"together_ai\")\n",
"print(response)"
] ]
}, },
{ {
"attachments": {},
"cell_type": "markdown", "cell_type": "markdown",
"source": [
"## With Streaming"
],
"metadata": { "metadata": {
"id": "sfWtgf-mBQcM" "id": "sfWtgf-mBQcM"
} },
"source": [
"## With Streaming"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "execution_count": 8,
"response = completion(model=model_name, messages=messages, together_ai=True, stream=True)\n",
"print(response)\n",
"for chunk in response:\n",
" print(chunk['choices'][0]['delta']) # same as openai format"
],
"metadata": { "metadata": {
"colab": { "colab": {
"base_uri": "https://localhost:8080/" "base_uri": "https://localhost:8080/"
@ -109,11 +93,10 @@
"id": "wuBhlZtC6MH5", "id": "wuBhlZtC6MH5",
"outputId": "fcb82177-6494-4963-8e37-8716d3b9e616" "outputId": "fcb82177-6494-4963-8e37-8716d3b9e616"
}, },
"execution_count": 8,
"outputs": [ "outputs": [
{ {
"output_type": "stream",
"name": "stdout", "name": "stdout",
"output_type": "stream",
"text": [ "text": [
"<litellm.utils.CustomStreamWrapper object at 0x7ad005e93ee0>\n", "<litellm.utils.CustomStreamWrapper object at 0x7ad005e93ee0>\n",
"{'role': 'assistant', 'content': '\\\\n'}\n", "{'role': 'assistant', 'content': '\\\\n'}\n",
@ -136,7 +119,27 @@
"{'role': 'assistant', 'content': ' can'}\n" "{'role': 'assistant', 'content': ' can'}\n"
] ]
} }
],
"source": [
"response = completion(model=model_name, messages=messages, stream=True, custom_llm_provider=\"together_ai\")\n",
"print(response)\n",
"for chunk in response:\n",
" print(chunk['choices'][0]['delta']) # same as openai format"
] ]
} }
] ],
} "metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View file

@ -9,7 +9,7 @@
| gpt-3.5-turbo-16k-0613 | `completion('gpt-3.5-turbo-16k-0613', messages)` | `os.environ['OPENAI_API_KEY']` | | gpt-3.5-turbo-16k-0613 | `completion('gpt-3.5-turbo-16k-0613', messages)` | `os.environ['OPENAI_API_KEY']` |
| gpt-4 | `completion('gpt-4', messages)` | `os.environ['OPENAI_API_KEY']` | | gpt-4 | `completion('gpt-4', messages)` | `os.environ['OPENAI_API_KEY']` |
## Azure OpenAI Chat Completion Models ### Azure OpenAI Chat Completion Models
| Model Name | Function Call | Required OS Variables | | Model Name | Function Call | Required OS Variables |
|------------------|-----------------------------------------|-------------------------------------------| |------------------|-----------------------------------------|-------------------------------------------|