Skip to content

Commit eabe80b

Browse files
Merge pull request #1085 from Dhivya-Bharathy/feat/agentic-rag-tools
feat: Add Agentic RAG Tools Implementation
2 parents afa4df5 + 5f08657 commit eabe80b

File tree

3 files changed

+399
-0
lines changed

3 files changed

+399
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from praisonaiagents import Agent
2+
import os
3+
4+
# Set OpenAI API key if not already set
5+
if not os.getenv("OPENAI_API_KEY"):
6+
print("Please set your OpenAI API key: export OPENAI_API_KEY='your-api-key-here'")
7+
exit(1)
8+
9+
# Create the RAG agent with web search capabilities
10+
rag_agent = Agent(
11+
instructions="""You are a helpful AI assistant specialized in Thai recipes and cooking.
12+
13+
You have access to a PDF knowledge base about Thai recipes from: https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf
14+
15+
You can also search the web for additional information about Thai cooking, ingredients, and techniques.
16+
17+
When answering questions:
18+
1. Use your knowledge about Thai cuisine to provide helpful information
19+
2. If needed, search the web for additional details, current information, or clarification
20+
3. Provide comprehensive, helpful answers about Thai cuisine
21+
4. Always be informative and helpful about Thai cooking!
22+
23+
You can use the internet_search function to search the web when needed.""",
24+
llm="gpt-4o",
25+
markdown=True,
26+
verbose=True
27+
)
28+
29+
if __name__ == "__main__":
30+
print("🤖 Thai Recipe RAG Agent is ready!")
31+
print("Ask me anything about Thai recipes or cooking!")
32+
print("Type 'quit' to exit.\n")
33+
34+
while True:
35+
user_input = input("You: ")
36+
if user_input.lower() in ['quit', 'exit', 'bye']:
37+
print("👋 Goodbye! Happy cooking!")
38+
break
39+
40+
try:
41+
response = rag_agent.start(user_input)
42+
print(f"\n🤖 Assistant: {response}\n")
43+
except Exception as e:
44+
print(f"❌ Error: {e}\n")
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# 🧠 Agentic RAG with GPT-5
2+
3+
An agentic RAG application built with the PraisonAI Agents framework, featuring GPT-5 and built-in vector search for efficient knowledge retrieval and question answering.
4+
5+
## ✨ Features
6+
7+
- **🤖 GPT-5**: Latest OpenAI model for intelligent responses
8+
- **🗄️ Built-in Vector Search**: ChromaDB integration for fast similarity search
9+
- **🔍 Agentic RAG**: Intelligent retrieval augmented generation
10+
- **📝 Markdown Formatting**: Beautiful, structured responses
11+
- **🌐 Dynamic Knowledge**: Add URLs to expand knowledge base
12+
- **⚡ Real-time Responses**: Fast answer generation- **🎯 Clean Interface**: Simplified UI without configuration complexity
13+
14+
## 🚀 Quick Start
15+
16+
### Prerequisites
17+
18+
- Python 3.11+
19+
- OpenAI API key with GPT-5 access
20+
21+
### Installation
22+
23+
1. **Clone and navigate to the project**
24+
```bash
25+
cd rag_examples/agentic_rag_gpt5
26+
```
27+
28+
2. **Install dependencies**
29+
```bash
30+
pip install -r requirements.txt
31+
```
32+
33+
3. **Set up your OpenAI API key**
34+
```bash
35+
export OPENAI_API_KEY="your-api-key-here"
36+
```
37+
Or create a `.env` file:
38+
```
39+
OPENAI_API_KEY=your-api-key-here
40+
```
41+
42+
4. **Run the application**
43+
```bash
44+
streamlit run agentic_rag_gpt5.py
45+
```
46+
47+
## 🎯 How to Use
48+
49+
1. **Enter your OpenAI API key** in the sidebar
50+
2. **Add knowledge sources** by entering URLs in the sidebar
51+
3. **Ask questions** using the text area or suggested prompts
52+
4. **Get answers** with markdown formatting
53+
54+
### Suggested Questions
55+
56+
- **"What is PraisonAI?"** - Learn about the PraisonAI Agents framework
57+
- **"Teams in PraisonAI"** - Understand how teams work in PraisonAI
58+
- **"Build RAG system"** - Get a step-by-step guide to building RAG systems
59+
60+
## 🏗️ Architecture
61+
62+
### Core Components
63+
64+
- **`Agent`**: PraisonAI Agents framework for intelligent Q&A
65+
- **`knowledge`**: Built-in knowledge base that handles URLs and documents
66+
- **`llm`**: OpenAI GPT-5-nano for generating responses
67+
- **Built-in Vector Search**: Automatic similarity search without external setup
68+
69+
### Data Flow
70+
71+
1. **Knowledge Loading**: URLs are processed and stored in the built-in vector database
72+
2. **Vector Search**: OpenAI embeddings enable semantic search
73+
3. **Response Generation**: GPT-5-nano processes information and generates answers
74+
4. **Formatted Output**: Markdown-formatted responses
75+
76+
## 🔧 Configuration
77+
78+
### Database Settings
79+
- **Vector DB**: Built-in vector database with automatic indexing
80+
- **Storage**: Local storage managed by PraisonAI Agents
81+
- **Search**: Automatic similarity search
82+
83+
### Model Configuration
84+
- **LLM**: OpenAI GPT-5-nano
85+
- **Embeddings**: Automatic handling by PraisonAI Agents
86+
- **Vector Store**: Built-in with automatic document processing
87+
88+
## 📚 Knowledge Management
89+
90+
### Adding Sources
91+
- Use the sidebar to add new URLs
92+
- Sources are automatically processed and indexed
93+
- Current sources are displayed as numbered list
94+
95+
### Default Knowledge
96+
- Starts with PraisonAI documentation: `https://docs.praisonai.com/introduction/agents.md`
97+
- Expandable with any web-based documentation
98+
99+
## 🎨 UI Features
100+
101+
### Sidebar
102+
- **API Key Management**: Secure input for OpenAI credentials
103+
- **URL Addition**: Dynamic knowledge base expansion
104+
- **Current Sources**: Numbered list of loaded URLs
105+
106+
### Main Interface
107+
- **Suggested Prompts**: Quick access to common questions
108+
- **Query Input**: Large text area for custom questions
109+
- **Fast Responses**: Quick answer generation
110+
- **Markdown Rendering**: Beautiful formatted responses
111+
112+
## 🛠️ Technical Details
113+
114+
### Dependencies
115+
```
116+
streamlit>=1.28.0
117+
praisonaiagents>=0.1.0
118+
openai>=1.0.0
119+
python-dotenv>=1.0.0
120+
```
121+
122+
### Key Features
123+
- **Built-in Knowledge Base**: Automatic document processing and indexing
124+
- **Vector Search**: Efficient similarity search with built-in database
125+
- **Caching**: Efficient resource loading with Streamlit caching
126+
- **Error Handling**: Graceful handling of API and processing errors
127+
128+
## 🔍 Troubleshooting
129+
130+
### Common Issues
131+
132+
**Knowledge base not loading**
133+
- Check OpenAI API key is valid
134+
- Ensure URLs are accessible
135+
- Verify internet connection
136+
137+
**Agent initialization errors**
138+
- Check if PraisonAI Agents is properly installed
139+
- Verify OpenAI API key has sufficient credits
140+
- Ensure Python version is 3.11+
141+
142+
### Performance Tips
143+
- **Cache Resources**: Knowledge base and agent are cached for efficiency
144+
- **Built-in Vector Search**: Fast similarity search without external setup
145+
- **Local Storage**: Optimized local storage for optimal performance
146+
147+
## 🎯 Use Cases
148+
149+
- **Documentation Q&A**: Ask questions about technical documentation
150+
- **Research Assistant**: Get answers from multiple knowledge sources
151+
- **Learning Tool**: Interactive exploration of complex topics
152+
- **Content Discovery**: Find relevant information across multiple sources
153+
154+
**Built with ❤️ using PraisonAI Agents and GPT-5**

0 commit comments

Comments
 (0)