llama-index-integrations/tools/llama-index-tools-dappier/examples/dappier_ai_recommendations.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_ai_recommendations.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 (
DappierAIRecommendationsToolSpec,
)
dappier_tool = DappierAIRecommendationsToolSpec()
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.
Real-time news, updates, and personalized content from top sports sources like Sportsnaut, Forever Blueshirts, Minnesota Sports Fan, LAFB Network, Bounding Into Sports, and Ringside Intel.
print(
dappier_tool.get_sports_news_recommendations(
query="latest sports news", similarity_top_k=3
)
)
Real-time updates, analysis, and personalized content from top sources like The Mix, Snipdaily, Nerdable, and Familyproof.
print(
dappier_tool.get_lifestyle_news_recommendations(
query="latest lifestyle updates", similarity_top_k=3
)
)
A dog care expert with access to articles on health, behavior, lifestyle, grooming, ownership, and more.
print(
dappier_tool.get_iheartdogs_recommendations(
query="dog care tips", similarity_top_k=3
)
)
A cat care expert with access to articles on health, behavior, lifestyle, grooming, ownership, and more.
print(
dappier_tool.get_iheartcats_recommendations(
query="cat care advice", similarity_top_k=3
)
)
A helpful guide to making conscious and compassionate choices that help people, animals, and the planet.
print(
dappier_tool.get_greenmonster_recommendations(
query="sustainable living", similarity_top_k=3
)
)
Politics, breaking news, multicultural news, Hispanic language content, Entertainment, Health, Education, and many more.
print(
dappier_tool.get_wishtv_recommendations(
query="latest breaking news", similarity_top_k=3
)
)
Up-to-date local news, weather forecasts, sports coverage, and community stories for Northern Michigan, including the Cadillac and Traverse City areas.
print(
dappier_tool.get_nine_and_ten_news_recommendations(
query="northern michigan local news", similarity_top_k=3
)
)
We can create an agent with access to the Dappier AI Recommendations tool start testing it out:
from llama_index.core.agent import FunctionAgent
from llama_index.llms.openai import OpenAI
agent = FunctionAgent(
tools=dappier_tool_list,
llm=OpenAI(model="gpt-4o"),
)
print(
await agent.run(
"Get latest sports news, lifestyle news, breaking news, dog care advice and summarize it into different sections, with source links."
)
)