mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-27 00:48:45 +00:00
wolfram alpha improvements (#591)
Co-authored-by: Nicolas <nicolascamara29@gmail.com>
This commit is contained in:
parent
a5ee7de650
commit
4c6c5f0391
@ -52,8 +52,15 @@ class WolframAlphaAPIWrapper(BaseModel):
|
|||||||
def run(self, query: str) -> str:
|
def run(self, query: str) -> str:
|
||||||
"""Run query through WolframAlpha and parse result."""
|
"""Run query through WolframAlpha and parse result."""
|
||||||
res = self.wolfram_client.query(query)
|
res = self.wolfram_client.query(query)
|
||||||
# Includes only text from the response
|
|
||||||
answer = next(res.results).text
|
try:
|
||||||
|
assumption = next(res.pods).text
|
||||||
|
answer = next(res.results).text
|
||||||
|
except StopIteration:
|
||||||
|
return "Wolfram Alpha wasn't able to answer it"
|
||||||
|
|
||||||
if answer is None or answer == "":
|
if answer is None or answer == "":
|
||||||
|
# We don't want to return the assumption alone if answer is empty
|
||||||
return "No good Wolfram Alpha Result was found"
|
return "No good Wolfram Alpha Result was found"
|
||||||
return answer
|
else:
|
||||||
|
return f"Assumption: {assumption} \nAnswer: {answer}"
|
||||||
|
Loading…
Reference in New Issue
Block a user