`${this.caller}: I can't use Google searching because the user has not defined the required API keys.\nVisit: https://programmablesearchengine.google.com/controlpanel/create to create the API keys.`
);
return`Search is disabled and no content was found. This functionality is disabled because the user has not set it up yet.`;
`${this.caller}: I can't use Serper.dev searching because the user has not defined the required API key.\nVisit: https://serper.dev to create the API key for free.`
);
return`Search is disabled and no content was found. This functionality is disabled because the user has not set it up yet.`;
}
this.super.introspect(
`${this.caller}: Using Serper.dev to search for "${
query.length>100?`${query.slice(0,100)}...`:query
}"`
);
const{response,error}=awaitfetch(
"https://google.serper.dev/search",
{
method:"POST",
headers:{
"X-API-KEY":process.env.AGENT_SERPER_DEV_KEY,
"Content-Type":"application/json",
},
body:JSON.stringify({q:query}),
redirect:"follow",
}
)
.then((res)=>res.json())
.then((data)=>{
return{response:data,error:null};
})
.catch((e)=>{
return{response:null,error:e.message};
});
if(error)
return`There was an error searching for content. ${error}`;
constdata=[];
if(response.hasOwnProperty("knowledgeGraph"))
data.push(response.knowledgeGraph);
response.organic?.forEach((searchResult)=>{
const{title,link,snippet}=searchResult;
data.push({
title,
link,
snippet,
});
});
if(data.length===0)
return`No information was found online for the search query.`;
`${this.caller}: I can't use Bing Web Search because the user has not defined the required API key.\nVisit: https://portal.azure.com/ to create the API key.`
);
return`Search is disabled and no content was found. This functionality is disabled because the user has not set it up yet.`;
}
constsearchURL=newURL(
"https://api.bing.microsoft.com/v7.0/search"
);
searchURL.searchParams.append("q",query);
this.super.introspect(
`${this.caller}: Using Bing Web Search to search for "${
query.length>100?`${query.slice(0,100)}...`:query
}"`
);
constsearchResponse=awaitfetch(searchURL,{
headers:{
"Ocp-Apim-Subscription-Key":
process.env.AGENT_BING_SEARCH_API_KEY,
},
})
.then((res)=>res.json())
.then((data)=>{
constsearchResults=data.webPages?.value||[];
returnsearchResults.map((result)=>({
title:result.name,
link:result.url,
snippet:result.snippet,
}));
})
.catch((e)=>{
console.log(e);
return[];
});
if(searchResponse.length===0)
return`No information was found online for the search query.`;
// hl (str): Host Language code to display results in (reference https://developers.google.com/custom-search/docs/xml_results?hl=en#wsInterfaceLanguages)
// limit (int): The maximum number of results to return [10-100, defaults to 100]
// device_type: get results based on desktop/mobile (defaults to desktop)
if(!process.env.AGENT_SERPLY_API_KEY){
this.super.introspect(
`${this.caller}: I can't use Serply.io searching because the user has not defined the required API key.\nVisit: https://serply.io to create the API key for free.`
);
return`Search is disabled and no content was found. This functionality is disabled because the user has not set it up yet.`;