|
@@ -66,6 +66,41 @@ class BingSearchTool(BuiltinTool):
|
|
|
results.append(self.create_text_message(text=f'{related.get("displayText", "")}{url}'))
|
|
|
|
|
|
return results
|
|
|
+ elif result_type == "json":
|
|
|
+ result = {}
|
|
|
+ if search_results:
|
|
|
+ result["organic"] = [
|
|
|
+ {
|
|
|
+ "title": item.get("name", ""),
|
|
|
+ "snippet": item.get("snippet", ""),
|
|
|
+ "url": item.get("url", ""),
|
|
|
+ "siteName": item.get("siteName", ""),
|
|
|
+ }
|
|
|
+ for item in search_results
|
|
|
+ ]
|
|
|
+
|
|
|
+ if computation and "expression" in computation and "value" in computation:
|
|
|
+ result["computation"] = {"expression": computation["expression"], "value": computation["value"]}
|
|
|
+
|
|
|
+ if entities:
|
|
|
+ result["entities"] = [
|
|
|
+ {
|
|
|
+ "name": item.get("name", ""),
|
|
|
+ "url": item.get("url", ""),
|
|
|
+ "description": item.get("description", ""),
|
|
|
+ }
|
|
|
+ for item in entities
|
|
|
+ ]
|
|
|
+
|
|
|
+ if news:
|
|
|
+ result["news"] = [{"name": item.get("name", ""), "url": item.get("url", "")} for item in news]
|
|
|
+
|
|
|
+ if related_searches:
|
|
|
+ result["related searches"] = [
|
|
|
+ {"displayText": item.get("displayText", ""), "url": item.get("webSearchUrl", "")} for item in news
|
|
|
+ ]
|
|
|
+
|
|
|
+ return self.create_json_message(result)
|
|
|
else:
|
|
|
# construct text
|
|
|
text = ""
|