mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 19:39:02 +08:00
fix: incomplete response (#3215)
This commit is contained in:
parent
33ea689861
commit
cc5ccaaca1
@ -70,43 +70,44 @@ class SerpAPI:
|
|||||||
raise ValueError(f"Got error from SerpAPI: {res['error']}")
|
raise ValueError(f"Got error from SerpAPI: {res['error']}")
|
||||||
|
|
||||||
if typ == "text":
|
if typ == "text":
|
||||||
|
toret = ""
|
||||||
if "answer_box" in res.keys() and type(res["answer_box"]) == list:
|
if "answer_box" in res.keys() and type(res["answer_box"]) == list:
|
||||||
res["answer_box"] = res["answer_box"][0]
|
res["answer_box"] = res["answer_box"][0] + "\n"
|
||||||
if "answer_box" in res.keys() and "answer" in res["answer_box"].keys():
|
if "answer_box" in res.keys() and "answer" in res["answer_box"].keys():
|
||||||
toret = res["answer_box"]["answer"]
|
toret += res["answer_box"]["answer"] + "\n"
|
||||||
elif "answer_box" in res.keys() and "snippet" in res["answer_box"].keys():
|
if "answer_box" in res.keys() and "snippet" in res["answer_box"].keys():
|
||||||
toret = res["answer_box"]["snippet"]
|
toret += res["answer_box"]["snippet"] + "\n"
|
||||||
elif (
|
if (
|
||||||
"answer_box" in res.keys()
|
"answer_box" in res.keys()
|
||||||
and "snippet_highlighted_words" in res["answer_box"].keys()
|
and "snippet_highlighted_words" in res["answer_box"].keys()
|
||||||
):
|
):
|
||||||
toret = res["answer_box"]["snippet_highlighted_words"][0]
|
for item in res["answer_box"]["snippet_highlighted_words"]:
|
||||||
elif (
|
toret += item + "\n"
|
||||||
|
if (
|
||||||
"sports_results" in res.keys()
|
"sports_results" in res.keys()
|
||||||
and "game_spotlight" in res["sports_results"].keys()
|
and "game_spotlight" in res["sports_results"].keys()
|
||||||
):
|
):
|
||||||
toret = res["sports_results"]["game_spotlight"]
|
toret += res["sports_results"]["game_spotlight"] + "\n"
|
||||||
elif (
|
if (
|
||||||
"shopping_results" in res.keys()
|
"shopping_results" in res.keys()
|
||||||
and "title" in res["shopping_results"][0].keys()
|
and "title" in res["shopping_results"][0].keys()
|
||||||
):
|
):
|
||||||
toret = res["shopping_results"][:3]
|
toret += res["shopping_results"][:3] + "\n"
|
||||||
elif (
|
if (
|
||||||
"knowledge_graph" in res.keys()
|
"knowledge_graph" in res.keys()
|
||||||
and "description" in res["knowledge_graph"].keys()
|
and "description" in res["knowledge_graph"].keys()
|
||||||
):
|
):
|
||||||
toret = res["knowledge_graph"]["description"]
|
toret = res["knowledge_graph"]["description"] + "\n"
|
||||||
elif "snippet" in res["organic_results"][0].keys():
|
if "snippet" in res["organic_results"][0].keys():
|
||||||
toret = res["organic_results"][0]["snippet"]
|
for item in res["organic_results"]:
|
||||||
elif "link" in res["organic_results"][0].keys():
|
toret += "content: " + item["snippet"] + "\n" + "link: " + item["link"] + "\n"
|
||||||
toret = res["organic_results"][0]["link"]
|
if (
|
||||||
elif (
|
|
||||||
"images_results" in res.keys()
|
"images_results" in res.keys()
|
||||||
and "thumbnail" in res["images_results"][0].keys()
|
and "thumbnail" in res["images_results"][0].keys()
|
||||||
):
|
):
|
||||||
thumbnails = [item["thumbnail"] for item in res["images_results"][:10]]
|
thumbnails = [item["thumbnail"] for item in res["images_results"][:10]]
|
||||||
toret = thumbnails
|
toret = thumbnails
|
||||||
else:
|
if toret == "":
|
||||||
toret = "No good search result found"
|
toret = "No good search result found"
|
||||||
elif typ == "link":
|
elif typ == "link":
|
||||||
if "knowledge_graph" in res.keys() and "title" in res["knowledge_graph"].keys() \
|
if "knowledge_graph" in res.keys() and "title" in res["knowledge_graph"].keys() \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user