forked from BerriAI/litellm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c12ceb6
commit 670f51e
Showing
3 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Getting Started | ||
|
||
LiteLLM simplifies LLM API calls by mapping them all to the [OpenAI ChatCompletion format](https://platform.openai.com/docs/api-reference/chat). | ||
|
||
## basic usage | ||
|
||
```python | ||
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) | ||
``` | ||
|
||
More details 👉 | ||
* [Completion() function details](./completion/) | ||
* [Supported models / providers](./providers/) | ||
|
||
## streaming | ||
|
||
Same example from before. Just pass in `stream=True` in the completion args. | ||
```python | ||
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, stream=True) | ||
|
||
# cohere call | ||
response = completion("command-nightly", messages, stream=True) | ||
``` | ||
|
||
More details 👉 | ||
* [streaming + async](./completion/stream.md) | ||
* [tutorial for streaming Llama2 on TogetherAI](./tutorials/TogetherAI_liteLLM.md) | ||
|
||
## exception handling | ||
|
||
LiteLLM maps exceptions across all supported providers to the OpenAI exceptions. All our exceptions inherit from OpenAI's exception types, so any error-handling you have for that, should work out of the box with LiteLLM. | ||
|
||
```python | ||
from openai.errors import AuthenticationError | ||
from litellm import completion | ||
|
||
os.environ["ANTHROPIC_API_KEY"] = "bad-key" | ||
try: | ||
# some code | ||
completion(model="claude-instant-1", messages=[{"role": "user", "content": "Hey, how's it going?"}]) | ||
except AuthenticationError as e: | ||
print(e.llm_provider) | ||
``` | ||
|
||
More details 👉 | ||
* [exception mapping](./exception_mapping.md) | ||
* [retries + model fallbacks for completion()](./completion/reliable_completions.md) | ||
* [tutorial for model fallbacks with completion()](./tutorials/fallbacks.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters