Updated teaching_agent_team.py with serpapi
This commit is contained in:
parent
2905974487
commit
06f06e1d12
1 changed files with 64 additions and 61 deletions
|
|
@ -5,16 +5,18 @@ from composio_phidata import Action, ComposioToolSet
|
||||||
import os
|
import os
|
||||||
from phi.tools.arxiv_toolkit import ArxivToolkit
|
from phi.tools.arxiv_toolkit import ArxivToolkit
|
||||||
from phi.utils.pprint import pprint_run_response
|
from phi.utils.pprint import pprint_run_response
|
||||||
from phi.tools.duckduckgo import DuckDuckGo
|
from phi.tools.serpapi_tools import SerpApiTools
|
||||||
|
|
||||||
# Set page configuration
|
# Set page configuration
|
||||||
st.set_page_config(page_title="👨🏫 AI Teaching Agent Team", layout="centered")
|
st.set_page_config(page_title="Learning Path Generator", layout="centered")
|
||||||
|
|
||||||
# Initialize session state for API keys and topic
|
# Initialize session state for API keys and topic
|
||||||
if 'openai_api_key' not in st.session_state:
|
if 'openai_api_key' not in st.session_state:
|
||||||
st.session_state['openai_api_key'] = ''
|
st.session_state['openai_api_key'] = ''
|
||||||
if 'composio_api_key' not in st.session_state:
|
if 'composio_api_key' not in st.session_state:
|
||||||
st.session_state['composio_api_key'] = ''
|
st.session_state['composio_api_key'] = ''
|
||||||
|
if 'serpapi_api_key' not in st.session_state:
|
||||||
|
st.session_state['serpapi_api_key'] = ''
|
||||||
if 'topic' not in st.session_state:
|
if 'topic' not in st.session_state:
|
||||||
st.session_state['topic'] = ''
|
st.session_state['topic'] = ''
|
||||||
|
|
||||||
|
|
@ -23,13 +25,14 @@ with st.sidebar:
|
||||||
st.title("API Keys Configuration")
|
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['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()
|
st.session_state['composio_api_key'] = st.text_input("Enter your Composio API Key", type="password").strip()
|
||||||
|
st.session_state['serpapi_api_key'] = st.text_input("Enter your SerpAPI Key", type="password").strip()
|
||||||
|
|
||||||
# Add info about terminal responses
|
# Add info about terminal responses
|
||||||
st.info("Note: You can also view detailed agent responses\nin your terminal after execution.")
|
st.info("Note: You can also view detailed agent responses\nin your terminal after execution.")
|
||||||
|
|
||||||
# Validate API keys
|
# Validate API keys
|
||||||
if not st.session_state['openai_api_key'] or not st.session_state['composio_api_key']:
|
if not st.session_state['openai_api_key'] or not st.session_state['composio_api_key'] or not st.session_state['serpapi_api_key']:
|
||||||
st.error("Please enter both OpenAI and Composio API keys in the sidebar.")
|
st.error("Please enter OpenAI, Composio, and SerpAPI keys in the sidebar.")
|
||||||
st.stop()
|
st.stop()
|
||||||
|
|
||||||
# Set the OpenAI API key and Composio API key from session state
|
# Set the OpenAI API key and Composio API key from session state
|
||||||
|
|
@ -43,15 +46,15 @@ except Exception as e:
|
||||||
st.error(f"Error initializing ComposioToolSet: {e}")
|
st.error(f"Error initializing ComposioToolSet: {e}")
|
||||||
st.stop()
|
st.stop()
|
||||||
|
|
||||||
# Create the Professor agent
|
# Create the KnowledgeBuilder agent
|
||||||
professor = Agent(
|
knowledge_agent = Agent(
|
||||||
name="Professor",
|
name="KnowledgeBuilder",
|
||||||
role="Research and Knowledge Specialist",
|
role="Research and Knowledge Specialist",
|
||||||
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
||||||
tools=[google_docs_tool],
|
tools=[google_docs_tool],
|
||||||
instructions=[
|
instructions=[
|
||||||
"Create a comprehensive knowledge base that covers fundamental concepts, advanced topics, and current developments of the given topic.",
|
"Create a comprehensive knowledge base that covers fundamental concepts, advanced topics, and current developments of the given topic.",
|
||||||
"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.",
|
"Exlain the topic from first principles first. 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.",
|
||||||
"Make sure it is formatted in a way that is easy to read and understand. DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
"Make sure it is formatted in a way that is easy to read and understand. DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
||||||
"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.**",
|
"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.**",
|
||||||
],
|
],
|
||||||
|
|
@ -59,9 +62,9 @@ professor = Agent(
|
||||||
markdown=True,
|
markdown=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create the Academic Advisor agent
|
# Create the RoadmapArchitect agent
|
||||||
advisor = Agent(
|
roadmap_agent = Agent(
|
||||||
name="Academic Advisor",
|
name="RoadmapArchitect",
|
||||||
role="Learning Path Designer",
|
role="Learning Path Designer",
|
||||||
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
||||||
tools=[google_docs_tool],
|
tools=[google_docs_tool],
|
||||||
|
|
@ -71,22 +74,22 @@ advisor = Agent(
|
||||||
"Include estimated time commitments for each section.",
|
"Include estimated time commitments for each section.",
|
||||||
"Present the roadmap in a clear, structured format. DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
"Present the roadmap in a clear, structured format. DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
||||||
"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.**",
|
"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,
|
show_tool_calls=True,
|
||||||
markdown=True
|
markdown=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create the Research Librarian agent
|
# Create the ResourceCurator agent
|
||||||
librarian = Agent(
|
resource_agent = Agent(
|
||||||
name="Research Librarian",
|
name="ResourceCurator",
|
||||||
role="Learning Resource Specialist",
|
role="Learning Resource Specialist",
|
||||||
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
||||||
tools=[google_docs_tool, ArxivToolkit(), DuckDuckGo(fixed_max_results=10)],
|
tools=[google_docs_tool, SerpApiTools(api_key=st.session_state['serpapi_api_key']) ],
|
||||||
instructions=[
|
instructions=[
|
||||||
"Find and validate high-quality learning resources for the given topic.",
|
"Make a list of high-quality learning resources for the given topic.",
|
||||||
"Use the DuckDuckGo search tool to find current and relevant learning materials.",
|
"Use the SerpApi search tool to find current and relevant learning materials.",
|
||||||
"Include technical blogs, GitHub repositories, official documentation, video tutorials, and courses.",
|
"Using SerpApi search tool, 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. DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
"Present the resources in a curated list with descriptions and quality assessments. DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
||||||
"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.**",
|
"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.**",
|
||||||
],
|
],
|
||||||
|
|
@ -94,15 +97,15 @@ librarian = Agent(
|
||||||
markdown=True,
|
markdown=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create the Teaching Assistant agent
|
# Create the PracticeDesigner agent
|
||||||
assistant = Agent(
|
practice_agent = Agent(
|
||||||
name="Teaching Assistant",
|
name="PracticeDesigner",
|
||||||
role="Exercise Creator",
|
role="Exercise Creator",
|
||||||
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
model=OpenAIChat(id="gpt-4o", api_key=st.session_state['openai_api_key']),
|
||||||
tools=[google_docs_tool, DuckDuckGo(fixed_max_results=10)],
|
tools=[google_docs_tool, SerpApiTools(api_key=st.session_state['serpapi_api_key'])],
|
||||||
instructions=[
|
instructions=[
|
||||||
"Create comprehensive practice materials for the given topic.",
|
"Create comprehensive practice materials for the given topic.",
|
||||||
"Use the DuckDuckGo search tool to find example problems and real-world applications.",
|
"Use the SerpApi search tool to find example problems and real-world applications.",
|
||||||
"Include progressive exercises, quizzes, hands-on projects, and real-world application scenarios.",
|
"Include progressive exercises, quizzes, hands-on projects, and real-world application scenarios.",
|
||||||
"Ensure the materials align with the roadmap progression.",
|
"Ensure the materials align with the roadmap progression.",
|
||||||
"Provide detailed solutions and explanations for all practice materials.DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
"Provide detailed solutions and explanations for all practice materials.DONT FORGET TO CREATE THE GOOGLE DOCUMENT.",
|
||||||
|
|
@ -113,7 +116,7 @@ assistant = Agent(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Streamlit main UI
|
# Streamlit main UI
|
||||||
st.title("👨🏫 AI Teaching Agent Team")
|
st.title("AI Learning Roadmap Agent")
|
||||||
st.markdown("Enter a topic to generate a detailed learning path and resources")
|
st.markdown("Enter a topic to generate a detailed learning path and resources")
|
||||||
|
|
||||||
# Add info message about Google Docs
|
# Add info message about Google Docs
|
||||||
|
|
@ -129,78 +132,78 @@ if st.button("Start"):
|
||||||
else:
|
else:
|
||||||
# Display loading animations while generating responses
|
# Display loading animations while generating responses
|
||||||
with st.spinner("Generating Knowledge Base..."):
|
with st.spinner("Generating Knowledge Base..."):
|
||||||
professor_response: RunResponse = professor.run(
|
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.",
|
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||||
stream=False
|
stream=False
|
||||||
)
|
)
|
||||||
|
|
||||||
with st.spinner("Generating Learning Roadmap..."):
|
with st.spinner("Generating Learning Roadmap..."):
|
||||||
advisor_response: RunResponse = advisor.run(
|
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.",
|
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||||
stream=False
|
stream=False
|
||||||
)
|
)
|
||||||
|
|
||||||
with st.spinner("Curating Learning Resources..."):
|
with st.spinner("Curating Learning Resources..."):
|
||||||
librarian_response: RunResponse = librarian.run(
|
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.",
|
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||||
stream=False
|
stream=False
|
||||||
)
|
)
|
||||||
|
|
||||||
with st.spinner("Creating Practice Materials..."):
|
with st.spinner("Creating Practice Materials..."):
|
||||||
assistant_response: RunResponse = assistant.run(
|
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.",
|
f"the topic is: {st.session_state['topic']},Don't forget to add the Google Doc link in your response.",
|
||||||
stream=False
|
stream=False
|
||||||
)
|
)
|
||||||
|
|
||||||
# Extract Google Doc links from the responses
|
# Extract Google Doc links from the responses
|
||||||
def extract_google_doc_link(response_content):
|
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:
|
if "https://docs.google.com" in response_content:
|
||||||
return response_content.split("https://docs.google.com")[1].split()[0]
|
return response_content.split("https://docs.google.com")[1].split()[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
professor_doc_link = extract_google_doc_link(professor_response.content)
|
knowledge_doc_link = extract_google_doc_link(knowledge_response.content)
|
||||||
advisor_doc_link = extract_google_doc_link(advisor_response.content)
|
roadmap_doc_link = extract_google_doc_link(roadmap_response.content)
|
||||||
librarian_doc_link = extract_google_doc_link(librarian_response.content)
|
resource_doc_link = extract_google_doc_link(resource_response.content)
|
||||||
assistant_doc_link = extract_google_doc_link(assistant_response.content)
|
practice_doc_link = extract_google_doc_link(practice_response.content)
|
||||||
|
|
||||||
# Display Google Doc links at the top of the Streamlit UI
|
# Display Google Doc links at the top of the Streamlit UI
|
||||||
st.markdown("### Google Doc Links:")
|
st.markdown("### Google Doc Links:")
|
||||||
if professor_doc_link:
|
if knowledge_doc_link:
|
||||||
st.markdown(f"- **Professor's Document:** [View Document](https://docs.google.com{professor_doc_link})")
|
st.markdown(f"- **KnowledgeBuilder Document:** [View Document](https://docs.google.com{knowledge_doc_link})")
|
||||||
if advisor_doc_link:
|
if roadmap_doc_link:
|
||||||
st.markdown(f"- **Academic Advisor's Document:** [View Document](https://docs.google.com{advisor_doc_link})")
|
st.markdown(f"- **RoadmapArchitect Document:** [View Document](https://docs.google.com{roadmap_doc_link})")
|
||||||
if librarian_doc_link:
|
if resource_doc_link:
|
||||||
st.markdown(f"- **Research Librarian's Document:** [View Document](https://docs.google.com{librarian_doc_link})")
|
st.markdown(f"- **ResourceCurator Document:** [View Document](https://docs.google.com{resource_doc_link})")
|
||||||
if assistant_doc_link:
|
if practice_doc_link:
|
||||||
st.markdown(f"- **Teaching Assistant's Document:** [View Document](https://docs.google.com{assistant_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
|
# Display responses in the Streamlit UI using pprint_run_response
|
||||||
st.markdown("### Professor's Response:")
|
st.markdown("### KnowledgeBuilder Response:")
|
||||||
st.markdown(professor_response.content)
|
st.markdown(knowledge_response.content)
|
||||||
pprint_run_response(professor_response, markdown=True)
|
pprint_run_response(knowledge_response, markdown=True)
|
||||||
|
st.divider()
|
||||||
|
st.markdown("### RoadmapArchitect Response:")
|
||||||
|
st.markdown(roadmap_response.content)
|
||||||
|
pprint_run_response(roadmap_response, markdown=True)
|
||||||
st.divider()
|
st.divider()
|
||||||
|
|
||||||
st.markdown("### Academic Advisor's Response:")
|
st.markdown("### ResourceCurator Response:")
|
||||||
st.markdown(advisor_response.content)
|
st.markdown(resource_response.content)
|
||||||
pprint_run_response(advisor_response, markdown=True)
|
pprint_run_response(resource_response, markdown=True)
|
||||||
st.divider()
|
st.divider()
|
||||||
|
|
||||||
st.markdown("### Research Librarian's Response:")
|
st.markdown("### PracticeDesigner Response:")
|
||||||
st.markdown(librarian_response.content)
|
st.markdown(practice_response.content)
|
||||||
pprint_run_response(librarian_response, markdown=True)
|
pprint_run_response(practice_response, markdown=True)
|
||||||
st.divider()
|
st.divider()
|
||||||
|
|
||||||
st.markdown("### Teaching Assistant's Response:")
|
|
||||||
st.markdown(assistant_response.content)
|
|
||||||
pprint_run_response(assistant_response, markdown=True)
|
|
||||||
st.divider()
|
|
||||||
|
|
||||||
# Information about the agents
|
# Information about the agents
|
||||||
st.markdown("---")
|
st.markdown("---")
|
||||||
st.markdown("### About the Agents:")
|
st.markdown("### About the Agents:")
|
||||||
st.markdown("""
|
st.markdown("""
|
||||||
- **Professor**: Researches the topic and creates a detailed knowledge base.
|
- **KnowledgeBuilder**: Researches the topic and creates a detailed knowledge base.
|
||||||
- **Academic Advisor**: Designs a structured learning roadmap for the topic.
|
- **RoadmapArchitect**: Designs a structured learning roadmap for the topic.
|
||||||
- **Research Librarian**: Curates high-quality learning resources.
|
- **ResourceCurator**: Curates high-quality learning resources.
|
||||||
- **Teaching Assistant**: Creates practice materials, exercises, and projects.
|
- **PracticeDesigner**: Creates practice materials, exercises, and projects.
|
||||||
""")
|
""")
|
||||||
Loading…
Reference in a new issue