docs/docs/examples/examples.ipynb
# install tavily
!pip install tavily-python
# import and connect
from tavily import TavilyClient
client = TavilyClient(api_key="")
# simple query using tavily's advanced search
client.search("What happend in the latest burning man floods?", search_depth="advanced")
# install lanchain
!pip install langchain
# set up openai api key
openai_api_key = ""
# libraries
from langchain.adapters.openai import convert_openai_messages
from langchain_community.chat_models import ChatOpenAI
# setup query
query = "What happend in the latest burning man floods?"
# run tavily search
content = client.search(query, search_depth="advanced")["results"]
# setup prompt
prompt = [{
"role": "system",
"content": f'You are an AI critical thinker research assistant. '\
f'Your sole purpose is to write well written, critically acclaimed,'\
f'objective and structured reports on given text.'
}, {
"role": "user",
"content": f'Information: """{content}"""\n\n' \
f'Using the above information, answer the following'\
f'query: "{query}" in a detailed report --'\
f'Please use MLA format and markdown syntax.'
}]
# run gpt-4
lc_messages = convert_openai_messages(prompt)
report = ChatOpenAI(model='gpt-4',openai_api_key=openai_api_key).invoke(lc_messages).content
# print report
print(report)