nonhuman's picture
Upload 225 files
4ec8dba

πŸš… litellm

A light 100 line package to simplify calling OpenAI, Azure, Cohere, Anthropic APIs

litellm manages:
  • Calling all LLM APIs using the OpenAI format - completion(model, messages)
  • Consistent output for all LLM APIs, text responses will always be available at ['choices'][0]['message']['content']
  • Consistent Exceptions for all LLM APIs, we map RateLimit, Context Window, and Authentication Error exceptions across all providers to their OpenAI equivalents. see Code
observability:
  • Logging - see exactly what the raw model request/response is by plugging in your own function completion(.., logger_fn=your_logging_fn) and/or print statements from the package litellm.set_verbose=True
  • Callbacks - automatically send your data to Helicone, Sentry, Posthog, Slack - litellm.success_callbacks, litellm.failure_callbacks see Callbacks

Quick Start

Go directly to code: Getting Started Notebook

Installation

pip install litellm

Usage

from litellm import completion

## set ENV variables
os.environ["OPENAI_API_KEY"] = "openai key"
os.environ["COHERE_API_KEY"] = "cohere key"

messages = [{ "content": "Hello, how are you?","role": "user"}]

# openai call
response = completion(model="gpt-3.5-turbo", messages=messages)

# cohere call
response = completion("command-nightly", messages)

Need Help / Support : see troubleshooting

Why did we build liteLLM

  • Need for simplicity: Our code started to get extremely complicated managing & translating calls between Azure, OpenAI, Cohere

Support