AI Personalized Learning Agent: phidata + googledocs
This commit is contained in:
parent
abb2cffa62
commit
3c150dc5a2
3 changed files with 258 additions and 0 deletions
59
ai_agent_tutorials/ai_personal_learning_agent/README.md
Normal file
59
ai_agent_tutorials/ai_personal_learning_agent/README.md
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# AI Personal Learning Agent
|
||||
|
||||
A Personal learning assistant built on PraisonAI Framework that explains a particular topic, creates learning plans and roadmaps using multiple specialized AI agents which are self reflective and hierarchical. The system uses OpenAI's GPT-4o to generate comprehensive learning materials, roadmaps, and practice exercises.
|
||||
|
||||
## Features
|
||||
|
||||
- 🧠 Knowledge Building: Researches and creates comprehensive knowledge bases
|
||||
- 🗺️ Learning Roadmaps: Generates structured learning paths with time estimates
|
||||
- 📚 Resource Curation: Finds and validates high-quality learning materials
|
||||
- ✍️ Practice Materials: Creates progressive exercises and projects
|
||||
- 🔍 Internet Search Integration: Used a custom InternetSearchTool tool for real-time research
|
||||
- 📊 Live Terminal Output: Shows real-time agent interactions in terminal - also in streamlit UI
|
||||
|
||||
## Agents
|
||||
|
||||
1. **KnowledgeBuilder**: Research specialist that gathers and organizes information
|
||||
2. **RoadmapArchitect**: Curriculum designer that creates structured learning paths
|
||||
3. **ResourceCurator**: Resource specialist that finds and validates learning materials
|
||||
4. **PracticeDesigner**: Exercise creator that develops practice materials
|
||||
|
||||
|
||||
## How to Run
|
||||
|
||||
1. Clone the repository
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
|
||||
cd ai_agent_tutorials/ai_personal_learning_agent
|
||||
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
1. Get your OpenAI API Key
|
||||
- Create an account on [OpenAI Platform](https://platform.openai.com/)
|
||||
- Navigate to API Keys section
|
||||
- Create a new API key
|
||||
|
||||
2. (Optional) Set up environment variables
|
||||
```bash
|
||||
export OPENAI_API_KEY='your-api-key-here'
|
||||
```
|
||||
This way of using the openai key is fundamental to how PraisonAI is designed - it initializes the OpenAI client at module import time, which means setting the environment variable after import won't help. We need to set the environment variable BEFORE importing PraisonAI. So, export way helps majorly - else if you want to use streamlit, keep the session state openai api key intializations before the imports of praisonAI
|
||||
|
||||
## Usage
|
||||
|
||||
1. Start the Streamlit app
|
||||
```bash
|
||||
streamlit run ai_personal_learning_agent.py
|
||||
```
|
||||
|
||||
2. Use the application
|
||||
- Enter your OpenAI API key in the sidebar (if not set in environment)
|
||||
- Type a topic you want to learn about (e.g., "Python Programming", "Machine Learning")
|
||||
- Click "Generate Learning Plan"
|
||||
- Wait for the agents to generate your personalized learning plan
|
||||
- View the results and terminal output in the interface
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
import streamlit as st
|
||||
from phi.agent import Agent, RunResponse
|
||||
from phi.model.openai import OpenAIChat
|
||||
from composio_phidata import Action, ComposioToolSet
|
||||
import os
|
||||
from phi.utils.pprint import pprint_run_response
|
||||
|
||||
# Set page configuration
|
||||
st.set_page_config(page_title="Learning Path Generator", layout="centered")
|
||||
|
||||
# Initialize session state for API keys and topic
|
||||
if 'openai_api_key' not in st.session_state:
|
||||
st.session_state['openai_api_key'] = ''
|
||||
if 'composio_api_key' not in st.session_state:
|
||||
st.session_state['composio_api_key'] = ''
|
||||
if 'topic' not in st.session_state:
|
||||
st.session_state['topic'] = ''
|
||||
|
||||
# Streamlit sidebar for API keys
|
||||
with st.sidebar:
|
||||
st.title("API Keys Configuration")
|
||||
st.session_state['openai_api_key'] = st.text_input("Enter your OpenAI API Key", type="password").strip()
|
||||
st.session_state['composio_api_key'] = st.text_input("Enter your Composio API Key", type="password").strip()
|
||||
|
||||
# Validate API keys
|
||||
if not st.session_state['openai_api_key'] or not st.session_state['composio_api_key']:
|
||||
st.error("Please enter both OpenAI and Composio API keys in the sidebar.")
|
||||
st.stop()
|
||||
|
||||
# Set the OpenAI API key and Composio API key from session state
|
||||
os.environ["OPENAI_API_KEY"] = st.session_state['openai_api_key']
|
||||
|
||||
try:
|
||||
composio_toolset = ComposioToolSet(api_key=st.session_state['composio_api_key'])
|
||||
google_docs_tool = composio_toolset.get_tools(actions=[Action.GOOGLEDOCS_CREATE_DOCUMENT])[0]
|
||||
except Exception as e:
|
||||
st.error(f"Error initializing ComposioToolSet: {e}")
|
||||
st.stop()
|
||||
|
||||
# Create the KnowledgeBuilder agent
|
||||
knowledge_agent = Agent(
|
||||
name="KnowledgeBuilder",
|
||||
role="Research and Knowledge Specialist",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
tools=[google_docs_tool],
|
||||
instructions=[
|
||||
"Research the given topic thoroughly using internet sources.",
|
||||
"Create a comprehensive knowledge base that covers fundamental concepts, advanced topics, and current developments.",
|
||||
"Include key terminology, core principles, and practical applications and make it as a detailed report that anyone who's starting out can read and get maximum value out of it.",
|
||||
"Always include sources and citations for your findings.",
|
||||
"Open a new Google Doc and write down the response of the agent neatly with great formatting and structure in it. **Include the Google Doc link in your response.**",
|
||||
],
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# Create the RoadmapArchitect agent
|
||||
roadmap_agent = Agent(
|
||||
name="RoadmapArchitect",
|
||||
role="Learning Path Designer",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
tools=[google_docs_tool],
|
||||
instructions=[
|
||||
"Using the knowledge base for the given topic, create a detailed learning roadmap.",
|
||||
"Break down the topic into logical subtopics and arrange them in order of progression, a detailed report of roadmap that includes all the subtopics in order to be an expert in this topic.",
|
||||
"Include estimated time commitments for each section.",
|
||||
"Present the roadmap in a clear, structured format.",
|
||||
"Open a new Google Doc and write down the response of the agent neatly with great formatting and structure in it. **Include the Google Doc link in your response.**",
|
||||
],
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# Create the ResourceCurator agent
|
||||
resource_agent = Agent(
|
||||
name="ResourceCurator",
|
||||
role="Learning Resource Specialist",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
tools=[google_docs_tool],
|
||||
instructions=[
|
||||
"Find and validate high-quality learning resources for the given topic.",
|
||||
"Include technical blogs, GitHub repositories, official documentation, video tutorials, and courses.",
|
||||
"Verify the credibility and relevance of each resource.",
|
||||
"Present the resources in a curated list with descriptions and quality assessments.",
|
||||
"Open a new Google Doc and write down the response of the agent neatly with great formatting and structure in it. **Include the Google Doc link in your response.**",
|
||||
],
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# Create the PracticeDesigner agent
|
||||
practice_agent = Agent(
|
||||
name="PracticeDesigner",
|
||||
role="Exercise Creator",
|
||||
model=OpenAIChat(id="gpt-4o"),
|
||||
tools=[google_docs_tool],
|
||||
instructions=[
|
||||
"Create comprehensive practice materials for the given topic.",
|
||||
"Include progressive exercises, quizzes, hands-on projects, and real-world application scenarios.",
|
||||
"Ensure the materials align with the roadmap progression.",
|
||||
"Provide detailed solutions and explanations for all practice materials.",
|
||||
"Open a new Google Doc and write down the response of the agent neatly with great formatting and structure in it. **Include the Google Doc link in your response.**",
|
||||
],
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
)
|
||||
|
||||
# Streamlit main UI
|
||||
st.title("AI Personal Learning Agent")
|
||||
st.markdown("Enter a topic to generate a detailed learning path and resources")
|
||||
|
||||
# Query bar for topic input
|
||||
st.session_state['topic'] = st.text_input("Enter the topic you want to learn about:", placeholder="e.g., Machine Learning, LoRA, etc.")
|
||||
|
||||
# Start button
|
||||
if st.button("Start"):
|
||||
if not st.session_state['topic']:
|
||||
st.error("Please enter a topic.")
|
||||
else:
|
||||
# Display loading animations while generating responses
|
||||
with st.spinner("Generating Knowledge Base..."):
|
||||
knowledge_response: RunResponse = knowledge_agent.run(
|
||||
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||
stream=False
|
||||
)
|
||||
|
||||
with st.spinner("Generating Learning Roadmap..."):
|
||||
roadmap_response: RunResponse = roadmap_agent.run(
|
||||
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||
stream=False
|
||||
)
|
||||
|
||||
with st.spinner("Curating Learning Resources..."):
|
||||
resource_response: RunResponse = resource_agent.run(
|
||||
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||
stream=False
|
||||
)
|
||||
|
||||
with st.spinner("Creating Practice Materials..."):
|
||||
practice_response: RunResponse = practice_agent.run(
|
||||
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||
stream=False
|
||||
)
|
||||
|
||||
# Extract Google Doc links from the responses
|
||||
def extract_google_doc_link(response_content):
|
||||
# Assuming the Google Doc link is embedded in the response content
|
||||
# You may need to adjust this logic based on the actual response format
|
||||
if "https://docs.google.com" in response_content:
|
||||
return response_content.split("https://docs.google.com")[1].split()[0]
|
||||
return None
|
||||
|
||||
knowledge_doc_link = extract_google_doc_link(knowledge_response.content)
|
||||
roadmap_doc_link = extract_google_doc_link(roadmap_response.content)
|
||||
resource_doc_link = extract_google_doc_link(resource_response.content)
|
||||
practice_doc_link = extract_google_doc_link(practice_response.content)
|
||||
|
||||
# Display Google Doc links at the top of the Streamlit UI
|
||||
st.markdown("### Google Doc Links:")
|
||||
if knowledge_doc_link:
|
||||
st.markdown(f"- **KnowledgeBuilder Document:** [View Document](https://docs.google.com{knowledge_doc_link})")
|
||||
if roadmap_doc_link:
|
||||
st.markdown(f"- **RoadmapArchitect Document:** [View Document](https://docs.google.com{roadmap_doc_link})")
|
||||
if resource_doc_link:
|
||||
st.markdown(f"- **ResourceCurator Document:** [View Document](https://docs.google.com{resource_doc_link})")
|
||||
if practice_doc_link:
|
||||
st.markdown(f"- **PracticeDesigner Document:** [View Document](https://docs.google.com{practice_doc_link})")
|
||||
|
||||
# Display responses in the Streamlit UI using pprint_run_response
|
||||
st.markdown("### KnowledgeBuilder Response:")
|
||||
st.markdown(knowledge_response.content)
|
||||
st.markdown(pprint_run_response(knowledge_response, markdown=True))
|
||||
|
||||
st.markdown("### RoadmapArchitect Response:")
|
||||
st.markdown(roadmap_response.content)
|
||||
st.markdown(pprint_run_response(roadmap_response, markdown=True))
|
||||
|
||||
st.markdown("### ResourceCurator Response:")
|
||||
st.markdown(resource_response.content)
|
||||
st.markdown(pprint_run_response(resource_response, markdown=True))
|
||||
|
||||
st.markdown("### PracticeDesigner Response:")
|
||||
st.markdown(pprint_run_response(practice_response, markdown=True))
|
||||
|
||||
# Information about the agents
|
||||
st.markdown("---")
|
||||
st.markdown("### About the Agents:")
|
||||
st.markdown("""
|
||||
- **KnowledgeBuilder**: Researches the topic and creates a detailed knowledge base.
|
||||
- **RoadmapArchitect**: Designs a structured learning roadmap for the topic.
|
||||
- **ResourceCurator**: Curates high-quality learning resources.
|
||||
- **PracticeDesigner**: Creates practice materials, exercises, and projects.
|
||||
""")
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
streamlit==1.41.1
|
||||
openai==1.58.1
|
||||
duckduckgo-search==6.4.1
|
||||
typing-extensions>=4.5.0
|
||||
phidata
|
||||
composio-phidata
|
||||
Loading…
Reference in a new issue