fix: openai payload issue

This commit is contained in:
Timothy J. Baek 2024-09-21 21:35:00 +02:00
parent 19e49e43cb
commit e35883ca9c

View File

@ -411,7 +411,12 @@ async def generate_chat_completion(
# Change max_completion_tokens to max_tokens (Backward compatible) # Change max_completion_tokens to max_tokens (Backward compatible)
if "api.openai.com" not in url and not payload["model"].lower().startswith("o1-"): if "api.openai.com" not in url and not payload["model"].lower().startswith("o1-"):
if "max_completion_tokens" in payload: if "max_completion_tokens" in payload:
payload["max_tokens"] = payload.pop("max_completion_tokens") # Remove "max_completion_tokens" from the payload
payload["max_tokens"] = payload["max_completion_tokens"]
del payload["max_completion_tokens"]
else:
if "max_tokens" in payload and "max_completion_tokens" in payload:
del payload["max_tokens"]
# Convert the modified body back to JSON # Convert the modified body back to JSON
payload = json.dumps(payload) payload = json.dumps(payload)