Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix list_service method not returning expected response (#787) #788

Merged
merged 10 commits into from
Nov 8, 2024
15 changes: 13 additions & 2 deletions comps/cores/mega/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,19 @@

def list_service(self):
response = {}
for node in self.all_leaves():
response = {self.services[node].description: self.services[node].endpoint_path}
for node, service in self.megaservice.services.items():

Check warning on line 75 in comps/cores/mega/gateway.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/gateway.py#L75

Added line #L75 was not covered by tests
# Check if the service has a 'description' attribute and it is not None
if hasattr(service, "description") and service.description:
response[node] = {"description": service.description}

Check warning on line 78 in comps/cores/mega/gateway.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/gateway.py#L77-L78

Added lines #L77 - L78 were not covered by tests
# Check if the service has an 'endpoint' attribute and it is not None
if hasattr(service, "endpoint") and service.endpoint:
if node in response:
response[node]["endpoint"] = service.endpoint

Check warning on line 82 in comps/cores/mega/gateway.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/gateway.py#L80-L82

Added lines #L80 - L82 were not covered by tests
else:
response[node] = {"endpoint": service.endpoint}

Check warning on line 84 in comps/cores/mega/gateway.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/gateway.py#L84

Added line #L84 was not covered by tests
# If neither 'description' nor 'endpoint' is available, add an error message for the node
if node not in response:
response[node] = {"error": f"Service node {node} does not have 'description' or 'endpoint' attribute."}

Check warning on line 87 in comps/cores/mega/gateway.py

View check run for this annotation

Codecov / codecov/patch

comps/cores/mega/gateway.py#L86-L87

Added lines #L86 - L87 were not covered by tests
return response

def list_parameter(self):
Expand Down
2 changes: 2 additions & 0 deletions comps/cores/mega/micro_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
provider: Optional[str] = None,
provider_endpoint: Optional[str] = None,
use_remote_service: Optional[bool] = False,
description: Optional[str] = None,
dynamic_batching: bool = False,
dynamic_batching_timeout: int = 1,
dynamic_batching_max_batch_size: int = 32,
Expand All @@ -53,6 +54,7 @@ def __init__(
self.input_datatype = input_datatype
self.output_datatype = output_datatype
self.use_remote_service = use_remote_service
self.description = description
self.dynamic_batching = dynamic_batching
self.dynamic_batching_timeout = dynamic_batching_timeout
self.dynamic_batching_max_batch_size = dynamic_batching_max_batch_size
Expand Down