Skip to content

Commit d12d982

Browse files
committed
initial commit for using open AI APIs
1 parent 5f4e080 commit d12d982

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

ads/aqua/client/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,20 @@ def embeddings(
582582
payload = {**(payload or {}), "input": input}
583583
return self._request(payload=payload, headers=headers)
584584

585+
def list_models(self) -> Union[Dict[str, Any], Iterator[Mapping[str, Any]]]:
586+
"""Generate embeddings by sending a request to the endpoint.
587+
588+
Args:
589+
590+
Returns:
591+
Union[Dict[str, Any], Iterator[Mapping[str, Any]]]: The server's response, typically including the generated embeddings.
592+
"""
593+
headers = {"Content-Type", "application/json"}
594+
response = self._client.get(self.endpoint, headers=headers, json={}).json()
595+
json_response = response.json()
596+
logger.debug(f"Response JSON: {json_response}")
597+
return json_response
598+
585599

586600
class AsyncClient(BaseClient):
587601
"""

ads/aqua/extension/deployment_handler.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,38 @@ def post(self, *args, **kwargs): # noqa: ARG002
373373
)
374374

375375

376+
class AquaModelListHandler(AquaAPIhandler):
377+
"""Handler for Aqua model list params REST APIs.
378+
379+
Methods
380+
-------
381+
get(self, *args, **kwargs)
382+
Validates parameters for the given model id.
383+
"""
384+
385+
@handle_exceptions
386+
def get(self, model_deployment_id):
387+
"""
388+
Handles streaming inference request for the Active Model Deployments
389+
Raises
390+
------
391+
HTTPError
392+
Raises HTTPError if inputs are missing or are invalid
393+
"""
394+
395+
self.set_header("Content-Type", "application/json")
396+
397+
model_deployment = AquaDeploymentApp().get(model_deployment_id)
398+
endpoint = model_deployment.endpoint + "/predict/v1/models"
399+
400+
aqua_client = Client(endpoint=endpoint)
401+
try:
402+
list_model_result = aqua_client.list_models()
403+
return self.finish(list_model_result)
404+
except Exception as ex:
405+
raise HTTPError(500, str(ex))
406+
407+
376408
__handlers__ = [
377409
("deployments/?([^/]*)/params", AquaDeploymentParamsHandler),
378410
("deployments/config/?([^/]*)", AquaDeploymentHandler),
@@ -381,4 +413,5 @@ def post(self, *args, **kwargs): # noqa: ARG002
381413
("deployments/?([^/]*)/activate", AquaDeploymentHandler),
382414
("deployments/?([^/]*)/deactivate", AquaDeploymentHandler),
383415
("inference/stream/?([^/]*)", AquaDeploymentStreamingInferenceHandler),
416+
("deployments/models/list/?([^/]*)", AquaModelListHandler),
384417
]

0 commit comments

Comments
 (0)