-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmem-cli
More file actions
executable file
·96 lines (78 loc) · 3.27 KB
/
mem-cli
File metadata and controls
executable file
·96 lines (78 loc) · 3.27 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# --- CONFIGURATION ---
if [ -z "$DONTFORGET_API_URL" ]; then
echo -e "\033[0;31mError: DONTFORGET_API_URL is not set.\033[0m"
exit 1
fi
if [ -z "$DONTFORGET_SECRET_KEY" ]; then
echo -e "\033[0;31mError: DONTFORGET_SECRET_KEY is not set.\033[0m"
exit 1
fi
API_URL="$DONTFORGET_API_URL"
API_KEY="$DONTFORGET_SECRET_KEY"
# --- COLORS ---
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# --- LOGIC ---
COMMAND=$1
INPUT=$2
case $COMMAND in
remember|save|r)
if [ -z "$INPUT" ]; then
TEMP_FILE=$(mktemp)
${EDITOR:-vim} "$TEMP_FILE"
CONTENT=$(cat "$TEMP_FILE")
rm "$TEMP_FILE"
if [ -z "$CONTENT" ]; then echo -e "${RED}Aborted.${NC}"; exit 1; fi
else
CONTENT="$INPUT"
fi
echo -e "${BLUE}🧠 Saving...${NC}"
# Safe JSON creation
JSON_PAYLOAD=$(python3 -c "import json; print(json.dumps({'text': '''$CONTENT'''}))")
RESPONSE=$(curl -s -X POST "$API_URL/remember" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD")
STATUS=$(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('status', 'error'))" 2>/dev/null)
if [ "$STATUS" == "saved" ]; then
# Parse list of tags
TAGS=$(echo "$RESPONSE" | python3 -c "import sys, json; print(', '.join(json.load(sys.stdin).get('tags', [])))" 2>/dev/null)
echo -e "${GREEN}✔ Saved!${NC}"
echo -e "${YELLOW}Tags:${NC} $TAGS"
else
echo -e "${RED}✘ Error:${NC} $RESPONSE"
fi
;;
ask|remind|q)
if [ -z "$INPUT" ]; then echo -e "${RED}Missing query.${NC}"; exit 1; fi
echo -e "${BLUE}🔍 Thinking...${NC}"
JSON_PAYLOAD=$(python3 -c "import json; print(json.dumps({'question': '''$INPUT'''}))")
RESPONSE=$(curl -s -X POST "$API_URL/remind" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD")
ANSWER=$(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('answer', 'Server Error'))" 2>/dev/null)
STATS=$(echo "$RESPONSE" | python3 -c "import sys, json; d=json.load(sys.stdin).get('stats', {}); print(f'{d.get(\"found\",0)} records | {d.get(\"tokens\",0)} tokens')" 2>/dev/null)
echo -e "\n${GREEN}$ANSWER${NC}\n"
echo -e "${BLUE}--------------------------------${NC}"
echo -e "${YELLOW}📊 Stats: $STATS${NC}\n"
;;
delete|d)
if [ -z "$INPUT" ]; then echo -e "${RED}Missing query.${NC}"; exit 1; fi
JSON_PAYLOAD=$(python3 -c "import json; print(json.dumps({'question': '''$INPUT'''}))")
RESPONSE=$(curl -s -X POST "$API_URL/delete" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD")
ANSWER=$(echo "$RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin).get('answer', 'Error'))" 2>/dev/null)
echo -e "\n${GREEN}$ANSWER${NC}\n"
;;
*)
echo "Usage: mem [r|q|d] [text]"
exit 1
;;
esac