-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_cli.py
More file actions
74 lines (59 loc) · 2.31 KB
/
Copy pathmemory_cli.py
File metadata and controls
74 lines (59 loc) · 2.31 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
import argparse
import os
import sys
from datetime import datetime
# Add current dir to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Monkey patch config before importing main
import config
from main import SimpleMemSystem
def main():
parser = argparse.ArgumentParser(description="SimpleMem CLI for Gemini")
parser.add_argument("--api-key", help="Gemini API Key")
parser.add_argument("action", choices=["add", "query", "clear"], help="Action to perform")
parser.add_argument("text", nargs="?", help="Text to add or query")
parser.add_argument("--date", help="Date for the memory (ISO format)", default=None)
args = parser.parse_args()
# Set API Key
if args.api_key:
config.OPENAI_API_KEY = args.api_key
os.environ["GEMINI_API_KEY"] = args.api_key
os.environ["GOOGLE_API_KEY"] = args.api_key
os.environ["OPENAI_API_KEY"] = args.api_key
# Ensure environment variables are set for litellm
if config.OPENAI_API_KEY:
os.environ["GEMINI_API_KEY"] = config.OPENAI_API_KEY
os.environ["GOOGLE_API_KEY"] = config.OPENAI_API_KEY
os.environ["OPENAI_API_KEY"] = config.OPENAI_API_KEY
# Initialize System
clear_db = (args.action == "clear")
try:
system = SimpleMemSystem(clear_db=clear_db)
except Exception as e:
print(f"Error initializing system: {e}")
return
if args.action == "add":
if not args.text:
print("Error: Text required for 'add' action.")
return
timestamp = args.date or datetime.now().isoformat()
print(f"Adding memory: '{args.text}' at {timestamp}")
system.add_dialogue("User", args.text, timestamp)
system.finalize()
print("✅ Memory added successfully.")
elif args.action == "query":
if not args.text:
print("Error: Text required for 'query' action.")
return
print(f"🔎 Querying: '{args.text}'")
try:
answer = system.ask(args.text)
print("\n=== Answer ===")
print(answer)
print("==============")
except Exception as e:
print(f"Error during query: {e}")
elif args.action == "clear":
print("✅ Memory cleared.")
if __name__ == "__main__":
main()