Created
November 4, 2024 04:39
-
-
Save jgoodie/2c928976a1010719bc2954dda9b976ff to your computer and use it in GitHub Desktop.
Function to call Tavily search API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def TavilySearch(state): | |
""" Retrieve docs from web search """ | |
# Search | |
tavily_search = TavilySearchResults(max_results=5) | |
search_docs = tavily_search.invoke(state['question']) | |
search_docs = [get_news_article_text(d['url']) for d in search_docs] | |
# Format | |
formatted_search_docs = "\n\n---\n\n".join( | |
[ | |
f'<Document href="{doc["url"]}"/>\n{doc["text"]}\n</Document>' | |
for doc in search_docs | |
] | |
) | |
return {"context": [formatted_search_docs]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment