Skip to content

Commit e68c215

Browse files
Adding aqua client
1 parent d1d942d commit e68c215

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

ads/aqua/extension/deployment_handler.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import List, Union
66
from urllib.parse import urlparse
77

8-
from tornado.iostream import StreamClosedError
98
from tornado.web import HTTPError
109

1110
from ads.aqua.common.decorator import handle_exceptions
@@ -215,11 +214,9 @@ async def post(self, model_deployment_id):
215214
model_deployment_id, input_data
216215
)
217216
for chunk in response_gen:
218-
if not chunk:
219-
continue
220-
self.write(f"data: {chunk}\n\n")
217+
self.write(chunk)
221218
await self.flush()
222-
except StreamClosedError as ex:
219+
except Exception as ex:
223220
raise HTTPError(500, str(ex)) from ex
224221
finally:
225222
self.finish()

ads/aqua/modeldeployment/deployment.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from oci.data_science.models import ModelDeploymentShapeSummary
1212
from pydantic import ValidationError
1313

14+
from ads.aqua import Client
1415
from ads.aqua.app import AquaApp, logger
1516
from ads.aqua.common.entities import (
1617
AquaMultiModelRef,
@@ -1361,7 +1362,33 @@ def get_model_deployment_response(self, model_deployment_id: str, payload: dict)
13611362
13621363
"""
13631364

1364-
response = self.model_deployment_client.predict_with_response_stream(
1365-
model_deployment_id=model_deployment_id, request_body=payload
1365+
model_deployment = self.get(model_deployment_id)
1366+
endpoint = model_deployment.endpoint + "/predictWithResponseStream"
1367+
endpoint_type = model_deployment.environment_variables.get(
1368+
"MODEL_DEPLOY_PREDICT_ENDPOINT", "/v1/completions"
13661369
)
1367-
yield from self._stream_sanitizer(response)
1370+
aqua_client = Client(endpoint=endpoint)
1371+
if endpoint_type == "/v1/completions":
1372+
for chunk in aqua_client.generate(
1373+
prompt=payload.pop("prompt"),
1374+
payload=payload,
1375+
stream=True,
1376+
):
1377+
try:
1378+
yield chunk["choices"][0]["text"]
1379+
except Exception as e:
1380+
logger.debug(
1381+
f"Exception occurred while parsing streaming response: {e}"
1382+
)
1383+
else:
1384+
for chunk in aqua_client.chat(
1385+
messages=payload.pop("messages"),
1386+
payload=payload,
1387+
stream=True,
1388+
):
1389+
try:
1390+
yield chunk["choices"][0]["delta"]["content"]
1391+
except Exception as e:
1392+
logger.debug(
1393+
f"Exception occurred while parsing streaming response: {e}"
1394+
)

0 commit comments

Comments
 (0)