Skip to content

Commit e8a6dd9

Browse files
committed
Adding streaming support for responses
1 parent b136a8c commit e8a6dd9

4 files changed

Lines changed: 572 additions & 144 deletions

File tree

src/lightspeed_evaluation/core/api/client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
wait_exponential,
1818
)
1919

20-
from lightspeed_evaluation.core.api.streaming_parser import parse_streaming_response
20+
from lightspeed_evaluation.core.api.streaming_parser import (
21+
parse_responses_streaming,
22+
parse_streaming_response,
23+
)
2124
from lightspeed_evaluation.core.constants import (
2225
SUPPORTED_ENDPOINT_TYPES,
2326
)
@@ -628,6 +631,16 @@ def _responses_query(self, api_request: APIRequest) -> APIResponse:
628631
try:
629632
responses_request = self._build_responses_request(api_request)
630633

634+
if responses_request.get("stream"):
635+
with self.client.stream(
636+
"POST",
637+
f"/{self.config.version}/responses",
638+
json=responses_request,
639+
) as response:
640+
self._handle_response_errors(response)
641+
raw_data = parse_responses_streaming(response)
642+
return APIResponse.from_raw_response(raw_data)
643+
631644
response = self.client.post(
632645
f"/{self.config.version}/responses",
633646
json=responses_request,

0 commit comments

Comments
 (0)