Skip to content

Commit

Permalink
fixing wolfram scenario where no pods are returned
Browse files Browse the repository at this point in the history
  • Loading branch information
krachwal committed May 30, 2024
1 parent 9983332 commit 10693bc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions python-backend/wolfram_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def ask(query: str, include_pod: str = None) -> dict:
else:
try:
result = json.loads(result.content)
logger.debug(result)
logger.debug(f"Wolfram Response: {result}")
try:
raise APIError(result["queryresult"]["error"]["msg"])
except (AttributeError, TypeError):
Expand Down Expand Up @@ -70,8 +70,12 @@ def closed_form(expression: str) -> dict:
# only want to return: queryresult -> pods[0] -> subpods
# infos has metadata on the subpods e.g. the constant names and links to reference content
# Note: the index of the infos does not line up with the index of the closed form results
subpods = result["queryresult"]["pods"][0]["subpods"]
meta = result["queryresult"]["pods"][0].get("infos", [])
return {"closed_forms": subpods, "metadata": meta}
if int(result["queryresult"]["numpods"]) > 0:
subpods = result["queryresult"]["pods"][0]["subpods"]
meta = result["queryresult"]["pods"][0].get("infos", [])
return {"closed_forms": subpods, "metadata": meta}
else:
return {}
except Exception as e:
logger.error("Failed to obtain Wolfram API result", e)

0 comments on commit 10693bc

Please sign in to comment.