litellm/README.md

123 lines
4.6 KiB
Markdown
Raw Normal View History

2023-08-24 22:51:02 +08:00
<h1 align="center">
2023-08-24 23:32:50 +08:00
🚅 LiteLLM
</h1>
<p align="center">
2023-08-29 00:25:55 +08:00
<p align="center">Call all LLM APIs using the OpenAI format [Anthropic, Huggingface, Cohere, TogetherAI, Azure, OpenAI, etc.]</p>
2023-08-24 23:32:50 +08:00
</p>
2023-08-24 22:51:02 +08:00
2023-08-24 22:55:02 +08:00
<h4 align="center">
2023-08-24 23:32:50 +08:00
<a href="https://pypi.org/project/litellm/" target="_blank">
2023-08-24 22:55:02 +08:00
<img src="https://img.shields.io/pypi/v/litellm.svg" alt="PyPI Version">
</a>
2023-08-24 23:32:50 +08:00
<a href="https://pypi.org/project/litellm/0.1.1/" target="_blank">
2023-08-24 22:55:02 +08:00
<img src="https://img.shields.io/badge/stable%20version-v0.1.424-blue?color=green&link=https://pypi.org/project/litellm/0.1.1/" alt="Stable Version">
</a>
2023-08-24 23:32:50 +08:00
<a href="https://dl.circleci.com/status-badge/redirect/gh/BerriAI/litellm/tree/main" target="_blank">
2023-08-24 22:55:02 +08:00
<img src="https://dl.circleci.com/status-badge/img/gh/BerriAI/litellm/tree/main.svg?style=svg" alt="CircleCI">
</a>
<img src="https://img.shields.io/pypi/dm/litellm" alt="Downloads">
2023-08-24 23:32:50 +08:00
<a href="https://discord.gg/wuPM9dRgDw" target="_blank">
2023-08-24 22:58:42 +08:00
<img src="https://dcbadge.vercel.app/api/server/wuPM9dRgDw?style=flat">
</a>
2023-08-27 05:04:51 +08:00
<a href="https://www.ycombinator.com/companies/berriai">
<img src="https://img.shields.io/badge/Y%20Combinator-W23-orange?style=flat-square" alt="Y Combinator W23">
</a>
2023-09-09 05:49:40 +08:00
<a href="https://github.com/BerriAI/litellm/issues">
2023-09-09 00:20:50 +08:00
<img src="https://img.shields.io/github/commit-activity/m/BerriAI/litellm" alt="git commit activity" />
</a>
2023-08-24 22:55:02 +08:00
</h4>
2023-07-31 22:35:27 +08:00
2023-08-24 23:19:57 +08:00
<h4 align="center">
2023-08-25 01:01:01 +08:00
<a target="_blank" href="https://colab.research.google.com/github/BerriAI/litellm/blob/main/cookbook/liteLLM_OpenAI.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
</a>
2023-08-24 23:19:57 +08:00
</h4>
2023-08-24 23:32:50 +08:00
2023-08-24 23:28:35 +08:00
<h4 align="center">
2023-09-09 05:49:05 +08:00
<a href="https://docs.litellm.ai/docs/providers" target="_blank">100+ Supported Models</a> |
2023-08-24 23:32:50 +08:00
<a href="https://docs.litellm.ai/docs/" target="_blank">Docs</a> |
<a href="https://litellm.ai/playground" target="_blank">Demo Website</a>
2023-08-24 23:28:35 +08:00
</h4>
2023-08-24 23:32:50 +08:00
2023-08-24 23:22:12 +08:00
LiteLLM manages
2023-08-24 23:19:57 +08:00
2023-08-24 23:29:06 +08:00
- Translating inputs to the provider's completion and embedding endpoints
2023-09-09 06:03:22 +08:00
- Guarantees [consistent output](https://docs.litellm.ai/docs/completion/output), text responses will always be available at `['choices'][0]['message']['content']`
2023-09-09 06:04:17 +08:00
- Exception mapping - common exceptions across providers are mapped to the OpenAI exception types
2023-09-03 08:42:59 +08:00
2023-09-03 08:43:21 +08:00
**🤝 Schedule a 1-on-1 Session:** Book a [1-on-1 session](https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat) with Krrish and Ishaan, the founders, to discuss any issues, provide feedback, or explore how we can improve LiteLLM for you.
2023-08-25 03:31:39 +08:00
# Usage
2023-08-24 23:43:18 +08:00
2023-08-25 01:01:01 +08:00
<a target="_blank" href="https://colab.research.google.com/github/BerriAI/litellm/blob/main/cookbook/liteLLM_OpenAI.ipynb">
2023-08-24 23:19:57 +08:00
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
</a>
2023-07-31 22:58:10 +08:00
```
pip install litellm
```
2023-07-27 08:44:43 +08:00
```python
2023-07-27 08:46:23 +08:00
from litellm import completion
2023-08-30 01:39:33 +08:00
import os
2023-08-13 11:05:03 +08:00
## set ENV variables
os.environ["OPENAI_API_KEY"] = "openai key"
os.environ["COHERE_API_KEY"] = "cohere key"
2023-08-25 00:42:58 +08:00
os.environ["ANTHROPIC_API_KEY"] = "anthropic key"
2023-07-27 08:46:23 +08:00
2023-07-27 08:44:34 +08:00
messages = [{ "content": "Hello, how are you?","role": "user"}]
2023-07-27 08:46:23 +08:00
2023-07-27 08:44:34 +08:00
# openai call
response = completion(model="gpt-3.5-turbo", messages=messages)
# cohere call
2023-08-25 00:42:58 +08:00
response = completion(model="command-nightly", messages=messages)
# anthropic
response = completion(model="claude-2", messages=messages)
2023-07-27 08:44:34 +08:00
```
2023-08-01 23:18:44 +08:00
Stable version
```
2023-08-18 20:25:30 +08:00
pip install litellm==0.1.424
2023-08-01 23:18:44 +08:00
```
2023-07-27 08:44:34 +08:00
2023-08-25 03:31:39 +08:00
## Streaming
2023-08-06 06:10:49 +08:00
liteLLM supports streaming the model response back, pass `stream=True` to get a streaming iterator in response.
2023-08-16 00:49:44 +08:00
Streaming is supported for OpenAI, Azure, Anthropic, Huggingface models
2023-08-06 06:12:34 +08:00
```python
2023-08-06 06:10:49 +08:00
response = completion(model="gpt-3.5-turbo", messages=messages, stream=True)
for chunk in response:
print(chunk['choices'][0]['delta'])
2023-08-09 07:22:18 +08:00
2023-08-09 07:19:34 +08:00
# claude 2
2023-08-09 07:23:59 +08:00
result = completion('claude-2', messages, stream=True)
2023-08-09 07:19:34 +08:00
for chunk in result:
print(chunk['choices'][0]['delta'])
2023-08-06 06:10:49 +08:00
```
2023-08-28 23:59:34 +08:00
# Support / talk with founders
2023-08-24 23:43:18 +08:00
- [Schedule Demo 👋](https://calendly.com/d/4mp-gd3-k5k/berriai-1-1-onboarding-litellm-hosted-version)
2023-08-09 21:09:28 +08:00
- [Community Discord 💭](https://discord.gg/wuPM9dRgDw)
- Our numbers 📞 +1 (770) 8783-106 / +1 (412) 618-6238
- Our emails ✉️ ishaan@berri.ai / krrish@berri.ai
2023-07-29 00:11:27 +08:00
2023-08-28 23:59:34 +08:00
# Why did we build this
2023-08-06 06:10:49 +08:00
- **Need for simplicity**: Our code started to get extremely complicated managing & translating calls between Azure, OpenAI, Cohere
2023-08-28 23:50:12 +08:00
2023-08-28 23:59:34 +08:00
# Contributors
2023-08-28 23:50:12 +08:00
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
2023-08-28 23:56:19 +08:00
<a href="https://github.com/BerriAI/litellm/graphs/contributors">
<img src="https://contrib.rocks/image?repo=BerriAI/litellm" />
</a>