Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ads/aqua/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@ def embeddings(
payload = {**(payload or {}), "input": input}
return self._request(payload=payload, headers=headers)

def list_models(self) -> Union[Dict[str, Any], Iterator[Mapping[str, Any]]]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic in this method here seems generic, should we call it fetch_data or get_json_response instead oflist_models? Also, docstrings need to be changed here.

"""Generate embeddings by sending a request to the endpoint.

Args:

Returns:
Union[Dict[str, Any], Iterator[Mapping[str, Any]]]: The server's response, typically including the generated embeddings.
"""
headers = {"Content-Type", "application/json"}
response = self._client.get(self.endpoint, headers=headers, json={}).json()
json_response = response.json()
logger.debug(f"Response JSON: {json_response}")
return json_response


class AsyncClient(BaseClient):
"""
Expand Down
33 changes: 33 additions & 0 deletions ads/aqua/extension/deployment_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,38 @@ def post(self, *args, **kwargs): # noqa: ARG002
)


class AquaModelListHandler(AquaAPIhandler):
"""Handler for Aqua model list params REST APIs.

Methods
-------
get(self, *args, **kwargs)
Validates parameters for the given model id.
"""

@handle_exceptions
def get(self, model_deployment_id):
"""
Handles streaming inference request for the Active Model Deployments
Raises
------
HTTPError
Raises HTTPError if inputs are missing or are invalid
"""

self.set_header("Content-Type", "application/json")

model_deployment = AquaDeploymentApp().get(model_deployment_id)
endpoint = model_deployment.endpoint + "/predict/v1/models"

aqua_client = Client(endpoint=endpoint)
try:
list_model_result = aqua_client.list_models()
return self.finish(list_model_result)
except Exception as ex:
raise HTTPError(500, str(ex))


__handlers__ = [
("deployments/?([^/]*)/params", AquaDeploymentParamsHandler),
("deployments/config/?([^/]*)", AquaDeploymentHandler),
Expand All @@ -381,4 +413,5 @@ def post(self, *args, **kwargs): # noqa: ARG002
("deployments/?([^/]*)/activate", AquaDeploymentHandler),
("deployments/?([^/]*)/deactivate", AquaDeploymentHandler),
("inference/stream/?([^/]*)", AquaDeploymentStreamingInferenceHandler),
("deployments/models/list/?([^/]*)", AquaModelListHandler),
]
Loading