Formatting (#2750)
This commit is contained in:
@@ -7,6 +7,7 @@ In order to run this file, you need to set up your Mem0 API at Mem0 platform and
|
||||
export OPENAI_API_KEY="your_openai_api_key"
|
||||
export MEM0_API_KEY="your_mem0_api_key"
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
from agents import Agent, Runner
|
||||
@@ -23,25 +24,19 @@ study_agent = Agent(
|
||||
- Identify topics the user has struggled with (e.g., "I'm confused", "this is hard")
|
||||
- Help with spaced repetition by suggesting topics to revisit based on last review time
|
||||
- Personalize answers using stored memories
|
||||
- Summarize PDFs or notes the user uploads""")
|
||||
- Summarize PDFs or notes the user uploads""",
|
||||
)
|
||||
|
||||
|
||||
# Upload and store PDF to Mem0
|
||||
def upload_pdf(pdf_url: str, user_id: str):
|
||||
pdf_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "pdf_url",
|
||||
"pdf_url": {"url": pdf_url}
|
||||
}
|
||||
}
|
||||
pdf_message = {"role": "user", "content": {"type": "pdf_url", "pdf_url": {"url": pdf_url}}}
|
||||
client.add([pdf_message], user_id=user_id)
|
||||
print("✅ PDF uploaded and processed into memory.")
|
||||
|
||||
|
||||
# Main interaction loop with your personal study buddy
|
||||
async def study_buddy(user_id: str, topic: str, user_input: str):
|
||||
|
||||
memories = client.search(f"{topic}", user_id=user_id)
|
||||
memory_context = "n".join(f"- {m['memory']}" for m in memories)
|
||||
|
||||
@@ -56,9 +51,11 @@ Now respond to the user's new question or comment:
|
||||
result = await Runner.run(study_agent, prompt)
|
||||
response = result.final_output
|
||||
|
||||
client.add([
|
||||
{"role": "user", "content": f'''Topic: {topic}nUser: {user_input}nnStudy Assistant: {response}'''}
|
||||
], user_id=user_id, metadata={"topic": topic})
|
||||
client.add(
|
||||
[{"role": "user", "content": f"""Topic: {topic}nUser: {user_input}nnStudy Assistant: {response}"""}],
|
||||
user_id=user_id,
|
||||
metadata={"topic": topic},
|
||||
)
|
||||
|
||||
return response
|
||||
|
||||
@@ -78,7 +75,12 @@ async def main():
|
||||
|
||||
# Demonstrate spaced repetition prompting
|
||||
topic = "Momentum Conservation"
|
||||
print(await study_buddy(user_id, topic, "I think we covered this last week. Is it time to review momentum conservation again?"))
|
||||
print(
|
||||
await study_buddy(
|
||||
user_id, topic, "I think we covered this last week. Is it time to review momentum conservation again?"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
Reference in New Issue
Block a user