Merge pull request #2535 from BerriAI/litellm_fireworks_ai_support

feat(utils.py): add native fireworks ai support
This commit is contained in:
Krish Dholakia 2024-03-15 10:02:53 -07:00 committed by GitHub
commit 32ca306123
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,53 @@
# Fireworks AI
https://fireworks.ai/
**We support ALL Fireworks AI models, just set `fireworks_ai/` as a prefix when sending completion requests**
## API Key
```python
# env variable
os.environ['FIREWORKS_AI_API_KEY']
```
## Sample Usage
```python
from litellm import completion
import os
os.environ['FIREWORKS_AI_API_KEY'] = ""
response = completion(
model="fireworks_ai/mixtral-8x7b-instruct",
messages=[
{"role": "user", "content": "hello from litellm"}
],
)
print(response)
```
## Sample Usage - Streaming
```python
from litellm import completion
import os
os.environ['FIREWORKS_AI_API_KEY'] = ""
response = completion(
model="fireworks_ai/mixtral-8x7b-instruct",
messages=[
{"role": "user", "content": "hello from litellm"}
],
stream=True
)
for chunk in response:
print(chunk)
```
## Supported Models - ALL Fireworks AI Models Supported!
We support ALL Fireworks AI models, just set `fireworks_ai/` as a prefix when sending completion requests
| Model Name | Function Call |
|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| mixtral-8x7b-instruct | `completion(model="fireworks_ai/mixtral-8x7b-instruct", messages)` |
| firefunction-v1 | `completion(model="fireworks_ai/firefunction-v1", messages)` |
| llama-v2-70b-chat | `completion(model="fireworks_ai/llama-v2-70b-chat", messages)` |

View file

@ -138,6 +138,7 @@ const sidebars = {
"providers/ollama",
"providers/perplexity",
"providers/groq",
"providers/fireworks_ai",
"providers/vllm",
"providers/xinference",
"providers/cloudflare_workers",

View file

@ -328,6 +328,7 @@ openai_compatible_providers: List = [
"perplexity",
"xinference",
"together_ai",
"fireworks_ai",
]
@ -479,6 +480,7 @@ provider_list: List = [
"voyage",
"cloudflare",
"xinference",
"fireworks_ai",
"custom", # custom apis
]

View file

@ -892,6 +892,7 @@ def completion(
or custom_llm_provider == "mistral"
or custom_llm_provider == "openai"
or custom_llm_provider == "together_ai"
or custom_llm_provider in litellm.openai_compatible_providers
or "ft:gpt-3.5-turbo" in model # finetune gpt-3.5-turbo
): # allow user to make an openai call with a custom base
# note: if a user sets a custom base - we should ensure this works
@ -2394,6 +2395,7 @@ async def aembedding(*args, **kwargs):
or custom_llm_provider == "deepinfra"
or custom_llm_provider == "perplexity"
or custom_llm_provider == "groq"
or custom_llm_provider == "fireworks_ai"
or custom_llm_provider == "ollama"
or custom_llm_provider == "vertex_ai"
): # currently implemented aiohttp calls for just azure and openai, soon all.
@ -2893,6 +2895,7 @@ async def atext_completion(*args, **kwargs):
or custom_llm_provider == "deepinfra"
or custom_llm_provider == "perplexity"
or custom_llm_provider == "groq"
or custom_llm_provider == "fireworks_ai"
or custom_llm_provider == "text-completion-openai"
or custom_llm_provider == "huggingface"
or custom_llm_provider == "ollama"

View file

@ -529,6 +529,25 @@ def test_completion_azure_gpt4_vision():
# test_completion_azure_gpt4_vision()
def test_completion_fireworks_ai():
try:
litellm.set_verbose = True
messages = [
{"role": "system", "content": "You're a good bot"},
{
"role": "user",
"content": "Hey",
},
]
response = completion(
model="fireworks_ai/accounts/fireworks/models/mixtral-8x7b-instruct",
messages=messages,
)
print(response)
except Exception as e:
pytest.fail(f"Error occurred: {e}")
@pytest.mark.skip(reason="this test is flaky")
def test_completion_perplexity_api():
try:

View file

@ -5375,6 +5375,17 @@ def get_llm_provider(
# groq is openai compatible, we just need to set this to custom_openai and have the api_base be https://api.groq.com/openai/v1
api_base = "https://api.groq.com/openai/v1"
dynamic_api_key = get_secret("GROQ_API_KEY")
elif custom_llm_provider == "fireworks_ai":
# fireworks is openai compatible, we just need to set this to custom_openai and have the api_base be https://api.groq.com/openai/v1
if not model.startswith("accounts/fireworks/models"):
model = f"accounts/fireworks/models/{model}"
api_base = "https://api.fireworks.ai/inference/v1"
dynamic_api_key = (
get_secret("FIREWORKS_API_KEY")
or get_secret("FIREWORKS_AI_API_KEY")
or get_secret("FIREWORKSAI_API_KEY")
or get_secret("FIREWORKS_AI_TOKEN")
)
elif custom_llm_provider == "mistral":
# mistral is openai compatible, we just need to set this to custom_openai and have the api_base be https://api.mistral.ai
api_base = (