Merge pull request #9102 from BerriAI/litellm_add_atext_completion_on_ui

(Feat) - Allow adding Text-Completion OpenAI models through UI
This commit is contained in:
Ishaan Jaff 2025-03-10 18:11:00 -07:00 committed by GitHub
commit 6dcf64918c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 39 deletions

View file

@ -3900,42 +3900,19 @@ async def atext_completion(
ctx = contextvars.copy_context()
func_with_context = partial(ctx.run, func)
_, custom_llm_provider, _, _ = get_llm_provider(
model=model, api_base=kwargs.get("api_base", None)
)
if (
custom_llm_provider == "openai"
or custom_llm_provider == "azure"
or custom_llm_provider == "azure_text"
or custom_llm_provider == "custom_openai"
or custom_llm_provider == "anyscale"
or custom_llm_provider == "mistral"
or custom_llm_provider == "openrouter"
or custom_llm_provider == "deepinfra"
or custom_llm_provider == "perplexity"
or custom_llm_provider == "groq"
or custom_llm_provider == "nvidia_nim"
or custom_llm_provider == "cerebras"
or custom_llm_provider == "sambanova"
or custom_llm_provider == "ai21_chat"
or custom_llm_provider == "ai21"
or custom_llm_provider == "volcengine"
or custom_llm_provider == "text-completion-codestral"
or custom_llm_provider == "deepseek"
or custom_llm_provider == "text-completion-openai"
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)
if asyncio.iscoroutine(response):
response = await response
init_response = await loop.run_in_executor(None, func_with_context)
if isinstance(init_response, dict) or isinstance(
init_response, TextCompletionResponse
): ## CACHING SCENARIO
if isinstance(init_response, dict):
response = TextCompletionResponse(**init_response)
else:
response = init_response
elif asyncio.iscoroutine(init_response):
response = await init_response
else:
# Call the synchronous function using run_in_executor
response = await loop.run_in_executor(None, func_with_context)
response = init_response # type: ignore
if (
kwargs.get("stream", False) is True
or isinstance(response, TextCompletionStreamWrapper)

View file

@ -23,7 +23,7 @@ const ProviderSpecificFields: React.FC<ProviderSpecificFieldsProps> = ({
console.log(`type of selectedProviderEnum: ${typeof selectedProviderEnum}`);
return (
<>
{selectedProviderEnum === Providers.OpenAI && (
{selectedProviderEnum === Providers.OpenAI || selectedProviderEnum === Providers.OpenAI_Text && (
<>
<Form.Item
label="API Base"
@ -99,7 +99,8 @@ const ProviderSpecificFields: React.FC<ProviderSpecificFieldsProps> = ({
{(selectedProviderEnum === Providers.Azure ||
selectedProviderEnum === Providers.Azure_AI_Studio ||
selectedProviderEnum === Providers.OpenAI_Compatible
selectedProviderEnum === Providers.OpenAI_Compatible ||
selectedProviderEnum === Providers.OpenAI_Text_Compatible
) && (
<Form.Item
rules={[{ required: true, message: "Required" }]}

View file

@ -1,7 +1,11 @@
import OpenAI from "openai";
import React from "react";
export enum Providers {
OpenAI = "OpenAI",
OpenAI_Compatible = "OpenAI-Compatible Endpoints (Together AI, etc.)",
OpenAI_Text = "OpenAI Text Completion",
OpenAI_Text_Compatible = "OpenAI-Compatible Text Completion Models (Together AI, etc.)",
Azure = "Azure",
Azure_AI_Studio = "Azure AI Foundry (Studio)",
Anthropic = "Anthropic",
@ -11,7 +15,6 @@ export enum Providers {
Groq = "Groq",
MistralAI = "Mistral AI",
Deepseek = "Deepseek",
OpenAI_Compatible = "OpenAI-Compatible Endpoints (Together AI, etc.)",
Cohere = "Cohere",
Databricks = "Databricks",
Ollama = "Ollama",
@ -28,6 +31,7 @@ export enum Providers {
export const provider_map: Record<string, string> = {
OpenAI: "openai",
OpenAI_Text: "text-completion-openai",
Azure: "azure",
Azure_AI_Studio: "azure_ai",
Anthropic: "anthropic",
@ -37,6 +41,7 @@ export const provider_map: Record<string, string> = {
MistralAI: "mistral",
Cohere: "cohere_chat",
OpenAI_Compatible: "openai",
OpenAI_Text_Compatible: "text-completion-openai",
Vertex_AI: "vertex_ai",
Databricks: "databricks",
xAI: "xai",
@ -53,6 +58,9 @@ export const provider_map: Record<string, string> = {
export const providerLogoMap: Record<string, string> = {
[Providers.OpenAI]: "https://artificialanalysis.ai/img/logos/openai_small.svg",
[Providers.OpenAI_Text]: "https://artificialanalysis.ai/img/logos/openai_small.svg",
[Providers.OpenAI_Text_Compatible]: "https://artificialanalysis.ai/img/logos/openai_small.svg",
[Providers.OpenAI_Compatible]: "https://artificialanalysis.ai/img/logos/openai_small.svg",
[Providers.Azure]: "https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",
[Providers.Azure_AI_Studio]: "https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg",
[Providers.Anthropic]: "https://artificialanalysis.ai/img/logos/anthropic_small.svg",
@ -61,7 +69,6 @@ export const providerLogoMap: Record<string, string> = {
[Providers.Groq]: "https://artificialanalysis.ai/img/logos/groq_small.png",
[Providers.MistralAI]: "https://artificialanalysis.ai/img/logos/mistral_small.png",
[Providers.Cohere]: "https://artificialanalysis.ai/img/logos/cohere_small.png",
[Providers.OpenAI_Compatible]: "https://upload.wikimedia.org/wikipedia/commons/4/4e/OpenAI_Logo.svg",
[Providers.Vertex_AI]: "https://artificialanalysis.ai/img/logos/google_small.svg",
[Providers.Databricks]: "https://artificialanalysis.ai/img/logos/databricks_small.png",
[Providers.Ollama]: "https://artificialanalysis.ai/img/logos/ollama_small.svg",