forked from BAI-LAB/MemoryOS
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
Latest commit
66 lines (51 loc) · 2.04 KB
/
Copy pathexample.py
File metadata and controls
66 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# example_2.py - Simple MemoryOS Basic Demo
importos
frommemoryosimportMemoryos
# --- 基础配置 ---
USER_ID="demo_user"
ASSISTANT_ID="demo_assistant"
OPENAI_API_KEY=""
OPENAI_BASE_URL=""
DATA_STORAGE_PATH="./simple_demo_data"
LLM_MODEL="gpt-4o-mini"
defsimple_demo():
print("🚀 MemoryOS Simple Demo")
# 1. 初始化 MemoryOS
print("📦 Initializing MemoryOS...")
try:
memo=Memoryos(
user_id=USER_ID,
openai_api_key=OPENAI_API_KEY,
openai_base_url=OPENAI_BASE_URL,
data_storage_path=DATA_STORAGE_PATH,
llm_model=LLM_MODEL,
assistant_id=ASSISTANT_ID,
short_term_capacity=7,
mid_term_heat_threshold=5,
)
print("✅ MemoryOS initialized successfully!\n")
exceptExceptionase:
print(f"❌ Error: {e}")
return
# 2. 添加一些基础记忆
print("💾 Adding some memories...")
memo.add_memory(
user_input="Hi! I'm Tom, I work as a data scientist in San Francisco.",
agent_response="Hello Tom! Nice to meet you. Data science is such an exciting field. What kind of data do you work with?"
)
memo.add_memory(
user_input="I mainly work with e-commerce data. I also love playing guitar in my free time.",
agent_response="That's a great combination! E-commerce analytics must provide fascinating insights into consumer behavior. How long have you been playing guitar?"
)
memo.add_memory(
user_input="I've been playing for about 5 years. I really enjoy blues and rock music.",
agent_response="Five years is a solid foundation! Blues and rock are fantastic genres for guitar. Do you have a favorite artist or song you like to play?"
)
test_query="What do you remember about my job and hobbies?"
print(f" User: {test_query}")
response=memo.get_response(
query=test_query,
)
print(f"Assistant: {response}")
if__name__=="__main__":
simple_demo()