From c4a595d3527fc59cc714e8115ea3bb14e937e5a4 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 4 Oct 2023 14:38:00 -0700 Subject: [PATCH] add batch completion rate limits docs --- docs/my-website/docs/completion/batching.md | 31 +++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/my-website/docs/completion/batching.md b/docs/my-website/docs/completion/batching.md index 334e8b1156..6d56608604 100644 --- a/docs/my-website/docs/completion/batching.md +++ b/docs/my-website/docs/completion/batching.md @@ -1,9 +1,36 @@ -# Batching Completion() Calls +# Batching Completion(), Handling Rate Limits LiteLLM allows you to: -* Send many completion calls to 1 model +* Send many completion calls to 1 model [while handling rate limits] * Send 1 completion call to many models: Return Fastest Response * Send 1 completion call to many models: Return All Responses +## Handling Rate Limits with batch completion +## Batch Completion with only 1 model +### Usage +```python +import asyncio +from litellm import batch_completion_rate_limits + +# kwargs to litellm.completion +jobs = [ + {"model": "gpt-4", "messages": [{"content": "Please provide a summary of the latest scientific discoveries."*500, "role": "user"}]}, + {"model": "gpt-4", "messages": [{"content": "Please provide a summary of the latest scientific discoveries."*800, "role": "user"}]}, + {"model": "gpt-4", "messages": [{"content": "Please provide a summary of the latest scientific discoveries."*900, "role": "user"}]}, + {"model": "gpt-4", "messages": [{"content": "Please provide a summary of the latest scientific discoveries."*900, "role": "user"}]}, + {"model": "gpt-4", "messages": [{"content": "Please provide a summary of the latest scientific discoveries."*900, "role": "user"}]} +] + +asyncio.run( + batch_completion_rate_limits( + jobs = jobs, + api_key=os.environ['OPENAI_API_KEY'], # pass your api key for your selected model + max_requests_per_minute=60, + max_tokens_per_minute=40000 + ) +) + +``` + ## Send multiple completion calls to 1 model In the batch_completion method, you provide a list of `messages` where each sub-list of messages is passed to `litellm.completion()`, allowing you to process multiple prompts efficiently in a single API call.