Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(main.py): support calling text completione endpoint for openai compatible providers #2709

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions litellm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def identify(event_details):
"xinference",
"together_ai",
"fireworks_ai",
"custom_openai",
]


Expand Down
21 changes: 13 additions & 8 deletions litellm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ def completion(
eos_token = kwargs.get("eos_token", None)
preset_cache_key = kwargs.get("preset_cache_key", None)
hf_model_name = kwargs.get("hf_model_name", None)
### TEXT COMPLETION CALLS ###
text_completion = kwargs.get("text_completion", False)
### ASYNC CALLS ###
acompletion = kwargs.get("acompletion", False)
client = kwargs.get("client", None)
Expand Down Expand Up @@ -602,6 +604,7 @@ def completion(
"cache",
"no-log",
"base_model",
"text_completion",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why text_completion ?

The health check does honor mode: completion already when set as below:

model_list:
 - model_name: starcoder2-3b
    litellm_params:
      api_base: https://vllm.example.com/v1
      api_key: "os.environ/API_KEY"
      model: openai/starcoder2-3b
      stream_timeout: 5
    model_info:
      mode: completion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with text_completion: true:

    litellm_params:
      model: openai/mistral-7b-instruct
      api_base: https://api.siemens.com/llm/v1
      api_key: "os.environ/API_KEY"
      stream_timeout: 5
      text_completion: true

still the same

]
default_params = openai_params + litellm_params
non_default_params = {
Expand Down Expand Up @@ -914,15 +917,11 @@ def completion(
)
elif (
model in litellm.open_ai_chat_completion_models
or custom_llm_provider == "custom_openai"
or custom_llm_provider == "deepinfra"
or custom_llm_provider == "perplexity"
or custom_llm_provider == "groq"
or custom_llm_provider == "anyscale"
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 (
custom_llm_provider in litellm.openai_compatible_providers
and text_completion == False
)
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
Expand Down Expand Up @@ -998,6 +997,10 @@ def completion(
)
elif (
custom_llm_provider == "text-completion-openai"
or (
custom_llm_provider in litellm.openai_compatible_providers
and text_completion == True
)
or "ft:babbage-002" in model
or "ft:davinci-002" in model # support for finetuned completion models
):
Expand Down Expand Up @@ -2943,6 +2946,7 @@ async def atext_completion(*args, **kwargs):
or custom_llm_provider == "huggingface"
or custom_llm_provider == "ollama"
or custom_llm_provider == "vertex_ai"
or custom_llm_provider in litellm.openai_compatible_providers
): # currently implemented aiohttp calls for just azure and openai, soon all.
# Await normally
response = await loop.run_in_executor(None, func_with_context)
Expand Down Expand Up @@ -3156,6 +3160,7 @@ def process_prompt(i, individual_prompt):
# default case, non OpenAI requests go through here
messages = [{"role": "system", "content": prompt}]
kwargs.pop("prompt", None)
kwargs["text_completion"] = True
response = completion(
model=model,
messages=messages,
Expand Down
Loading