Add web search and weather tool documentation for Agentic RAG unit

This commit is contained in:
davidberenstein1957
2025-02-27 07:55:40 +01:00
parent 5d433c9d06
commit 2c8f039356
6 changed files with 53 additions and 15 deletions

View File

@@ -0,0 +1,32 @@
# Importing a Tool from the LlamaHub to Websearch Actualities
Remember that we want Alfred to establish his presence as true renaissance host, with a deep knowledge of the world.
To do so, we need to make sure that Alfred has access to the latest news and information about the world.
Let's start by creating a web search tool for Alfred!
## Websearch using DuckDuckGoSearchToolSpec
Remember the [`ToolSpecs`](https://docs.llamaindex.ai/en/stable/module_guides/deploying/agents/tools/#tool-specs) from the previous unit?
We can use them to create a web search tool for Alfred.
Generally, when working with web search, DuckDuckGo is a good choice, as it is a search engine that is open to all and does not require any authentication.
To create a web search tool for Alfred, we can use the [`DuckDuckGoSearchToolSpec`](https://llamahub.ai/l/tools/llama-index-tools-duckduckgo?from=).
Let's create the tool spec for the web search tool.
```python
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
from llama_index.agent.openai import OpenAIAgent
tool_spec = DuckDuckGoSearchToolSpec()
agent = OpenAIAgent.from_tools(DuckDuckGoSearchToolSpec.to_tool_list())
agent.chat("What are the latest developments in machine learning?")
agent.chat("What does the word 'renaissance' mean?")
```
We can see that the agent is able to use the tool to search the web for information.
Great, let's continue with a a tool that can help Alfred get the weather information!

View File

View File

@@ -25,10 +25,4 @@ However, instead of answering the question on top of documents automatically, Al
![Agentic RAG](https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/agentic-rag.png)
Let's start creating the tools for our agentic RAG workflow!
Let's start **creating the web search and weather tools for our agentic RAG workflow!**

View File

@@ -16,16 +16,13 @@ First, let's give him a list of hard requirements for the gala.
A properly educated person in the age of the **renaissance** needs to have three main traits.
He or she needed to profound in the **knowledge of sports, culture, and science**. So, we need to make sure we can impress our guests with our knowledge and provide them with a gala that is truly unforgettable.
Although, to avoid any conflicts, there are some **topics, like politics and religion, that are to be avoided at a gala.** It needs to be an inclusive party without conflicts related to beliefs and ideals.
According to etiquette, a good host also needs to be aware of all actualities in the news, as well as the information of any guests that might show up at a hosted party, including their allergies, and preferences.
To avoid any confliect, there are some things that are just not acceptable at a gala because we want it to be an inclusive and open party, such as **politics** and **religion**.
According to etiquette, **a good host need to be aware of all guest information**, including their life stories and endevours. A good host also gossips and shares stories about the guests with one another.
Lastly, we need to make sure that we've got some general knowledge about the weather to ensure we can continuously find a real-time update to ensure perfect timing to launch the fireworks and end the gala with a bang! 🎆
Lastly, we need to make sure that we've got **some general knowledge about the weather** to ensure we can continuously find a real-time update to ensure perfect timing to launch the fireworks and end the gala with a bang! 🎆
As you can see, Alfred needs a lot of information to be able to host the gala.
Luckily, we can help and prepare Alfred by giving him some Retrieval Augmented Generation (RAG) training!
Luckily, we can help and prepare Alfred by giving him some **Retrieval Augmented Generation (RAG) training!**
Let's start by creating the tools that Alfred needs to be able to host the gala!

View File

@@ -0,0 +1 @@
# Creating a RAG Tool for Guest Stories

View File

@@ -0,0 +1,14 @@
# Creating a Custom Tool for Weather Information to Schedule the Fireworks
Remember that we need to make sure the fireworks are not cancelled due to bad weather?
As before, we can use a `ToolSpec` to create a tool for Alfred.
When searching for `"weather"` in LlamaHub, we get a list of `ToolSpecs` that are relevant to weather.
However, the tools that are available in the LlamaHub are not always what we need.
Both returned tools require authentication with an API key, which is not what we want so we will create a custom tool.
Let's create a custom tool that can be used to call an external weather API and get the weather information for a given location.
```python
```