Skip to content

Instantly share code, notes, and snippets.

@jgoodie
Created November 4, 2024 04:39
Show Gist options
  • Save jgoodie/2c928976a1010719bc2954dda9b976ff to your computer and use it in GitHub Desktop.
Save jgoodie/2c928976a1010719bc2954dda9b976ff to your computer and use it in GitHub Desktop.
Function to call Tavily search API
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