Skip to content

Commit 4c6c5f0

Browse files
wolfram alpha improvements (#591)
Co-authored-by: Nicolas <[email protected]>
1 parent a5ee7de commit 4c6c5f0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

langchain/utilities/wolfram_alpha.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ def validate_environment(cls, values: Dict) -> Dict:
5252
def run(self, query: str) -> str:
5353
"""Run query through WolframAlpha and parse result."""
5454
res = self.wolfram_client.query(query)
55-
# Includes only text from the response
56-
answer = next(res.results).text
55+
56+
try:
57+
assumption = next(res.pods).text
58+
answer = next(res.results).text
59+
except StopIteration:
60+
return "Wolfram Alpha wasn't able to answer it"
61+
5762
if answer is None or answer == "":
63+
# We don't want to return the assumption alone if answer is empty
5864
return "No good Wolfram Alpha Result was found"
59-
return answer
65+
else:
66+
return f"Assumption: {assumption} \nAnswer: {answer}"

0 commit comments

Comments
 (0)