forked from Nbtguyoriginal/Pybonce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyCells.py
More file actions
87 lines (71 loc) · 2.86 KB
/
Copy pathPyCells.py
File metadata and controls
87 lines (71 loc) · 2.86 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
import os
import openai
import config
openai.api_key = config.API_KEY
class Brain_matter:
def __init__(self):
self.memory_path = "memory_files"
self.reference_path = "memory_reference"
self.subconscious_path = "subconscious"
def save_memory(self, content, memory_type):
# Create subconscious directory if it doesn't exist
if not os.path.exists(self.subconscious_path):
os.makedirs(self.subconscious_path)
# Save the full content to subconscious
with open(os.path.join(self.subconscious_path, f"{memory_type}.txt"), "a") as f:
f.write(content + "\n")
# Create memory directory if it doesn't exist
if not os.path.exists(self.memory_path):
os.makedirs(self.memory_path)
# Summarize the content
summarized_content = self.summarize_memory(content)
# Save the summarized content to memory
with open(os.path.join(self.memory_path, f"{memory_type}.txt"), "a") as f:
f.write(summarized_content + "\n")
def summarize_memory(self, content):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": f"Summarize the following content: {content}"
}
],
temperature=0.02,
max_tokens=417,
top_p=1,
frequency_penalty=0.51,
presence_penalty=0.12
)
return response.choices[0].message['content']
def retrieve_memory(self, memory_type):
with open(os.path.join(self.memory_path, f"{memory_type}.txt"), "r") as f:
memories = f.readlines()
return memories
def evolve_memory(self, memory_type, content):
# Store the evolved memory in the reference folder
if not os.path.exists(self.reference_path):
os.makedirs(self.reference_path)
with open(os.path.join(self.reference_path, f"{memory_type}.txt"), "a") as f:
f.write(content + "\n")
def learn_passively(self, content):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": f"Tell me more about {content}"
}
],
temperature=0.02,
max_tokens=417,
top_p=1,
frequency_penalty=0.51,
presence_penalty=0.12
)
return response.choices[0].message['content']
# Example usage:
# memory_system = MemorySystem()
# memory_system.store_memory("The Eiffel Tower is located in Paris.", "landmarks")
# print(memory_system.retrieve_memory("landmarks"))
# print(memory_system.learn_passively("Eiffel Tower"))