Skip to content

Commit

Permalink
Add hypothesis fake data gen, make v2 for chains required at runtime,…
Browse files Browse the repository at this point in the history
… use root model for output
  • Loading branch information
marius-baseten committed May 20, 2024
1 parent 7d5eade commit 688c075
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
61 changes: 60 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ watchfiles = "^0.19.0"
libcst = "<1.2.0"
autoflake = "<=2.2"
pytest-asyncio = "^0.23.6"
hypothesis-jsonschema = "^0.23.1"
hypothesis = "^6.102.4"

[tool.poetry.group.builder.dependencies]
blake3 = "^0.3.3"
Expand Down
5 changes: 5 additions & 0 deletions truss-chains/truss_chains/code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,8 @@ def gen_truss_chainlet(
/ "_model_dbg.py",
)
return chainlet_dir


def create_fake_json_data(chainlet_descriptor: definitions.ChainletAPIDescriptor):
input_src = _gen_truss_input_pydantic(chainlet_descriptor)
input_src_str = f"{input_src.imports.}"
17 changes: 17 additions & 0 deletions truss-chains/truss_chains/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,30 @@ def add_needed_chainlets(chainlet: definitions.ChainletAPIDescriptor):


class ChainService:
name: str
_entrypoint: str
_services: MutableMapping[str, b10_service.TrussService]
_entrypoint_fake_json_data = Any

def __init__(self, entrypoint: str, name: str) -> None:
self.name = name
self._entrypoint = entrypoint
self._services = collections.OrderedDict() # Preserve order.
self.entrypoint_fake_json_data = None

def add_service(self, name: str, service: b10_service.TrussService) -> None:
self._services[name] = service

@property
def entrypoint_fake_json_data(self) -> Any:
if self._entrypoint_fake_json_data is None:
raise ValueError("Fake data was not set.")
return self._entrypoint_fake_json_data

@entrypoint_fake_json_data.setter
def entrypoint_fake_json_data(self, fake_data: Any) -> None:
self._entrypoint_fake_json_data = fake_data

@property
def get_entrypoint(self) -> b10_service.TrussService:
service = self._services.get(self._entrypoint)
Expand Down Expand Up @@ -209,4 +222,8 @@ def deploy_remotely(
else:
chainlet_name_to_url[chainlet_descriptor.name] = "http://dummy"

chain_service.entrypoint_fake_json_data = code_gen.create_fake_json_data(
framework.global_chainlet_registry.get_descriptor(entrypoint)
)

return chain_service

0 comments on commit 688c075

Please sign in to comment.