tool agent可执行工具api

This commit is contained in:
Tamiflu233
2023-12-23 17:30:41 +08:00
parent eb44372217
commit ecde1b08e4
7 changed files with 415 additions and 27 deletions

View File

@@ -1,4 +1,5 @@
from jarvis.core.llms import OpenAI
from jarvis.environment.py_env import PythonEnv
import json
'''
让大模型根据目标工具的API文档做网络请求获取到响应数据并返回
@@ -38,6 +39,7 @@ class ToolAgent():
super().__init__()
self.llm = OpenAI(config_path)
self.open_api_doc = {}
self.environment = PythonEnv()
with open(open_api_doc_path) as f:
self.open_api_doc = json.load(f)
# self.mac_systom_prompts =
@@ -91,7 +93,19 @@ class ToolAgent():
elif '```' in python_code:
python_code = response.split('```')[1].split('```')[0]
return python_code
def execute_code(self,code):
state = self.environment.step(code)
api_result = None;
if(state.error != None and state.error != ""):
api_result = state.error
else:
api_result = state.result
return api_result
agent = ToolAgent("../../examples/config.json","../core/openapi.json")
res = agent.generate_call_api_code("use /tools/bing/searchv2 tool to search How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.","/tools/bing/searchv2")
print(res)
# agent = ToolAgent("../../examples/config.json","../core/openapi.json")
# code_text = agent.generate_call_api_code("use /tools/bing/searchv2 tool to search How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.","/tools/bing/searchv2")
# code = agent.extract_python_code(code_text)
# print(code)
# api_res = agent.execute_code(code)
# print(api_res)

View File

@@ -10,7 +10,8 @@ RESULT_TARGET_PAGE_PER_TEXT_COUNT = 500
class BingAPI:
def __init__(self, subscription_key: str) -> None:
self._headers = {
'Ocp-Apim-Subscription-Key': subscription_key
'Ocp-Apim-Subscription-Key': subscription_key,
}
self._endpoint = "https://api.bing.microsoft.com/v7.0/search"
self._mkt = 'en-US'
@@ -55,3 +56,4 @@ class BingAPI:
return True, page_detail
except Exception:
return False, "Timeout for loading this page, Please try to load another one or search again."

View File

@@ -3,7 +3,7 @@ from langchain.utilities import BingSearchAPIWrapper
from bs4 import BeautifulSoup
from typing import Tuple
from enum import Enum
from .web_loader import WebPageLoader
from web_loader import WebPageLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Chroma
@@ -22,7 +22,7 @@ RESULT_TARGET_PAGE_PER_TEXT_COUNT = 500
class BingAPIV2:
def __init__(self) -> None:
self.search_engine = BingSearchAPIWrapper()
self.search_engine = BingSearchAPIWrapper(search_kwargs={'mkt': 'en-us'})
self.web_loader = WebPageLoader()
self.web_chunker = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
self.web_sniptter_embed = OpenAIEmbeddings()
@@ -66,4 +66,4 @@ class BingAPIV2:
return attended_content

367
jarvis/api/bing/test.json Normal file
View File

@@ -0,0 +1,367 @@
{
"_type": "SearchResponse",
"queryContext": {
"originalQuery": "Mercedes Sosa studio albums 2000-2009 wi"
},
"webPages": {
"webSearchUrl": "https://www.bing.com/search?q=Mercedes+Sosa+studio+albums+2000-2009+wi",
"totalEstimatedMatches": 48400,
"value": [
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.0",
"name": "Mercedes Sosa Discography | Discogs",
"url": "https://www.discogs.com/artist/333361-Mercedes-Sosa",
"thumbnailUrl": "https://www.bing.com/th?id=OIP.0k3D90jn0FG5bWZ-YrZrbgHaFd&w=80&h=80&c=1&pid=5.1",
"datePublished": "2023-12-12T08:00:00.0000000",
"datePublishedDisplayText": "2023年12月12日",
"isFamilyFriendly": true,
"displayUrl": "https://www.discogs.com/artist/333361-Mercedes-Sosa",
"snippet": "Explore music from Mercedes Sosa. Shop for vinyl, CDs, and more from Mercedes Sosa on Discogs.",
"dateLastCrawled": "2023-12-18T09:55:00.0000000Z",
"primaryImageOfPage": {
"thumbnailUrl": "https://www.bing.com/th?id=OIP.0k3D90jn0FG5bWZ-YrZrbgHaFd&w=80&h=80&c=1&pid=5.1",
"width": 80,
"height": 80,
"imageId": "OIP.0k3D90jn0FG5bWZ-YrZrbgHaFd"
},
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4908671216604867&mkt=zh-CN&setlang=zh-CN&w=8g_BctF7TFm4NOWDhWkiMgSTTrxtwoRh",
"language": "en",
"isNavigational": true
},
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.1",
"name": "Mercedes Sosa Albums, Songs - Discography - Album of The Year",
"url": "https://www.albumoftheyear.org/artist/33792-mercedes-sosa/",
"about": [
{
"_type": "CreativeWork",
"aggregateRating": {
"ratingValue": 67,
"bestRating": 100
}
}
],
"isFamilyFriendly": true,
"displayUrl": "https://www.albumoftheyear.org/artist/33792-mercedes-sosa",
"snippet": "1982. Como un Pájaro Libre. LP. 1979. Serenata Para la Tierra De Uno. LP. 1977. Mercedes Sosa interpreta a Atahualpa Yupanqui. LP.",
"dateLastCrawled": "2023-12-20T15:47:00.0000000Z",
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4856315554188671&mkt=zh-CN&setlang=zh-CN&w=DEAhgep4jGagZdSDScqwu-rUkQEWry9S",
"language": "en",
"isNavigational": false
},
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.2",
"name": "梅塞德斯·索萨 Mercedes Sosa | 豆瓣音乐-艺术家",
"url": "https://music.douban.com/musician/102414/",
"isFamilyFriendly": true,
"displayUrl": "https://music.douban.com/musician/102414",
"snippet": "Mercedes Sosa是“nueva cancion”二十世纪60年代后期在阿根廷和智利开始的“新音乐运动”中伟大的代表音乐家。. 新音乐运动是充满着对独裁的抗争和对人民的爱的音乐,具有鲜明的政治性,她的目标就是与社会和生活的不平等作斗争,来改善大众的生活。. 和 ...",
"dateLastCrawled": "2023-12-02T19:33:00.0000000Z",
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4524868639079408&mkt=zh-CN&setlang=zh-CN&w=0l7bBpne4BIJrEo1fQC6XHVfyFkctxN6",
"language": "zh_chs",
"isNavigational": false
},
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.3",
"name": "Mercedes Sosa: albums, songs, playlists | Listen on Deezer",
"url": "https://www.deezer.com/us/artist/10606",
"isFamilyFriendly": true,
"displayUrl": "https://www.deezer.com/us/artist/10606",
"snippet": "Sign up for Deezer for free and listen to Mercedes Sosa: discography, top tracks and playlists. Mercedes Sosa was an acclaimed singer from Argentina who, when she died at the age of 74 in 2009, was hailed by the Latin Grammy Awards as \"one of the great voices in popular music and long a symb..",
"dateLastCrawled": "2023-11-02T21:10:00.0000000Z",
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4783271050293297&mkt=zh-CN&setlang=zh-CN&w=cmhyL_5xA8J_Lh6PJQEKHqMj9sgRxKZX",
"language": "es",
"isNavigational": false
},
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.4",
"name": "Mercedes Sosa Discography - Download Albums in Hi-Res - Qobuz",
"url": "https://www.qobuz.com/us-en/interpreter/mercedes-sosa/50361",
"isFamilyFriendly": true,
"displayUrl": "https://www.qobuz.com/us-en/interpreter/mercedes-sosa/50361",
"snippet": "In fall 2000, Sosa won a Grammy for Best Folk Album for Misa Criolla at the first annual Latin Grammy Awards, and again in 2003 and 2006 for Acústico and Corazón Libre, respectively. On October 4, 2009, after receiving multiple Grammy nominations for the album, Cantora, Mercedes Sosa passed away after a long battle with kidney disease.",
"dateLastCrawled": "2023-09-21T22:15:00.0000000Z",
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4938272128254281&mkt=zh-CN&setlang=zh-CN&w=GHhZ1rIXaETFqvZr-EskUsyBgTLv0eDm",
"language": "en",
"isNavigational": false
},
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.5",
"name": "Mercedes Sosa Cantora 1 (2009, CD) - Discogs",
"url": "https://www.discogs.com/release/4511031-Mercedes-Sosa-Cantora-1",
"datePublished": "2009-03-27T08:00:00.0000000",
"datePublishedDisplayText": "2009年3月27日",
"isFamilyFriendly": true,
"displayUrl": "https://www.discogs.com/release/4511031-Mercedes-Sosa-Cantora-1",
"snippet": "Violin Grace Medina, Nicolás Tabbush, Pablo Sangiorgio, Raúl di Renzo, Sebastián Prusak, Serdar Geldymuradov, Yuiko Asaba. Cello Nicolás Rossi. Contrabass Daniel Falasca. Featuring Joan Manuel Serrat. Lyrics By, Music By Joan Manuel Serrat. Piano, Directed By, Arranged By Popi Spatocco.",
"dateLastCrawled": "2023-09-15T09:59:00.0000000Z",
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4654636781750405&mkt=zh-CN&setlang=zh-CN&w=BhGFKz2kp7pEr1dczgMtsYarJJdoAOOY",
"language": "en",
"isNavigational": false
},
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.6",
"name": "Mercedes Sosa albums and discography | Last.fm",
"url": "https://www.last.fm/music/Mercedes+Sosa/+albums",
"datePublished": "1993-01-01T08:00:00.0000000",
"datePublishedDisplayText": "1993年1月1日",
"isFamilyFriendly": true,
"displayUrl": "https://www.last.fm/music/Mercedes+Sosa/+albums",
"snippet": "Find the latest tracks, albums, and images from Mercedes Sosa. Playing via Spotify Playing via YouTube. Playback options ... 12 May 2009 · 20 tracks Play album Buy. Loading; Cantora 2. 25,091 listeners 11 May 2021 · 19 tracks Play album Buy. Loading; Gestos De Amor. 13,551 listeners ...",
"dateLastCrawled": "2023-11-12T15:02:00.0000000Z",
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4902752746761866&mkt=zh-CN&setlang=zh-CN&w=rZNn4ozKLEC1g9JZUPiMDLc_X3u-ZaZI",
"language": "en",
"isNavigational": false
},
{
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.7",
"name": "Mercedes Sosa on Amazon Music",
"url": "https://www.amazon.com/music/player/artists/B000QKLUGM/mercedes-sosa",
"isFamilyFriendly": true,
"displayUrl": "https://www.amazon.com/music/player/artists/B000QKLUGM/mercedes-sosa",
"snippet": "Check out Mercedes Sosa on Amazon Music. Stream ad-free or purchase CD's and MP3s now on Amazon.",
"dateLastCrawled": "2023-12-21T20:04:00.0000000Z",
"cachedPageUrl": "http://cncc.bingj.com/cache.aspx?q=Mercedes+Sosa+studio+albums+2000-2009+wi&d=4933049445018389&mkt=zh-CN&setlang=zh-CN&w=Pkzi0yqMqwbDSvdO9bxGNcJK2fY3WOLn",
"language": "en",
"isNavigational": false
}
],
"someResultsRemoved": true
},
"images": {
"id": "https://api.bing.microsoft.com/api/v7/#Images",
"readLink": "https://api.bing.microsoft.com/api/v7/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&qpvt=Mercedes+Sosa+studio+albums+2000-2009+wi",
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&qpvt=Mercedes+Sosa+studio+albums+2000-2009+wi",
"isFamilyFriendly": true,
"value": [
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=911CD36F077027A16B4D8F4BCFC4BFAB16559D72&FORM=IQFRBA",
"name": "Mercedes Sosa : Best Ever Albums",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C._TPFKq2iOlC_LIhLk4BgHgHaHa&pid=Api",
"datePublished": "2017-03-09T22:16:00.0000000Z",
"contentUrl": "https://albumart.besteveralbums.com/albumart/album_large_60327_536540a0cbfe8.jpg",
"hostPageUrl": "https://www.besteveralbums.com/thechart.php?b=3270",
"contentSize": "199039 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.besteveralbums.com/thechart.php?b=3270",
"width": 500,
"height": 500,
"thumbnail": {
"width": 474,
"height": 474
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=FFC34C164B971B65CEA3ED7D6C9690F4A8BAEB9C&FORM=IQFRBA",
"name": "Mercedes Sosa - Mercedes Sosa (Vinyl, LP, Album, Reissue, Stereo) | Discogs",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.HFgPPFRKGxgN9azZhGHVwwHaHh&pid=Api",
"datePublished": "2019-06-10T12:49:00.0000000Z",
"contentUrl": "https://img.discogs.com/qZ5LodpECTM8Ym3CUIMMXvig9qI=/fit-in/600x609/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-6360219-1558279813-1061.jpeg.jpg",
"hostPageUrl": "https://www.discogs.com/Mercedes-Sosa-Mercedes-Sosa/release/6360219",
"contentSize": "149782 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.discogs.com/Mercedes-Sosa-Mercedes-Sosa/release/6360219",
"width": 600,
"height": 609,
"thumbnail": {
"width": 474,
"height": 481
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=F6169E602BFAB8A76096689D53833A2DDC6A51D8&FORM=IQFRBA",
"name": "Mercedes Sosa - Sino - Reviews - Album of The Year",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.IfRl-g7pNHpPxI5_XfKyjgHaHa&pid=Api",
"datePublished": "2021-05-02T13:49:00.0000000Z",
"contentUrl": "https://cdn.albumoftheyear.org/album/317904-sino.jpg",
"hostPageUrl": "https://www.albumoftheyear.org/album/317904-mercedes-sosa-sino.php",
"contentSize": "187006 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.albumoftheyear.org/album/317904-mercedes-sosa-sino.php",
"width": 1000,
"height": 1000,
"thumbnail": {
"width": 474,
"height": 474
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=082C3A749DC9BB5542DA6BD03B900C98854A1584&FORM=IQFRBA",
"name": "Mercedes Sosa - Canción Con Todos (Album Version) Lyrics | Musixmatch",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.og4dDYif0zVHaCqtrAcYkAHaHa&pid=Api",
"datePublished": "2019-04-24T01:06:00.0000000Z",
"contentUrl": "https://s.mxmcdn.net/images-storage/albums8/4/6/2/9/0/7/11709264_800_800.jpg",
"hostPageUrl": "https://www.musixmatch.com/lyrics/Mercedes-Sosa/Canci%C3%B3n-Con-Todos-Album-Version",
"contentSize": "169338 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.musixmatch.com/lyrics/Mercedes-Sosa/Canción-Con-Todos-Album-Version",
"width": 800,
"height": 800,
"thumbnail": {
"width": 474,
"height": 474
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=E23900236813247087D48E57633BEC87EF825BAF&FORM=IQFRBA",
"name": "Mercedes Sosa - La Mas Completa Coleccion - Amazon.com Music",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.3iiFRe8iem3xKpgxSB77IwAAAA&pid=Api",
"datePublished": "2016-06-14T13:20:00.0000000Z",
"contentUrl": "https://images-na.ssl-images-amazon.com/images/I/51CqwdKtUZL._SX450_.jpg",
"hostPageUrl": "https://www.amazon.com/Mas-Completa-Coleccion-Mercedes-Sosa/dp/B000TW5H70",
"contentSize": "27672 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.amazon.com/Mas-Completa-Coleccion-Mercedes-Sosa/dp/B000TW5H70",
"width": 450,
"height": 445,
"thumbnail": {
"width": 450,
"height": 445
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=CB18B3E3F00F6A8237B50F7F3636928807833A55&FORM=IQFRBA",
"name": "Mercedes Sosa - Misa Criolla (2000, CD) | Discogs",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.PzPeywARekNgfg0xHNe73gHaHj&pid=Api",
"datePublished": "2021-01-15T23:56:00.0000000Z",
"contentUrl": "https://img.discogs.com/j61tIz31sn_0WLIX77O1XG-oEqE=/fit-in/600x612/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-3323697-1325776603.jpeg.jpg",
"hostPageUrl": "https://www.discogs.com/Mercedes-Sosa-Misa-Criolla/release/3323697",
"contentSize": "119668 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.discogs.com/Mercedes-Sosa-Misa-Criolla/release/3323697",
"width": 600,
"height": 612,
"thumbnail": {
"width": 474,
"height": 483
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=9BEEFDD8E6A310EDA241D4301E3F82D9609ED35E&FORM=IQFRBA",
"name": "Mercedes Sosa, una voz única, generosa e inolvidable",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.m-PfbcNed_0h5DFqH7wW1QHaFj&pid=Api",
"datePublished": "2020-07-12T03:11:00.0000000Z",
"contentUrl": "https://www.rionegro.com.ar/wp-content/uploads/2020/07/mercedes-sosa.jpg",
"hostPageUrl": "https://www.rionegro.com.ar/mercedes-sosa-una-voz-unica-generosa-e-inolvidable-1424501/",
"contentSize": "152495 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.rionegro.com.ar/mercedes-sosa-una-voz-unica-generosa-e-inolvidable-1424501/",
"width": 1200,
"height": 900,
"thumbnail": {
"width": 474,
"height": 355
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=256FE2A48B038676D7099FB33E504FE83DE38FFF&FORM=IQFRBA",
"name": "Mercedes Sosa Cantora Éxitos de Mercedes Sosa : Napster",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.IFRg6VN_P9x-iuLbwfh0mgHaHa&pid=Api",
"datePublished": "2021-06-17T10:03:00.0000000Z",
"contentUrl": "https://direct.rhapsody.com/imageserver/images/alb.583777285/600x600.jpg",
"hostPageUrl": "https://es.napster.com/artist/mercedes-sosa/album/mercedes-sosa-cantora-exitos",
"contentSize": "69367 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://es.napster.com/artist/mercedes-sosa/album/mercedes-sosa-cantora-exitos",
"width": 600,
"height": 600,
"thumbnail": {
"width": 474,
"height": 474
}
},
{
"webSearchUrl": "https://www.bing.com/images/search?q=mercedes+sosa+studio+albums+2000-2009+wi&id=ACECD5C598DC43B6D803CD4882A9887DBB35B438&FORM=IQFRBA",
"name": "The Definitive Collection: Mercedes Sosa, Mercedes Sosa: Amazon.fr: Musique",
"thumbnailUrl": "https://tse1-mm.cn.bing.net/th?id=OIP-C.QELk7KsOTjK17AWMHNBOxQHaHd&pid=Api",
"datePublished": "2020-06-10T20:16:00.0000000Z",
"contentUrl": "https://images-na.ssl-images-amazon.com/images/I/61jalIfFc8L.jpg",
"hostPageUrl": "https://www.amazon.fr/Definitive-Collection-Mercedes-Sosa/dp/B005GZ81LY",
"contentSize": "80560 B",
"encodingFormat": "jpeg",
"hostPageDisplayUrl": "https://www.amazon.fr/Definitive-Collection-Mercedes-Sosa/dp/B005GZ81LY",
"width": 496,
"height": 500,
"thumbnail": {
"width": 474,
"height": 477
}
}
]
},
"rankingResponse": {
"mainline": {
"items": [
{
"answerType": "Images",
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#Images"
}
},
{
"answerType": "WebPages",
"resultIndex": 0,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.0"
}
},
{
"answerType": "WebPages",
"resultIndex": 1,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.1"
}
},
{
"answerType": "WebPages",
"resultIndex": 2,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.2"
}
},
{
"answerType": "WebPages",
"resultIndex": 3,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.3"
}
},
{
"answerType": "WebPages",
"resultIndex": 4,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.4"
}
},
{
"answerType": "WebPages",
"resultIndex": 5,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.5"
}
},
{
"answerType": "WebPages",
"resultIndex": 6,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.6"
}
},
{
"answerType": "WebPages",
"resultIndex": 7,
"value": {
"id": "https://api.bing.microsoft.com/api/v7/#WebPages.7"
}
}
]
},
"sidebar": {
"items": [
{
"answerType": "Entities"
}
]
}
}
}

View File

@@ -3,18 +3,23 @@ from jarvis.core.tool_request_util import ToolRequestUtil
# Initialize the ToolRequestUtil
tool_request_util = ToolRequestUtil()
# Define the API path and method
# Define the API path
api_path = "/tools/bing/searchv2"
# Define the method to be used for the API call
method = "get"
# Define the query parameters
# Define the parameters for the API call
params = {
"query": "Mercedes Sosa studio albums 2000-2009",
"top_k": 1 # We only need the top result since we're looking for a specific Wikipedia page
"query": "Mercedes Sosa studio albums 2000-2009 site:en.wikipedia.org",
"top_k": 5 # We only need the top result since we are looking for a specific piece of information
}
# Make the API request
response = tool_request_util.request(api_path, method, params=params, content_type="application/json")
# Define the content type
content_type = "application/json"
# Print the response from the API
# Make the API call and store the response
response = tool_request_util.request(api_path, method, params=params, content_type=content_type)
# Print the return value of the API call
print(response)

View File

@@ -4,20 +4,20 @@ import json
headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML like Gecko) Chrome/52.0.2743.116 Safari/537.36'}
# url="http://101.132.188.137:8079/test?q=1"
# url="http://101.132.188.137:8079/tools/bing/load_pagev2"
url="http://10.241.41.203:8079/tools/bing/load_pagev2"
# url="http://192.168.31.128:8079/tools/bing/searchv2"
# param = {
# # 'url': 'https://blog.csdn.net/sjxgghg/article/details/134312033',
# # 'query': '如何解决这个bug?',
# 'query': 'Mercedes Sosa studio albums 2000-2009',
# 'url':'https://en.wikipedia.org/wiki/Mercedes_Sosa'
# }
# url="http://192.168.1.102:8079/tools/bing/load_pagev2"
url="http://192.168.1.102:8079/tools/bing/searchv2"
param = {
'url': 'https://blog.csdn.net/sjxgghg/article/details/134312033',
'query': '如何解决这个bug?',
# 'query': '2015',
# 'url':'https://en.wikipedia.org/wiki/OpenAI'
# 'url': 'https://blog.csdn.net/sjxgghg/article/details/134312033',
# 'query': '如何解决这个bug?',
'query': 'Mercedes Sosa studio albums 2000-2009 en.wiki',
# 'url':'https://en.wikipedia.org/wiki/Mercedes_Sosa'
}
# param = {
# # 'url': 'https://blog.csdn.net/ruanjianceshizl/article/details/134797818',
# # 'query': 'cmd',
# 'query': '2015',
# 'url':'https://en.wikipedia.org/wiki/OpenAI'
# }
res = requests.get(url,
headers=headers,
json=param,

View File

@@ -3,7 +3,7 @@ class ToolRequestUtil:
def __init__(self):
self.session = requests.session()
self.headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML like Gecko) Chrome/52.0.2743.116 Safari/537.36'}
self.base_url = "http://10.241.41.203:8079"
self.base_url = "http://192.168.1.102:8079"
def request(self , api_path , method , params=None , content_type=None):
"""
:param api_path: the path of the api