Skip to content

Commit

Permalink
fix(pm4py): fixed exception handling in OpenAI requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Feb 28, 2024
1 parent c56bd55 commit b40821d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pm4py/algo/querying/llm/connectors/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ def apply(prompt: str, parameters: Optional[Dict[Any, Any]] = None) -> str:

response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload).json()

if "error" in response:
# raise an exception when the request fails, with the provided message
raise Exception(response["error"]["message"])

return response["choices"][0]["message"]["content"]

0 comments on commit b40821d

Please sign in to comment.