MCPcopy Create free account
hub / github.com/Open-Bee/DataStudio / _request_non_streaming

Method _request_non_streaming

datastudio/models/openai_api.py:197–230  ·  view source on GitHub ↗

Make a non-streaming API request. Args: session: Shared aiohttp session. message: Preprocessed message list. **kwargs: Additional parameters. Returns: Tuple of (ret_code, response_content).

(
        self,
        session: aiohttp.ClientSession,
        message: List[dict],
        **kwargs,
    )

Source from the content-addressed store, hash-verified

195 return payload
196
197 async def _request_non_streaming(
198 self,
199 session: aiohttp.ClientSession,
200 message: List[dict],
201 **kwargs,
202 ) -> Tuple[int, Any]:
203 """Make a non-streaming API request.
204
205 Args:
206 session: Shared aiohttp session.
207 message: Preprocessed message list.
208 **kwargs: Additional parameters.
209
210 Returns:
211 Tuple of (ret_code, response_content).
212 """
213 headers = self._build_openai_headers()
214 payload = self._build_payload(message, **kwargs)
215
216 async with session.post(
217 self.api_base, json=payload, headers=headers
218 ) as response:
219 resp_status = response.status
220 if resp_status == 200:
221 data = await response.json(content_type=None)
222 else:
223 error_text = await response.text()
224
225 if resp_status != 200:
226 return 1, f"HTTP {resp_status}: {error_text[:200]}"
227
228 # Post-process OUTSIDE connection scope
229 answer = self._parse_openai_response(data)
230 return 0, answer
231
232 async def _make_request(
233 self,

Calls 3

_build_openai_headersMethod · 0.95
_build_payloadMethod · 0.95