Skip to content

Commit 6e6e9be

Browse files
Boris Devclaude
authored andcommitted
fix: handle azure model mapping and exception serialization
This update adds Azure model mapping for both small and big models, and improves error detail serialization for exceptions with non-JSON serializable attributes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7faf5bf commit 6e6e9be

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

server.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ def validate_model_field(cls, v, info): # Renamed to avoid conflict
251251
if PREFERRED_PROVIDER == "google" and SMALL_MODEL in GEMINI_MODELS:
252252
new_model = f"gemini/{SMALL_MODEL}"
253253
mapped = True
254+
elif PREFERRED_PROVIDER == "azure":
255+
new_model = f"azure/{SMALL_MODEL}"
256+
mapped = True
254257
else:
255258
new_model = f"openai/{SMALL_MODEL}"
256259
mapped = True
@@ -260,6 +263,9 @@ def validate_model_field(cls, v, info): # Renamed to avoid conflict
260263
if PREFERRED_PROVIDER == "google" and BIG_MODEL in GEMINI_MODELS:
261264
new_model = f"gemini/{BIG_MODEL}"
262265
mapped = True
266+
elif PREFERRED_PROVIDER == "azure":
267+
new_model = f"azure/{BIG_MODEL}"
268+
mapped = True
263269
else:
264270
new_model = f"openai/{BIG_MODEL}"
265271
mapped = True
@@ -329,6 +335,9 @@ def validate_model_token_count(cls, v, info): # Renamed to avoid conflict
329335
if PREFERRED_PROVIDER == "google" and SMALL_MODEL in GEMINI_MODELS:
330336
new_model = f"gemini/{SMALL_MODEL}"
331337
mapped = True
338+
elif PREFERRED_PROVIDER == "azure":
339+
new_model = f"azure/{SMALL_MODEL}"
340+
mapped = True
332341
else:
333342
new_model = f"openai/{SMALL_MODEL}"
334343
mapped = True
@@ -338,6 +347,9 @@ def validate_model_token_count(cls, v, info): # Renamed to avoid conflict
338347
if PREFERRED_PROVIDER == "google" and BIG_MODEL in GEMINI_MODELS:
339348
new_model = f"gemini/{BIG_MODEL}"
340349
mapped = True
350+
elif PREFERRED_PROVIDER == "azure":
351+
new_model = f"azure/{BIG_MODEL}"
352+
mapped = True
341353
else:
342354
new_model = f"openai/{BIG_MODEL}"
343355
mapped = True
@@ -1553,7 +1565,13 @@ async def create_message(request: MessagesRequest, raw_request: Request):
15531565
# Check for LiteLLM-specific attributes
15541566
for attr in ["message", "status_code", "response", "llm_provider", "model"]:
15551567
if hasattr(e, attr):
1556-
error_details[attr] = getattr(e, attr)
1568+
value = getattr(e, attr)
1569+
# Convert non-JSON serializable objects to strings
1570+
try:
1571+
json.dumps(value)
1572+
error_details[attr] = value
1573+
except (TypeError, ValueError):
1574+
error_details[attr] = str(value)
15571575

15581576
# Check for additional exception details in dictionaries
15591577
if hasattr(e, "__dict__"):

0 commit comments

Comments
 (0)