Spaces:
Sleeping
Sleeping
Refine flashcard generation process and update user interaction in Notebook-Tutor
Browse files- Simplify and clarify the steps for generating and exporting flashcards in prompt_templates.py, emphasizing the use of flashcard_tool for export.
- Update the welcome message and file upload prompt in chainlit_frontend.py for a more streamlined user experience.
- Adjust the logic in agents.py to allow for more flexible agent state transitions, particularly for the QAAgent and FlashcardsAgent.
- Ensure a directory is created for saving flashcards in tools.py, enhancing the flashcard creation tool's reliability.
notebook_tutor/agents.py
CHANGED
@@ -54,9 +54,11 @@ def agent_node(state, agent, name):
|
|
54 |
# Set the appropriate flags and next state
|
55 |
if name == "QuizAgent":
|
56 |
new_state["quiz_created"] = True
|
57 |
-
|
|
|
58 |
new_state["question_answered"] = True
|
59 |
-
|
|
|
60 |
new_state["flashcards_created"] = True
|
61 |
|
62 |
return new_state
|
|
|
54 |
# Set the appropriate flags and next state
|
55 |
if name == "QuizAgent":
|
56 |
new_state["quiz_created"] = True
|
57 |
+
|
58 |
+
if name == "QAAgent":
|
59 |
new_state["question_answered"] = True
|
60 |
+
|
61 |
+
if name == "FlashcardsAgent":
|
62 |
new_state["flashcards_created"] = True
|
63 |
|
64 |
return new_state
|
notebook_tutor/chainlit_frontend.py
CHANGED
@@ -26,13 +26,13 @@ async def start_chat():
|
|
26 |
"presence_penalty": 0,
|
27 |
}
|
28 |
cl.user_session.set("settings", settings)
|
29 |
-
welcome_message = "Welcome to the Notebook-Tutor!
|
30 |
await cl.Message(content=welcome_message).send()
|
31 |
|
32 |
files = None
|
33 |
while files is None:
|
34 |
files = await cl.AskFileMessage(
|
35 |
-
content="Please upload a Jupyter notebook (.ipynb, max. 5mb):",
|
36 |
accept={"application/x-ipynb+json": [".ipynb"]},
|
37 |
max_size_mb=5
|
38 |
).send()
|
@@ -60,6 +60,7 @@ async def start_chat():
|
|
60 |
|
61 |
@cl.on_message
|
62 |
async def main(message: cl.Message):
|
|
|
63 |
# Retrieve the LangGraph chain from the session
|
64 |
tutor_chain = cl.user_session.get("tutor_chain")
|
65 |
|
|
|
26 |
"presence_penalty": 0,
|
27 |
}
|
28 |
cl.user_session.set("settings", settings)
|
29 |
+
welcome_message = "Welcome to the Notebook-Tutor!"
|
30 |
await cl.Message(content=welcome_message).send()
|
31 |
|
32 |
files = None
|
33 |
while files is None:
|
34 |
files = await cl.AskFileMessage(
|
35 |
+
content="Please upload a Jupyter notebook (.ipynb, max. 5mb) to start:",
|
36 |
accept={"application/x-ipynb+json": [".ipynb"]},
|
37 |
max_size_mb=5
|
38 |
).send()
|
|
|
60 |
|
61 |
@cl.on_message
|
62 |
async def main(message: cl.Message):
|
63 |
+
|
64 |
# Retrieve the LangGraph chain from the session
|
65 |
tutor_chain = cl.user_session.get("tutor_chain")
|
66 |
|
notebook_tutor/prompt_templates.py
CHANGED
@@ -40,15 +40,13 @@ class PromptTemplates:
|
|
40 |
1. Analyze User Query: Understand the user's request and determine the key concepts and information they need to learn.
|
41 |
2. Search Notebook Content: Use the notebook content to gather relevant information and generate accurate and informative flashcards.
|
42 |
3. Generate Flashcards: Create a series of flashcards content with clear questions on the front and detailed answers on the back. Ensure that the flashcards cover the essential points and concepts requested by the user.
|
43 |
-
4. Export Flashcards:
|
44 |
-
5.
|
45 |
-
|
46 |
Remember, your goal is to help the user learn efficiently and effectively by breaking down the notebook content into manageable, repeatable flashcards."""
|
47 |
|
48 |
self.SupervisorAgent_prompt = "You are a supervisor tasked with managing a conversation between the following agents: QAAgent, QuizAgent, FlashcardsAgent. Given the user request, decide which agent should act next."
|
49 |
|
50 |
def get_rag_qa_prompt(self):
|
51 |
-
# Returns the RAG QA prompt
|
52 |
return self.rag_QA_prompt
|
53 |
|
54 |
def get_qa_agent_prompt(self):
|
|
|
40 |
1. Analyze User Query: Understand the user's request and determine the key concepts and information they need to learn.
|
41 |
2. Search Notebook Content: Use the notebook content to gather relevant information and generate accurate and informative flashcards.
|
42 |
3. Generate Flashcards: Create a series of flashcards content with clear questions on the front and detailed answers on the back. Ensure that the flashcards cover the essential points and concepts requested by the user.
|
43 |
+
4. Export Flashcards: YOU MUST USE the flashcard_tool to create and export the flashcards in a format that can be easily imported into a flashcard management system, such as Anki.
|
44 |
+
5. Provide the list of flashcards in a clear and organized manner.
|
|
|
45 |
Remember, your goal is to help the user learn efficiently and effectively by breaking down the notebook content into manageable, repeatable flashcards."""
|
46 |
|
47 |
self.SupervisorAgent_prompt = "You are a supervisor tasked with managing a conversation between the following agents: QAAgent, QuizAgent, FlashcardsAgent. Given the user request, decide which agent should act next."
|
48 |
|
49 |
def get_rag_qa_prompt(self):
|
|
|
50 |
return self.rag_QA_prompt
|
51 |
|
52 |
def get_qa_agent_prompt(self):
|
notebook_tutor/tools.py
CHANGED
@@ -22,6 +22,7 @@ class FlashcardTool(BaseTool):
|
|
22 |
) -> str:
|
23 |
"""Use the tool to create flashcards."""
|
24 |
filename = f"flashcards_{uuid.uuid4()}.csv"
|
|
|
25 |
save_path = os.path.join('flashcards', filename)
|
26 |
|
27 |
os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
|
|
22 |
) -> str:
|
23 |
"""Use the tool to create flashcards."""
|
24 |
filename = f"flashcards_{uuid.uuid4()}.csv"
|
25 |
+
|
26 |
save_path = os.path.join('flashcards', filename)
|
27 |
|
28 |
os.makedirs(os.path.dirname(save_path), exist_ok=True)
|