Eric Botti
commited on
Commit
·
5dbe83d
1
Parent(s):
dfdde45
readded message logging
Browse files- .gitignore +2 -1
- src/agent_interfaces.py +2 -0
- src/data_collection.py +32 -0
.gitignore
CHANGED
@@ -2,4 +2,5 @@
|
|
2 |
/experiments/
|
3 |
/test/
|
4 |
/.idea/
|
5 |
-
*/__pycache__/
|
|
|
|
2 |
/experiments/
|
3 |
/test/
|
4 |
/.idea/
|
5 |
+
*/__pycache__/
|
6 |
+
/data/
|
src/agent_interfaces.py
CHANGED
@@ -6,6 +6,7 @@ from colorama import Fore, Style
|
|
6 |
from pydantic import BaseModel, ValidationError
|
7 |
|
8 |
from message import Message, AgentMessage
|
|
|
9 |
|
10 |
FORMAT_INSTRUCTIONS = """The output should be reformatted as a JSON instance that conforms to the JSON schema below.
|
11 |
Here is the output schema:
|
@@ -33,6 +34,7 @@ class BaseAgentInterface:
|
|
33 |
def add_message(self, message: Message):
|
34 |
"""Adds a message to the message history, without generating a response."""
|
35 |
bound_message = AgentMessage.from_message(message, self.id, len(self.messages))
|
|
|
36 |
self.messages.append(bound_message)
|
37 |
|
38 |
def respond_to(self, message: Message) -> Message:
|
|
|
6 |
from pydantic import BaseModel, ValidationError
|
7 |
|
8 |
from message import Message, AgentMessage
|
9 |
+
from data_collection import save
|
10 |
|
11 |
FORMAT_INSTRUCTIONS = """The output should be reformatted as a JSON instance that conforms to the JSON schema below.
|
12 |
Here is the output schema:
|
|
|
34 |
def add_message(self, message: Message):
|
35 |
"""Adds a message to the message history, without generating a response."""
|
36 |
bound_message = AgentMessage.from_message(message, self.id, len(self.messages))
|
37 |
+
save(bound_message)
|
38 |
self.messages.append(bound_message)
|
39 |
|
40 |
def respond_to(self, message: Message) -> Message:
|
src/data_collection.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from typing import NewType
|
3 |
+
|
4 |
+
import pydantic
|
5 |
+
|
6 |
+
import message
|
7 |
+
import player
|
8 |
+
|
9 |
+
from pydantic import BaseModel
|
10 |
+
|
11 |
+
Model = NewType("Model", BaseModel)
|
12 |
+
|
13 |
+
|
14 |
+
data_dir = os.path.join(os.pardir, "data")
|
15 |
+
|
16 |
+
|
17 |
+
def save(log_object: Model):
|
18 |
+
log_file = get_log_file(log_object)
|
19 |
+
|
20 |
+
with open(log_file, "a+") as f:
|
21 |
+
f.write(log_object.model_dump_json() + "\n")
|
22 |
+
|
23 |
+
|
24 |
+
def get_log_file(log_object: Model) -> str:
|
25 |
+
match type(log_object):
|
26 |
+
case message.AgentMessage:
|
27 |
+
log_file = "messages.jsonl"
|
28 |
+
# ...
|
29 |
+
case _:
|
30 |
+
raise ValueError(f"Unknown log object type: {type(log_object)}")
|
31 |
+
|
32 |
+
return os.path.join(data_dir, log_file)
|