소스 검색

fix: some google search result raise exception (#4567)

非法操作 11 달 전
부모
커밋
24576a39e5
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      api/core/tools/provider/builtin/google/tools/google_search.py

+ 5 - 2
api/core/tools/provider/builtin/google/tools/google_search.py

@@ -99,8 +99,11 @@ class SerpAPI:
             ):
                 toret = res["knowledge_graph"]["description"] + "\n"
             if "snippet" in res["organic_results"][0].keys():
-                for item in res["organic_results"]:
-                    toret += "content: " + item["snippet"] + "\n" + "link: " + item["link"] + "\n"
+                toret = "\n".join(
+                    f"content: {item['snippet']}\nlink: {item['link']}"
+                    for item in res["organic_results"]
+                    if "snippet" in item and "link" in item
+                )
             if (
                 "images_results" in res.keys()
                 and "thumbnail" in res["images_results"][0].keys()