feat(_init_.py): add new 'openai_text_completion_compatible_providers' list

Fixes https://github.com/BerriAI/litellm/issues/5558

Handles correctly routing fireworks ai calls when done via text completions
This commit is contained in:
Krrish Dholakia 2024-09-07 12:02:57 -07:00
parent be1fe015de
commit 67b8043e64
3 changed files with 22 additions and 3 deletions

View file

@ -483,7 +483,12 @@ openai_compatible_providers: List = [
"azure_ai",
"github",
]
openai_text_completion_compatible_providers: List = (
[ # providers that support `/v1/completions`
"together_ai",
"fireworks_ai",
]
)
# well supported replicate llms
replicate_models: List = [

View file

@ -1209,6 +1209,9 @@ def completion(
custom_llm_provider == "text-completion-openai"
or "ft:babbage-002" in model
or "ft:davinci-002" in model # support for finetuned completion models
or custom_llm_provider
in litellm.openai_text_completion_compatible_providers
and kwargs.get("text_completion") is True
):
openai.api_type = "openai"
@ -4099,8 +4102,8 @@ def text_completion(
kwargs.pop("prompt", None)
if (
_model is not None and custom_llm_provider == "openai"
if _model is not None and (
custom_llm_provider == "openai"
): # for openai compatible endpoints - e.g. vllm, call the native /v1/completions endpoint for text completion calls
if _model not in litellm.open_ai_chat_completion_models:
model = "text-completion-openai/" + _model

View file

@ -4239,3 +4239,14 @@ def test_completion_vllm():
mock_call.assert_called_once()
assert "hello" in mock_call.call_args.kwargs["extra_body"]
def test_completion_fireworks_ai_multiple_choices():
litellm.set_verbose = True
response = litellm.text_completion(
model="fireworks_ai/llama-v3p1-8b-instruct",
prompt=["halo", "hi", "halo", "hi"],
)
print(response.choices)
assert len(response.choices) == 4