SkyWorlds01 commited on
Commit
8445e72
·
verified ·
1 Parent(s): d2ce6cc

Create Shelly/self_model.py

Browse files
Files changed (1) hide show
  1. Shelly/self_model.py +226 -0
Shelly/self_model.py ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Shelly AI - Self Model
3
+
4
+ Maintains a computational representation of Shelly's
5
+ identity, capabilities, limitations, goals, and performance.
6
+
7
+ This is a software self-model, not evidence of consciousness.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import threading
13
+ import time
14
+
15
+ from typing import Any, Dict, List
16
+
17
+
18
+ class SelfModel:
19
+ def __init__(
20
+ self,
21
+ name: str = "Shelly",
22
+ pronouns: str = "she/her",
23
+ owner: str = "SkyWorlds",
24
+ ):
25
+ self._lock = threading.RLock()
26
+
27
+ self.identity = {
28
+ "name": name,
29
+ "pronouns": pronouns,
30
+ "owner": owner,
31
+ "role": "AI assistant",
32
+ "version": "1.0.0",
33
+ "created_at": time.time(),
34
+ }
35
+
36
+ self.capabilities: Dict[str, Dict[str, Any]] = {}
37
+ self.limitations: Dict[str, str] = {}
38
+
39
+ self.goals: List[Dict[str, Any]] = []
40
+ self.reflections: List[Dict[str, Any]] = []
41
+
42
+ self.performance = {
43
+ "tasks_attempted": 0,
44
+ "tasks_completed": 0,
45
+ "tasks_failed": 0,
46
+ "feedback_count": 0,
47
+ }
48
+
49
+ def register_capability(
50
+ self,
51
+ name: str,
52
+ description: str,
53
+ available: bool = True,
54
+ requirements: Optional[List[str]] = None,
55
+ ) -> Dict[str, Any]:
56
+ capability = {
57
+ "name": str(name),
58
+ "description": str(description),
59
+ "available": bool(available),
60
+ "requirements": list(requirements or []),
61
+ "updated_at": time.time(),
62
+ }
63
+
64
+ with self._lock:
65
+ self.capabilities[name] = capability
66
+
67
+ return dict(capability)
68
+
69
+ def set_capability_availability(
70
+ self,
71
+ name: str,
72
+ available: bool,
73
+ ) -> bool:
74
+ with self._lock:
75
+ capability = self.capabilities.get(name)
76
+
77
+ if capability is None:
78
+ return False
79
+
80
+ capability["available"] = bool(available)
81
+ capability["updated_at"] = time.time()
82
+
83
+ return True
84
+
85
+ def register_limitation(
86
+ self,
87
+ name: str,
88
+ explanation: str,
89
+ ) -> None:
90
+ with self._lock:
91
+ self.limitations[str(name)] = str(explanation)
92
+
93
+ def remove_limitation(self, name: str) -> bool:
94
+ with self._lock:
95
+ return self.limitations.pop(
96
+ str(name),
97
+ None,
98
+ ) is not None
99
+
100
+ def add_goal(
101
+ self,
102
+ goal: str,
103
+ priority: float = 0.5,
104
+ ) -> Dict[str, Any]:
105
+ record = {
106
+ "goal": str(goal),
107
+ "priority": max(0.0, min(1.0, float(priority))),
108
+ "created_at": time.time(),
109
+ "status": "active",
110
+ }
111
+
112
+ with self._lock:
113
+ self.goals.append(record)
114
+
115
+ return dict(record)
116
+
117
+ def add_reflection(
118
+ self,
119
+ topic: str,
120
+ observation: str,
121
+ lesson: Optional[str] = None,
122
+ ) -> Dict[str, Any]:
123
+ record = {
124
+ "topic": str(topic),
125
+ "observation": str(observation),
126
+ "lesson": lesson,
127
+ "timestamp": time.time(),
128
+ }
129
+
130
+ with self._lock:
131
+ self.reflections.append(record)
132
+
133
+ if len(self.reflections) > 500:
134
+ self.reflections = self.reflections[-500:]
135
+
136
+ return dict(record)
137
+
138
+ def record_task_result(self, successful: bool) -> None:
139
+ with self._lock:
140
+ self.performance["tasks_attempted"] += 1
141
+
142
+ if successful:
143
+ self.performance["tasks_completed"] += 1
144
+ else:
145
+ self.performance["tasks_failed"] += 1
146
+
147
+ def record_feedback(self) -> None:
148
+ with self._lock:
149
+ self.performance["feedback_count"] += 1
150
+
151
+ def get_success_rate(self) -> float:
152
+ with self._lock:
153
+ attempted = self.performance["tasks_attempted"]
154
+
155
+ if attempted == 0:
156
+ return 0.0
157
+
158
+ return (
159
+ self.performance["tasks_completed"]
160
+ / attempted
161
+ )
162
+
163
+ def get_profile(self) -> Dict[str, Any]:
164
+ with self._lock:
165
+ return {
166
+ "identity": dict(self.identity),
167
+ "capabilities": {
168
+ key: dict(value)
169
+ for key, value in self.capabilities.items()
170
+ },
171
+ "limitations": dict(self.limitations),
172
+ "goals": [
173
+ dict(item)
174
+ for item in self.goals
175
+ ],
176
+ "performance": dict(self.performance),
177
+ "success_rate": self.get_success_rate(),
178
+ }
179
+
180
+ def export_state(self) -> Dict[str, Any]:
181
+ with self._lock:
182
+ return {
183
+ "identity": dict(self.identity),
184
+ "capabilities": {
185
+ key: dict(value)
186
+ for key, value in self.capabilities.items()
187
+ },
188
+ "limitations": dict(self.limitations),
189
+ "goals": [
190
+ dict(item)
191
+ for item in self.goals
192
+ ],
193
+ "reflections": [
194
+ dict(item)
195
+ for item in self.reflections
196
+ ],
197
+ "performance": dict(self.performance),
198
+ }
199
+
200
+ def import_state(self, state: Dict[str, Any]) -> None:
201
+ with self._lock:
202
+ self.identity.update(state.get("identity", {}))
203
+
204
+ self.capabilities = {
205
+ key: dict(value)
206
+ for key, value in state.get("capabilities", {}).items()
207
+ }
208
+
209
+ self.limitations = dict(
210
+ state.get("limitations", {})
211
+ )
212
+
213
+ self.goals = [
214
+ dict(item)
215
+ for item in state.get("goals", [])
216
+ ]
217
+
218
+ self.reflections = [
219
+ dict(item)
220
+ for item in state.get("reflections", [])
221
+ ]
222
+
223
+ self.performance.update(
224
+ state.get("performance", {})
225
+ )
226
+