Back to Llama Index

Prompt for the API key securely

llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_real_time_search.ipynb

0.14.213.3 KB
Original Source

Building a Dappier Real Time Search Agent

<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:

Installation

First, install the llama-index and llama-index-tools-dappier packages

python
%pip install llama-index llama-index-tools-dappier

Setup API keys

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.

python
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.

python
# Prompt for the Dappier API key securely
dappier_api_key = getpass("Enter your API key: ")
os.environ["DAPPIER_API_KEY"] = dappier_api_key

Setup Dappier Tool

Initialize the Dappier Real-Time Search Tool, convert it to a tool list.

python
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)

Usage

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.

Search Real Time Data

Access real-time google web search results including the latest news, weather, travel, deals and more.

python
print(dappier_tool.search_real_time_data("How is the weather in New York today?"))

Search Stock Market Data

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.

python
print(dappier_tool.search_stock_market_data("latest financial news on Meta"))

Using the Dappier Real Time Search tool in an Agent

We can create an agent with access to the Dappier Real Time Search tool start testing it out:

python
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"),
)
python
print(
    await agent.run(
        "Analyze next week's weather in New York and provide daily clothing recommendations in a markdown format."
    )
)
python
print(await agent.run("Last 24-hour activity of apple stock"))