llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_real_time_search.ipynb
<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_real_time_search.ipynb" target="_parent"></a>
This tutorial walks through using the LLM tools provided by Dappier to allow LLMs to use Dappier's pre-trained, LLM ready RAG models and natural language APIs to ensure factual, up-to-date, responses from premium content providers across key verticals like News, Finance, Sports, Weather, and more.
To get started, you will need an OpenAI API key and a Dappier API key
We will import the relevant agents and tools and pass them our keys here:
First, install the llama-index and llama-index-tools-dappier packages
%pip install llama-index llama-index-tools-dappier
You'll need to set up your API keys for OpenAI and Dappier.
You can go to here to get API Key from Open AI.
import os
from getpass import getpass
# Prompt for the API key securely
openai_api_key = getpass("Enter your API key: ")
os.environ["OPENAI_API_KEY"] = openai_api_key
You can go to here to get API Key from Dappier with free credits.
# Prompt for the Dappier API key securely
dappier_api_key = getpass("Enter your API key: ")
os.environ["DAPPIER_API_KEY"] = dappier_api_key
Initialize the Dappier Real-Time Search Tool, convert it to a tool list.
from llama_index.tools.dappier import DappierRealTimeSearchToolSpec
dappier_tool = DappierRealTimeSearchToolSpec()
dappier_tool_list = dappier_tool.to_tool_list()
for tool in dappier_tool_list:
print(tool.metadata.name)
We've imported our OpenAI agent, set up the api key, and initialized our tool. Let's test out the tool before setting up our Agent.
Access real-time google web search results including the latest news, weather, travel, deals and more.
print(dappier_tool.search_real_time_data("How is the weather in New York today?"))
Access real-time financial news, stock prices, and trades from polygon.io, with AI-powered insights and up-to-the-minute updates to keep you informed on all your financial interests.
print(dappier_tool.search_stock_market_data("latest financial news on Meta"))
We can create an agent with access to the Dappier Real Time Search tool start testing it out:
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
agent = FunctionAgent(
tools=dappier_tool_list,
llm=OpenAI(model="gpt-4o"),
)
print(
await agent.run(
"Analyze next week's weather in New York and provide daily clothing recommendations in a markdown format."
)
)
print(await agent.run("Last 24-hour activity of apple stock"))