Commit 7b194a45 authored by Your Name's avatar Your Name

Fix litellm custom provider registration

- Use litellm.openai instead of 'openai' string for custom_handler
- This ensures proper registration of the coderai provider with litellm
parent 95e11455
...@@ -17,7 +17,7 @@ try: ...@@ -17,7 +17,7 @@ try:
# This allows LiteLLM to use its internal HTTP handler for custom providers # This allows LiteLLM to use its internal HTTP handler for custom providers
# by mapping them to the 'openai' provider behavior # by mapping them to the 'openai' provider behavior
litellm.custom_provider_map = [ litellm.custom_provider_map = [
{"provider": "coderai", "custom_handler": "openai"} {"provider": "coderai", "custom_handler": litellm.openai}
] ]
from litellm import acompletion, completion from litellm import acompletion, completion
from litellm.exceptions import ( from litellm.exceptions import (
...@@ -108,7 +108,7 @@ class LiteLLMBackend: ...@@ -108,7 +108,7 @@ class LiteLLMBackend:
""" """
Normalize model name for litellm. Normalize model name for litellm.
Always formats as: coderai/{provider}/{model} Always formats as: openai/{provider}/{model}
- If provider is detected from known patterns, use it - If provider is detected from known patterns, use it
- If model has / (e.g. org/model), use the org name as provider - If model has / (e.g. org/model), use the org name as provider
- If provider unknown, use "coderai" as default - If provider unknown, use "coderai" as default
...@@ -117,7 +117,7 @@ class LiteLLMBackend: ...@@ -117,7 +117,7 @@ class LiteLLMBackend:
model: Original model name (may be an alias) model: Original model name (may be an alias)
Returns: Returns:
Normalized model name: coderai/{provider}/{model} Normalized model name: openai/{provider}/{model}
""" """
print(f"DEBUG litellm: normalize_model_name input: {model}") print(f"DEBUG litellm: normalize_model_name input: {model}")
...@@ -135,16 +135,16 @@ class LiteLLMBackend: ...@@ -135,16 +135,16 @@ class LiteLLMBackend:
parts = resolved_model.split('/') parts = resolved_model.split('/')
prefix = parts[0].lower() prefix = parts[0].lower()
if prefix in known_providers: if prefix in known_providers:
# Valid provider, reformat as coderai/{provider}/{model} # Valid provider, reformat as openai/{provider}/{model}
model_part = '/'.join(parts[1:]) model_part = '/'.join(parts[1:])
result = f"coderai/{prefix}/{model_part}" result = f"openai/{prefix}/{model_part}"
print(f"DEBUG litellm: Known provider '{prefix}', returning: {result}") print(f"DEBUG litellm: Known provider '{prefix}', returning: {result}")
return result return result
# Otherwise, treat the first part as the org/provider name (not default to huggingface) # Otherwise, treat the first part as the org/provider name (not default to huggingface)
# This allows custom model paths like TeichAI/model-name to work correctly # This allows custom model paths like TeichAI/model-name to work correctly
org_name = parts[0] org_name = parts[0]
model_part = '/'.join(parts[1:]) model_part = '/'.join(parts[1:])
result = f"coderai/{org_name}/{model_part}" result = f"openai/{org_name}/{model_part}"
print(f"DEBUG litellm: Custom org/model, returning: {result}") print(f"DEBUG litellm: Custom org/model, returning: {result}")
return result return result
...@@ -188,12 +188,12 @@ class LiteLLMBackend: ...@@ -188,12 +188,12 @@ 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):
result = f"coderai/{provider}/{resolved_model}" result = f"openai/{provider}/{resolved_model}"
print(f"DEBUG litellm: Detected provider '{provider}', returning: {result}") print(f"DEBUG litellm: Detected provider '{provider}', returning: {result}")
return result return result
# Default: use "coderai" as provider for unknown models # Default: use "coderai" as provider for unknown models
result = f"coderai/coderai/{resolved_model}" result = f"openai/coderai/{resolved_model}"
print(f"DEBUG litellm: Unknown provider, using 'coderai', returning: {result}") print(f"DEBUG litellm: Unknown provider, using 'coderai', returning: {result}")
return result return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment