-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm.py
More file actions
executable file
·62 lines (49 loc) · 1.4 KB
/
Copy pathllm.py
File metadata and controls
executable file
·62 lines (49 loc) · 1.4 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
#!/usr/bin/env python3
import sys
import os
import subprocess
# Ensure vector store is in path
VECTOR_DIR = os.path.expanduser("")
sys.path.append(VECTOR_DIR)
from store import add, search, initialize_store
# llama.cpp binary
LLAMA_BIN = os.path.expanduser("")
# GGUF model file
MODEL_PATH = os.path.expanduser("")
# Initialize vector store
initialize_store(VECTOR_DIR)
def run_llama(prompt):
try:
result = subprocess.run([
LLAMA_BIN,
"--model", MODEL_PATH,
"--threads", "8",
"--prompt", prompt,
"--n-predict", str(2**15),
"--ctx-size", str(2**12)
], capture_output=True, text=True, check=True)
return result.stdout
except subprocess.CalledProcessError as e:
return f"Error running llama: {e.stderr.strip()}"
def get_memory(query, k=5):
return "\n".join(search(query, k))
def main():
if len(sys.argv) < 2:
print("Usage: python llm.py 'your message here'")
return
msg = " ".join(sys.argv[1:])
# Store memory if user wants
if msg.lower().startswith("remember this:"):
fact = msg[len("remember this:"):].strip()
add(fact)
print("memory stored.")
return
# Retrieve memory
mem = get_memory(msg)
if mem:
print("memory:\n", mem)
# Run llama.cpp
output = run_llama(msg)
print(output)
if __name__ == "__main__":
main()