-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsentinel.py
More file actions
63 lines (48 loc) · 2.14 KB
/
sentinel.py
File metadata and controls
63 lines (48 loc) · 2.14 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
from utils.logger import Logger
from agents.guard import Guard
from agents.burglar import Burglar
from utils.functions import LLMFunctions
"""
This class is used to analyse camera feeds and create memory blocks
"""
class Sentinel():
def __init__(self, max_memories: int = 0):
self.max_memories = max_memories
self.guard = Guard(max_memories=max_memories, use_automations=True)
self.burglar = Burglar()
self.llm_func = LLMFunctions()
def analyze_feed(self, description: str) -> str | None:
response = ''
turns = 0
# Kickstart the Guard by prompting it with the CameraFeed
response = self.guard.send_message(f'CameraFeed: {description}')
if response is None:
Logger.error('Error sending message')
return None
response = f'Guard: {response}\nCameraFeed: {description}\n'
#Logger.info(response)
if self.llm_func.is_function_call(response):
Logger.info(f'Decision taken without consultation: {response}')
return response
# The conversation can go on and on forever but we like the thrill of the unknown
# so if that happens, we'll be there to witness it!
# AKA the loop is not interrupted on purpose
while True:
burg = self.burglar.send_message(response)
#Logger.info(f'Ex-burglar: {burg}')
response += 'Ex-burglar: ' + burg + '\n'
decision = self.guard.send_message(response)
#Logger.info(f'Guard: {decision}')
if self.llm_func.is_function_call(decision):
#Logger.info(f'Verdict achieved: {decision} at turn {turns}')
break
response += 'Guard: ' + decision + '\n'
turns += 1
return decision
def get_cumulative_tokens(self) -> dict:
guard = self.guard.get_cumulative_tokens()
burglar = self.burglar.get_cumulative_tokens()
return {
'completion_tokens': guard['completion_tokens'] + burglar['completion_tokens'],
'prompt_tokens': guard['prompt_tokens'] + burglar['prompt_tokens']
}