Spaces:
No application file
No application file
#coding=utf8 | |
from langchain.utilities import BingSearchAPIWrapper | |
from configs.model_config import BING_SEARCH_URL, BING_SUBSCRIPTION_KEY | |
def bing_search(text, result_len=3): | |
if not (BING_SEARCH_URL and BING_SUBSCRIPTION_KEY): | |
return [{"snippet": "please set BING_SUBSCRIPTION_KEY and BING_SEARCH_URL in os ENV", | |
"title": "env info is not found", | |
"link": "https://python.langchain.com/en/latest/modules/agents/tools/examples/bing_search.html"}] | |
search = BingSearchAPIWrapper(bing_subscription_key=BING_SUBSCRIPTION_KEY, | |
bing_search_url=BING_SEARCH_URL) | |
return search.results(text, result_len) | |
if __name__ == "__main__": | |
r = bing_search('python') | |
print(r) | |