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
Show 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:
"""
Normalize model name for litellm.
LiteLLM requires model names in format "provider/model" e.g., "openai/gpt-3.5-turbo".
If no provider is specified, add a default provider based on common patterns.
Also handles model aliases (default, image, etc.) by resolving them to
the actual model name from the model manager.
Always formats as: openai/{provider}/{model}
- If provider is detected from known patterns, use it
- If model has / (e.g. HuggingFace org/model), detect or default to huggingface
- If provider unknown, use "coderai" as default
Args:
model: Original model name (may be an alias)
Returns:
Normalized model name
with provider prefix
Normalized model name
: openai/{provider}/{model}
"""
print
(
f
"DEBUG litellm: normalize_model_name input: {model}"
)
...
...
@@ -110,54 +109,59 @@ class LiteLLMBackend:
resolved_model
=
self
.
_resolve_model_alias
(
model
)
print
(
f
"DEBUG litellm: After alias resolution: {resolved_model}"
)
# If already has a provider prefix (contains /), check if it's valid
if
'/'
in
resolved_model
:
# Check if the prefix is a known litellm provider
# Known litellm providers
known_providers
=
[
'openai'
,
'anthropic'
,
'gemini'
,
'meta'
,
'mistral'
,
'cohere'
,
'ai21'
,
'bedrock'
,
'azure'
,
'ollama'
,
'huggingface'
,
'deepseek'
,
'qwen'
,
'sagemaker'
,
'vertex'
,
'aiplatform'
,
'vllm'
,
'tgi'
]
prefix
=
resolved_model
.
split
(
'/'
)[
0
]
.
lower
()
# Check if there's an existing provider prefix (contains /)
if
'/'
in
resolved_model
:
parts
=
resolved_model
.
split
(
'/'
)
prefix
=
parts
[
0
]
.
lower
()
if
prefix
in
known_providers
:
print
(
f
"DEBUG litellm: Known provider prefix, returning: {resolved_model}"
)
return
resolved_model
# Otherwise, it's likely a HuggingFace org/model path, add huggingface prefix
result
=
f
"huggingface/{resolved_model}"
print
(
f
"DEBUG litellm: HuggingFace org/model detected, adding huggingface prefix: {result}"
)
# Valid provider, reformat as openai/{provider}/{model}
model_part
=
'/'
.
join
(
parts
[
1
:])
result
=
f
"openai/{prefix}/{model_part}"
print
(
f
"DEBUG litellm: Known provider '{prefix}', returning: {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
#
Common model name patterns and their providers
#
No provider prefix - detect provider from model name pattern
provider_map
=
{
# OpenAI models
'gpt-'
:
'openai
/
'
,
'gpt3'
:
'openai
/
'
,
'gpt4'
:
'openai
/
'
,
'gpt-'
:
'openai'
,
'gpt3'
:
'openai'
,
'gpt4'
:
'openai'
,
# Anthropic models
'claude'
:
'anthropic
/
'
,
'claude'
:
'anthropic'
,
# Google models
'gemini'
:
'gemini
/
'
,
'palm'
:
'gemini
/
'
,
'gemini'
:
'gemini'
,
'palm'
:
'gemini'
,
# Meta/Llama models
'llama'
:
'meta/'
,
'llama2'
:
'meta/'
,
'llama3'
:
'meta/'
,
'mistral'
:
'mistral/'
,
'llama'
:
'meta'
,
'llama2'
:
'meta'
,
'llama3'
:
'meta'
,
# Mistral models
'mistral'
:
'mistral'
,
# AWS models
'amazon'
:
'bedrock
/
'
,
'amazon'
:
'bedrock'
,
# Azure models
'azure'
:
'azure
/
'
,
'azure'
:
'azure'
,
# Cohere models
'cohere'
:
'cohere
/
'
,
'cohere'
:
'cohere'
,
# AI21 models
'ai21'
:
'ai21
/
'
,
'ai21'
:
'ai21'
,
# Local/Ollama models
'ollama'
:
'ollama
/
'
,
'ollama'
:
'ollama'
,
# HuggingFace models
'hf'
:
'huggingface
/
'
,
'hf'
:
'huggingface'
,
# DeepSeek models
'deepseek'
:
'deepseek
/
'
,
'deepseek'
:
'deepseek'
,
# Qwen models
'qwen'
:
'qwen
/
'
,
'qwen'
:
'qwen'
,
}
model_lower
=
resolved_model
.
lower
()
...
...
@@ -165,11 +169,13 @@ class LiteLLMBackend:
# Check for known patterns
for
pattern
,
provider
in
provider_map
.
items
():
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
result
=
f
"openai/{resolved_model}"
print
(
f
"DEBUG litellm: U
sing default provider
, returning: {result}"
)
# Default:
use "coderai" as provider for unknown models
result
=
f
"openai/
coderai/
{resolved_model}"
print
(
f
"DEBUG litellm: U
nknown provider, using 'coderai'
, returning: {result}"
)
return
result
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