mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-24 10:14:26 +00:00
fix replicate docs
This commit is contained in:
parent
951554d015
commit
4cf6900eae
2 changed files with 63 additions and 61 deletions
2
cookbook/Evaluating_LLMs.ipynb
vendored
2
cookbook/Evaluating_LLMs.ipynb
vendored
|
@ -25,7 +25,7 @@
|
|||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install litellm==0.1.404 python-dotenv"
|
||||
"!pip install litellm python-dotenv"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
122
cookbook/liteLLM_Replicate_Demo.ipynb
vendored
122
cookbook/liteLLM_Replicate_Demo.ipynb
vendored
|
@ -1,21 +1,11 @@
|
|||
{
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": []
|
||||
},
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"cells": [
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "YV6L5fNv7Kep"
|
||||
},
|
||||
"source": [
|
||||
"# Call Replicate LLMs using chatGPT Input/Output Format\n",
|
||||
"This tutorial covers using the following Replicate Models with liteLLM\n",
|
||||
|
@ -28,10 +18,7 @@
|
|||
"\n",
|
||||
"\n",
|
||||
"\n"
|
||||
],
|
||||
"metadata": {
|
||||
"id": "YV6L5fNv7Kep"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -46,53 +33,44 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "mpHTbTqQ8fey"
|
||||
},
|
||||
"source": [
|
||||
"Imports & Set ENV variables\n",
|
||||
"Get your Replicate Key: https://replicate.com/account/api-tokens"
|
||||
],
|
||||
"metadata": {
|
||||
"id": "mpHTbTqQ8fey"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"id": "kDbgfcU8O-dW"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from litellm import completion\n",
|
||||
"import os\n",
|
||||
"os.environ['REPLICATE_API_TOKEN'] = ' ' # @param\n",
|
||||
"user_message = \"Hello, whats the weather in San Francisco??\"\n",
|
||||
"messages = [{ \"content\": user_message,\"role\": \"user\"}]"
|
||||
],
|
||||
"metadata": {
|
||||
"id": "kDbgfcU8O-dW"
|
||||
},
|
||||
"execution_count": 2,
|
||||
"outputs": []
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"## Call Replicate Models using completion(model, messages) - chatGPT format"
|
||||
],
|
||||
"metadata": {
|
||||
"id": "1KmkOdzLSOmJ"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Call Replicate Models using completion(model, messages) - chatGPT format"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"stability_ai = \"stability-ai/stablelm-tuned-alpha-7b:c49dae362cbaecd2ceabb5bd34fdb68413c4ff775111fea065d259d577757beb\"\n",
|
||||
"llama_2 = \"replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1\"\n",
|
||||
"llama_2_7b = \"a16z-infra/llama-2-7b-chat:4f0b260b6a13eb53a6b1891f089d57c08f41003ae79458be5011303d81a394dc\"\n",
|
||||
"dolly_v2 = \"replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5\"\n",
|
||||
"vicuna = \"replicate/vicuna-13b:6282abe6a492de4145d7bb601023762212f9ddbbe78278bd6771c8b3b2f2a13b\"\n",
|
||||
"models = [stability_ai, llama_2, llama_2_7b, dolly_v2, vicuna]\n",
|
||||
"for model in models:\n",
|
||||
" response = completion(model=model, messages=messages, replicate=True)\n",
|
||||
" print(f\"Response from {model} \\n]\\n\")\n",
|
||||
" print(response)"
|
||||
],
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/"
|
||||
|
@ -100,11 +78,10 @@
|
|||
"id": "XJ4nh4SnRzHP",
|
||||
"outputId": "986c0544-bb40-4915-f00f-498b0e518307"
|
||||
},
|
||||
"execution_count": 3,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"replicate is not installed. Installing...\n",
|
||||
"Response from stability-ai/stablelm-tuned-alpha-7b:c49dae362cbaecd2ceabb5bd34fdb68413c4ff775111fea065d259d577757beb \n",
|
||||
|
@ -129,17 +106,22 @@
|
|||
"{'choices': [{'finish_reason': 'stop', 'index': 0, 'message': {'role': 'assistant', 'content': ''}}], 'created': 1691611752.8998356, 'model': 'replicate/vicuna-13b:6282abe6a492de4145d7bb601023762212f9ddbbe78278bd6771c8b3b2f2a13b', 'usage': {'prompt_tokens': 9, 'completion_tokens': 0, 'total_tokens': 9}}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"llama_2 = \"replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1\"\n",
|
||||
"llama_2_7b = \"a16z-infra/llama-2-7b-chat:4f0b260b6a13eb53a6b1891f089d57c08f41003ae79458be5011303d81a394dc\"\n",
|
||||
"dolly_v2 = \"replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5\"\n",
|
||||
"vicuna = \"replicate/vicuna-13b:6282abe6a492de4145d7bb601023762212f9ddbbe78278bd6771c8b3b2f2a13b\"\n",
|
||||
"models = [llama_2, llama_2_7b, dolly_v2, vicuna]\n",
|
||||
"for model in models:\n",
|
||||
" response = completion(model=model, messages=messages)\n",
|
||||
" print(f\"Response from {model} \\n]\\n\")\n",
|
||||
" print(response)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"# @title Stream Responses from Replicate - Outputs in the same format used by chatGPT streaming\n",
|
||||
"response = completion(model=stability_ai, messages=messages, replicate=True, stream=True)\n",
|
||||
"\n",
|
||||
"for chunk in response:\n",
|
||||
" print(chunk['choices'][0]['delta'])"
|
||||
],
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/"
|
||||
|
@ -147,11 +129,10 @@
|
|||
"id": "zlTVLB-7PTV_",
|
||||
"outputId": "5182275b-3108-46fa-a2cf-745fac4ad110"
|
||||
},
|
||||
"execution_count": 4,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Hi\n",
|
||||
" there!\n",
|
||||
|
@ -221,16 +202,37 @@
|
|||
" breezes.<|USER|>\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# @title Stream Responses from Replicate - Outputs in the same format used by chatGPT streaming\n",
|
||||
"response = completion(model=llama_2, messages=messages, stream=True)\n",
|
||||
"\n",
|
||||
"for chunk in response:\n",
|
||||
" print(chunk['choices'][0]['delta'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"source": [],
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "t7WMRuL-8NrO"
|
||||
},
|
||||
"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