Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
coderai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
coderai
Commits
0ab10131
Commit
0ab10131
authored
Mar 16, 2026
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always use openai/{provider}/{model} format with coderai default
parent
c8cc0048
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
40 deletions
+46
-40
litellm.py
codai/openai/litellm.py
+46
-40
No files found.
codai/openai/litellm.py
View file @
0ab10131
...
@@ -92,17 +92,16 @@ class LiteLLMBackend:
...
@@ -92,17 +92,16 @@ class LiteLLMBackend:
"""
"""
Normalize model name for litellm.
Normalize model name for litellm.
LiteLLM requires model names in format "provider/model" e.g., "openai/gpt-3.5-turbo".
Always formats as: openai/{provider}/{model}
If no provider is specified, add a default provider based on common patterns.
- If provider is detected from known patterns, use it
- If model has / (e.g. HuggingFace org/model), detect or default to huggingface
Also handles model aliases (default, image, etc.) by resolving them to
- If provider unknown, use "coderai" as default
the actual model name from the model manager.
Args:
Args:
model: Original model name (may be an alias)
model: Original model name (may be an alias)
Returns:
Returns:
Normalized model name
with provider prefix
Normalized model name
: openai/{provider}/{model}
"""
"""
print
(
f
"DEBUG litellm: normalize_model_name input: {model}"
)
print
(
f
"DEBUG litellm: normalize_model_name input: {model}"
)
...
@@ -110,54 +109,59 @@ class LiteLLMBackend:
...
@@ -110,54 +109,59 @@ class LiteLLMBackend:
resolved_model
=
self
.
_resolve_model_alias
(
model
)
resolved_model
=
self
.
_resolve_model_alias
(
model
)
print
(
f
"DEBUG litellm: After alias resolution: {resolved_model}"
)
print
(
f
"DEBUG litellm: After alias resolution: {resolved_model}"
)
# If already has a provider prefix (contains /), check if it's valid
# Known litellm providers
known_providers
=
[
'openai'
,
'anthropic'
,
'gemini'
,
'meta'
,
'mistral'
,
'cohere'
,
'ai21'
,
'bedrock'
,
'azure'
,
'ollama'
,
'huggingface'
,
'deepseek'
,
'qwen'
,
'sagemaker'
,
'vertex'
,
'aiplatform'
,
'vllm'
,
'tgi'
]
# Check if there's an existing provider prefix (contains /)
if
'/'
in
resolved_model
:
if
'/'
in
resolved_model
:
# Check if the prefix is a known litellm provider
parts
=
resolved_model
.
split
(
'/'
)
known_providers
=
[
'openai'
,
'anthropic'
,
'gemini'
,
'meta'
,
'mistral'
,
'cohere'
,
prefix
=
parts
[
0
]
.
lower
()
'ai21'
,
'bedrock'
,
'azure'
,
'ollama'
,
'huggingface'
,
'deepseek'
,
'qwen'
,
'sagemaker'
,
'vertex'
,
'aiplatform'
,
'vllm'
,
'tgi'
]
prefix
=
resolved_model
.
split
(
'/'
)[
0
]
.
lower
()
if
prefix
in
known_providers
:
if
prefix
in
known_providers
:
print
(
f
"DEBUG litellm: Known provider prefix, returning: {resolved_model}"
)
# Valid provider, reformat as openai/{provider}/{model}
return
resolved_model
model_part
=
'/'
.
join
(
parts
[
1
:])
# Otherwise, it's likely a HuggingFace org/model path, add huggingface prefix
result
=
f
"openai/{prefix}/{model_part}"
result
=
f
"huggingface/{resolved_model}"
print
(
f
"DEBUG litellm: Known provider '{prefix}', returning: {result}"
)
print
(
f
"DEBUG litellm: HuggingFace org/model detected, adding huggingface prefix: {result}"
)
return
result
# Otherwise, it's likely a HuggingFace org/model path
result
=
f
"openai/huggingface/{resolved_model}"
print
(
f
"DEBUG litellm: HuggingFace org/model, returning: {result}"
)
return
result
return
result
#
Common model name patterns and their providers
#
No provider prefix - detect provider from model name pattern
provider_map
=
{
provider_map
=
{
# OpenAI models
# OpenAI models
'gpt-'
:
'openai
/
'
,
'gpt-'
:
'openai'
,
'gpt3'
:
'openai
/
'
,
'gpt3'
:
'openai'
,
'gpt4'
:
'openai
/
'
,
'gpt4'
:
'openai'
,
# Anthropic models
# Anthropic models
'claude'
:
'anthropic
/
'
,
'claude'
:
'anthropic'
,
# Google models
# Google models
'gemini'
:
'gemini
/
'
,
'gemini'
:
'gemini'
,
'palm'
:
'gemini
/
'
,
'palm'
:
'gemini'
,
# Meta/Llama models
# Meta/Llama models
'llama'
:
'meta/'
,
'llama'
:
'meta'
,
'llama2'
:
'meta/'
,
'llama2'
:
'meta'
,
'llama3'
:
'meta/'
,
'llama3'
:
'meta'
,
'mistral'
:
'mistral/'
,
# Mistral models
# Mistral models
'mistral'
:
'mistral'
,
# AWS models
# AWS models
'amazon'
:
'bedrock
/
'
,
'amazon'
:
'bedrock'
,
# Azure models
# Azure models
'azure'
:
'azure
/
'
,
'azure'
:
'azure'
,
# Cohere models
# Cohere models
'cohere'
:
'cohere
/
'
,
'cohere'
:
'cohere'
,
# AI21 models
# AI21 models
'ai21'
:
'ai21
/
'
,
'ai21'
:
'ai21'
,
# Local/Ollama models
# Local/Ollama models
'ollama'
:
'ollama
/
'
,
'ollama'
:
'ollama'
,
# HuggingFace models
# HuggingFace models
'hf'
:
'huggingface
/
'
,
'hf'
:
'huggingface'
,
# DeepSeek models
# DeepSeek models
'deepseek'
:
'deepseek
/
'
,
'deepseek'
:
'deepseek'
,
# Qwen models
# Qwen models
'qwen'
:
'qwen
/
'
,
'qwen'
:
'qwen'
,
}
}
model_lower
=
resolved_model
.
lower
()
model_lower
=
resolved_model
.
lower
()
...
@@ -165,11 +169,13 @@ class LiteLLMBackend:
...
@@ -165,11 +169,13 @@ class LiteLLMBackend:
# Check for known patterns
# Check for known patterns
for
pattern
,
provider
in
provider_map
.
items
():
for
pattern
,
provider
in
provider_map
.
items
():
if
model_lower
.
startswith
(
pattern
):
if
model_lower
.
startswith
(
pattern
):
return
f
"{provider}{resolved_model}"
result
=
f
"openai/{provider}/{resolved_model}"
print
(
f
"DEBUG litellm: Detected provider '{provider}', returning: {result}"
)
return
result
# Default:
assume OpenAI-compatible local model
# Default:
use "coderai" as provider for unknown models
result
=
f
"openai/{resolved_model}"
result
=
f
"openai/
coderai/
{resolved_model}"
print
(
f
"DEBUG litellm: U
sing default provider
, returning: {result}"
)
print
(
f
"DEBUG litellm: U
nknown provider, using 'coderai'
, returning: {result}"
)
return
result
return
result
def
_resolve_model_alias
(
self
,
model
:
str
)
->
str
:
def
_resolve_model_alias
(
self
,
model
:
str
)
->
str
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment