Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix watsonx datetime conversion issue py3.10 (#12339)

isaken524f10bf6c4f
diff --git a/litellm/llms/watsonx/completion/transformation.py b/litellm/llms/watsonx/completion/transformation.py
index d45704840fe..a0b9735a990 100644
--- a/litellm/llms/watsonx/completion/transformation.py
+++ b/litellm/llms/watsonx/completion/transformation.py
@@ -300,9 +300,14 @@ class IBMWatsonXAIConfig(IBMWatsonXMixin, BaseConfig):
json_resp["results"][0]["stop_reason"]
)
if json_resp.get("created_at"):
- model_response.created = int(
- datetime.fromisoformat(json_resp["created_at"]).timestamp()
- )
+ try:
+ created_datetime = datetime.fromisoformat(json_resp["created_at"])
+ except ValueError:
+ # datetime.fromisoformat cannot handle 'Z' in Python 3.10
+ created_datetime = datetime.fromisoformat(
+ f'{json_resp["created_at"].rstrip("Z")}+00:00'
+ )
+ model_response.created = int(created_datetime.timestamp())
else:
model_response.created = int(time.time())
usage = Usage(