Skip to content

Commit 78b06eb

Browse files
authored
Changed outputs to list (#131)
* changed outputs to support list * fixed CI for tests for python api server * added None check
1 parent 267ab06 commit 78b06eb

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ name: Python API Server Tests
33
on:
44
push:
55
branches: [main]
6+
paths:
7+
- 'api-server/**'
68
pull_request:
79
branches: [main]
10+
paths:
11+
- 'api-server/**'
812

913
jobs:
1014
test:

python-sdk/exospherehost/node/BaseNode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC, abstractmethod
2-
from typing import Optional, Any
2+
from typing import Optional, Any, List
33

44

55
class BaseNode(ABC):
@@ -8,7 +8,7 @@ def __init__(self, unique_name: Optional[str] = None):
88
self.unique_name: Optional[str] = unique_name
99

1010
@abstractmethod
11-
async def execute(self, inputs: dict[str, Any]) -> dict[str, Any]:
11+
async def execute(self, inputs: dict[str, Any]) -> dict[str, Any] | List[dict[str, Any]]:
1212
pass
1313

1414
def get_unique_name(self) -> str:

python-sdk/exospherehost/runtime.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def _enqueue(self):
6969

7070
await sleep(self._poll_interval)
7171

72-
async def _notify_executed(self, state_id: str, outputs: dict[str, Any]):
72+
async def _notify_executed(self, state_id: str, outputs: List[dict[str, Any]]):
7373
async with ClientSession() as session:
7474
endpoint = self._get_executed_endpoint(state_id)
7575
body = {"outputs": outputs}
@@ -112,7 +112,15 @@ async def _worker(self):
112112
try:
113113
node = self._node_mapping[state["node_name"]]
114114
outputs = await node.execute(state["inputs"]) # type: ignore
115+
116+
if outputs is None:
117+
outputs = []
118+
119+
if isinstance(outputs, dict):
120+
outputs = [outputs]
121+
115122
await self._notify_executed(state["state_id"], outputs)
123+
116124
except Exception as e:
117125
await self._notify_errored(state["state_id"], str(e))
118126

state-manager/app/models/executed_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from pydantic import BaseModel, Field
2-
from typing import Any
2+
from typing import Any, List
33
from .state_status_enum import StateStatusEnum
44

55
class ExecutedRequestModel(BaseModel):
6-
outputs: dict[str, Any] = Field(..., description="Outputs of the state")
6+
outputs: List[dict[str, Any]] = Field(..., description="Outputs of the state")
77

88

99
class ExecutedResponseModel(BaseModel):

0 commit comments

Comments
 (0)