-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path01_basic_usage.py
More file actions
76 lines (63 loc) · 2.22 KB
/
Copy path01_basic_usage.py
File metadata and controls
76 lines (63 loc) · 2.22 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
67
68
69
70
71
72
73
74
75
76
"""
Basic Usage Example for MindForge
==================================
This example demonstrates the simplest way to use MindForge for AI memory management.
"""
import os
from mindforge import MemoryManager
from mindforge.models.chat import OpenAIChatModel
from mindforge.models.embedding import OpenAIEmbeddingModel
from mindforge.storage.sqlite_engine import SQLiteEngine
from mindforge.config import AppConfig
def main():
print("=" * 60)
print("MindForge - Basic Usage Example")
print("=" * 60)
# Step 1: Set up configuration
config = AppConfig()
# Step 2: Get API key from environment
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
print("\nError: OPENAI_API_KEY environment variable not set!")
print("Please set it with: export OPENAI_API_KEY='your-key-here'")
return
# Step 3: Initialize models
print("\n1. Initializing AI models...")
chat_model = OpenAIChatModel(api_key=api_key, model_name="gpt-3.5-turbo")
embedding_model = OpenAIEmbeddingModel(api_key=api_key)
print(" ✓ Models initialized")
# Step 4: Initialize storage
print("\n2. Initializing storage...")
storage = SQLiteEngine(db_path="basic_example.db", embedding_dim=1536)
print(" ✓ Storage initialized")
# Step 5: Create memory manager
print("\n3. Creating MemoryManager...")
manager = MemoryManager(
chat_model=chat_model,
embedding_model=embedding_model,
storage_engine=storage,
config=config
)
print(" ✓ MemoryManager ready")
# Step 6: Process some queries
print("\n4. Processing queries with memory...")
print("-" * 60)
queries = [
"Hello! My name is Alex and I love programming.",
"What's my name?",
"What do I love doing?",
]
for i, query in enumerate(queries, 1):
print(f"\nQuery {i}: {query}")
response = manager.process_input(query)
print(f"Response: {response}")
print("\n" + "=" * 60)
print("Example completed successfully!")
print("=" * 60)
# Cleanup
import os
if os.path.exists("basic_example.db"):
os.remove("basic_example.db")
print("\nCleaned up database file.")
if __name__ == "__main__":
main()