Skip to content

Commit

Permalink
Merge pull request #17 from synth-laboratories/better-system-id
Browse files Browse the repository at this point in the history
Add System id
  • Loading branch information
DoKu88 authored Dec 17, 2024
2 parents 762c43d + 9f160b9 commit d868c32
Show file tree
Hide file tree
Showing 19 changed files with 1,206 additions and 389 deletions.
4 changes: 2 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"Classes"
],
"summary": "abstractions.TrainingQuestion",
"description": "A training question is a question that an agent (system_id) is trying to answer.\nIt contains an intent and criteria that the agent is trying to meet.\n\n[View source on GitHub](https://github.com/synth-laboratories/synth-sdk/blob/main/synth_sdk/tracing/abstractions.py)",
"description": "A training question is a question that an agent (instance_system_id) is trying to answer.\nIt contains an intent and criteria that the agent is trying to meet.\n\n[View source on GitHub](https://github.com/synth-laboratories/synth-sdk/blob/main/synth_sdk/tracing/abstractions.py)",
"externalDocs": {
"description": "View source on GitHub",
"url": "https://github.com/synth-laboratories/synth-sdk/blob/main/synth_sdk/tracing/abstractions.py"
Expand Down Expand Up @@ -235,7 +235,7 @@
"Classes"
],
"summary": "abstractions.RewardSignal",
"description": "A reward signal tells us how well an agent (system_id) is doing on a particular question (question_id).\n\n[View source on GitHub](https://github.com/synth-laboratories/synth-sdk/blob/main/synth_sdk/tracing/abstractions.py)",
"description": "A reward signal tells us how well an agent (instance_system_id) is doing on a particular question (question_id).\n\n[View source on GitHub](https://github.com/synth-laboratories/synth-sdk/blob/main/synth_sdk/tracing/abstractions.py)",
"externalDocs": {
"description": "View source on GitHub",
"url": "https://github.com/synth-laboratories/synth-sdk/blob/main/synth_sdk/tracing/abstractions.py"
Expand Down
60 changes: 38 additions & 22 deletions synth_sdk/tracing/abstractions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
from dataclasses import dataclass
from typing import Any, List, Dict, Optional, Union
from datetime import datetime
from typing import Any, Dict, List, Optional, Union

from pydantic import BaseModel
import logging
from synth_sdk.tracing.config import VALID_TYPES


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -39,13 +40,15 @@ class ComputeStep:
def to_dict(self):
# Serialize compute_input
serializable_input = [
input_item.__dict__ for input_item in self.compute_input
input_item.__dict__
for input_item in self.compute_input
if isinstance(input_item, (MessageInputs, ArbitraryInputs))
]

# Serialize compute_output
serializable_output = [
output_item.__dict__ for output_item in self.compute_output
output_item.__dict__
for output_item in self.compute_output
if isinstance(output_item, (MessageOutputs, ArbitraryOutputs))
]

Expand All @@ -59,8 +62,12 @@ def to_dict(self):

return {
"event_order": self.event_order,
"compute_ended": self.compute_ended.isoformat() if isinstance(self.compute_ended, datetime) else self.compute_ended,
"compute_began": self.compute_began.isoformat() if isinstance(self.compute_began, datetime) else self.compute_began,
"compute_ended": self.compute_ended.isoformat()
if isinstance(self.compute_ended, datetime)
else self.compute_ended,
"compute_began": self.compute_began.isoformat()
if isinstance(self.compute_began, datetime)
else self.compute_began,
"compute_input": serializable_input,
"compute_output": serializable_output,
}
Expand All @@ -86,7 +93,7 @@ class EnvironmentComputeStep(ComputeStep):

@dataclass
class Event:
system_id: str
instance_system_id: str
event_type: str
opened: Any # timestamp
closed: Any # timestamp
Expand All @@ -97,8 +104,12 @@ class Event:
def to_dict(self):
return {
"event_type": self.event_type,
"opened": self.opened.isoformat() if isinstance(self.opened, datetime) else self.opened,
"closed": self.closed.isoformat() if isinstance(self.closed, datetime) else self.closed,
"opened": self.opened.isoformat()
if isinstance(self.opened, datetime)
else self.opened,
"closed": self.closed.isoformat()
if isinstance(self.closed, datetime)
else self.closed,
"partition_index": self.partition_index,
"agent_compute_steps": [
step.to_dict() for step in self.agent_compute_steps
Expand All @@ -124,24 +135,27 @@ def to_dict(self):
@dataclass
class SystemTrace:
system_id: str
instance_system_id: str
metadata: Optional[Dict[str, Any]]
partition: List[EventPartitionElement]
current_partition_index: int = 0 # Track current partition

def to_dict(self):
return {
"system_id": self.system_id,
"instance_system_id": self.instance_system_id,
"partition": [element.to_dict() for element in self.partition],
"current_partition_index": self.current_partition_index,
"metadata": self.metadata if self.metadata else None
"metadata": self.metadata if self.metadata else None,
}


class TrainingQuestion(BaseModel):
'''
A training question is a question that an agent (system_id) is trying to answer.
"""
A training question is a question that an agent (instance_system_id) is trying to answer.
It contains an intent and criteria that the agent is trying to meet.
'''
"""

id: str
intent: str
criteria: str
Expand All @@ -155,28 +169,30 @@ def to_dict(self):


class RewardSignal(BaseModel):
'''
A reward signal tells us how well an agent (system_id) is doing on a particular question (question_id).
'''
"""
A reward signal tells us how well an agent (instance_system_id) is doing on a particular question (question_id).
"""

question_id: str
system_id: str
instance_system_id: str
reward: Union[float, int, bool]
annotation: Optional[str] = None

def to_dict(self):
return {
"question_id": self.question_id,
"system_id": self.system_id,
"instance_system_id": self.instance_system_id,
"reward": self.reward,
"annotation": self.annotation,
}


class Dataset(BaseModel):
'''
A dataset is a collection of training questions and reward signals.
"""
A dataset is a collection of training questions and reward signals.
This better represents the data that is used to train a model, and gives us more information about the data.
'''
"""

questions: List[TrainingQuestion]
reward_signals: List[RewardSignal]

Expand Down
Loading

0 comments on commit d868c32

Please sign in to comment.