From 524f10bf6c4f010fd1e10d447d571255e9b647a9 Mon Sep 17 00:00:00 2001 From: isaken Date: Sat, 5 Jul 2025 18:01:11 +0200 Subject: [PATCH] fix watsonx datetime conversion issue py3.10 (#12339) Got ValueError on Python3.10 because datetime.fromisoformat could not handle 'Z' -> '+00:00' at the end of a timestamp. Instead, try with the previous behavior, except ValueError, then attempt removing Z, and adding +00:00 to support Python3.10 --- litellm/llms/watsonx/completion/transformation.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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(