mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
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
This commit is contained in:
parent
738db9336e
commit
524f10bf6c
1 changed files with 8 additions and 3 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue