Skip to content

Commit

Permalink
Laying down basic strokes of standard get_data response
Browse files Browse the repository at this point in the history
  • Loading branch information
JackUrb committed Sep 14, 2023
1 parent 3c75caa commit 6cbf7fb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def validate_screening_unit(unit: Unit):
agent = unit.get_assigned_agent()
if agent is not None:
data = agent.state.get_data()
annotation = data["final_submission"]["annotations"][0]
annotation = data["outputs"]["final_submission"]["annotations"][0]
if annotation["isCorrect"] and annotation["currentAnnotation"] == 3:
return True
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ function Instructions({ taskData }) {
);
}

function TaskFrontend({ taskData, classifyDigit, handleSubmit }) {
function TaskFrontend({
taskData,
finalResults = null,
classifyDigit,
handleSubmit,
}) {
// TODO Update this file such that, if finalResults contains data we render in review mode with that data
const NUM_ANNOTATIONS = taskData.isScreeningUnit ? 1 : 3;
const [annotations, updateAnnotations] = React.useReducer(
(currentAnnotation, { updateIdx, updatedAnnotation }) => {
Expand Down
4 changes: 4 additions & 0 deletions mephisto/abstractions/_subcomponents/agent_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ def load_data(self) -> None:
def get_data(self) -> Dict[str, Any]:
"""
Return the currently stored data for this task
Data should however always follow the format of having an "inputs" and "outputs"
format, wherein "inputs" are whatever data was passed through to initialTaskData
and outputs can be whatever the results were.
"""
raise NotImplementedError()

Expand Down
5 changes: 4 additions & 1 deletion mephisto/abstractions/blueprints/mock/mock_agent_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def _load_data(self) -> None:

def get_data(self) -> Dict[str, Any]:
"""Return dict of this agent's state"""
return self.state
return {
"inputs": self.init_state,
"outputs": self.state,
}

def _save_data(self) -> None:
"""Mock agents don't save data (yet)"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ def _load_data(self) -> None:
agent_file = self._get_expected_data_file()
if self.agent.db.key_exists(agent_file):
state = self.agent.db.read_dict(agent_file)
self.requests = {x["uuid"]: RemoteRequest(**x) for x in state["requests"]}
self.init_data = state["init_data"]
self.final_submission = state["final_submission"]
self.requests = {x["uuid"]: RemoteRequest(**x) for x in state["outputs"]["requests"]}
self.init_data = state["inputs"]
self.final_submission = state["outputs"]["final_submission"]
# Backwards compatibility for times
if "start_time" in state:
self.metadata.task_start = state["start_time"]
self.metadata.task_end = state["end_time"]

def get_data(self) -> Dict[str, Any]:
"""Return dict with the messages of this agent"""
# TODO init_data -> inputs, final_submission -> outputs.final_submission, requests -> outputs.requests
return {
"final_submission": self.final_submission,
"init_data": self.init_data,
"requests": [r.to_dict() for r in self.requests.values()],
"inputs": self.init_data,
"outputs": {
"final_submission": self.final_submission,
"requests": [r.to_dict() for r in self.requests.values()],
},
"start_time": self.metadata.task_start,
"end_time": self.metadata.task_end,
}
Expand Down

0 comments on commit 6cbf7fb

Please sign in to comment.