|
10 | 10 | from json.decoder import JSONDecodeError
|
11 | 11 | from ..core.api_error import ApiError
|
12 | 12 | from ..types.code_synthesis_response import CodeSynthesisResponse
|
| 13 | +from ..types.magic_response import MagicResponse |
13 | 14 | from ..core.client_wrapper import AsyncClientWrapper
|
14 | 15 |
|
15 | 16 |
|
@@ -143,6 +144,70 @@ def synthesize(
|
143 | 144 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
144 | 145 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
145 | 146 |
|
| 147 | + def magic_request( |
| 148 | + self, *, query: str, cell: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None |
| 149 | + ) -> MagicResponse: |
| 150 | + """ |
| 151 | + Interactive assistant for IPython extension |
| 152 | +
|
| 153 | + Parameters |
| 154 | + ---------- |
| 155 | + query : str |
| 156 | +
|
| 157 | + cell : typing.Optional[str] |
| 158 | +
|
| 159 | + request_options : typing.Optional[RequestOptions] |
| 160 | + Request-specific configuration. |
| 161 | +
|
| 162 | + Returns |
| 163 | + ------- |
| 164 | + MagicResponse |
| 165 | + Successful Response |
| 166 | +
|
| 167 | + Examples |
| 168 | + -------- |
| 169 | + from axiomatic import Axiomatic |
| 170 | +
|
| 171 | + client = Axiomatic( |
| 172 | + api_key="YOUR_API_KEY", |
| 173 | + ) |
| 174 | + client.experimental.magic_request( |
| 175 | + query="query", |
| 176 | + ) |
| 177 | + """ |
| 178 | + _response = self._client_wrapper.httpx_client.request( |
| 179 | + "experimental/circuit_assistant", |
| 180 | + method="POST", |
| 181 | + params={ |
| 182 | + "query": query, |
| 183 | + "cell": cell, |
| 184 | + }, |
| 185 | + request_options=request_options, |
| 186 | + ) |
| 187 | + try: |
| 188 | + if 200 <= _response.status_code < 300: |
| 189 | + return typing.cast( |
| 190 | + MagicResponse, |
| 191 | + parse_obj_as( |
| 192 | + type_=MagicResponse, # type: ignore |
| 193 | + object_=_response.json(), |
| 194 | + ), |
| 195 | + ) |
| 196 | + if _response.status_code == 422: |
| 197 | + raise UnprocessableEntityError( |
| 198 | + typing.cast( |
| 199 | + HttpValidationError, |
| 200 | + parse_obj_as( |
| 201 | + type_=HttpValidationError, # type: ignore |
| 202 | + object_=_response.json(), |
| 203 | + ), |
| 204 | + ) |
| 205 | + ) |
| 206 | + _response_json = _response.json() |
| 207 | + except JSONDecodeError: |
| 208 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 209 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 210 | + |
146 | 211 |
|
147 | 212 | class AsyncExperimentalClient:
|
148 | 213 | def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
@@ -289,3 +354,75 @@ async def main() -> None:
|
289 | 354 | except JSONDecodeError:
|
290 | 355 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
291 | 356 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
| 357 | + |
| 358 | + async def magic_request( |
| 359 | + self, *, query: str, cell: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None |
| 360 | + ) -> MagicResponse: |
| 361 | + """ |
| 362 | + Interactive assistant for IPython extension |
| 363 | +
|
| 364 | + Parameters |
| 365 | + ---------- |
| 366 | + query : str |
| 367 | +
|
| 368 | + cell : typing.Optional[str] |
| 369 | +
|
| 370 | + request_options : typing.Optional[RequestOptions] |
| 371 | + Request-specific configuration. |
| 372 | +
|
| 373 | + Returns |
| 374 | + ------- |
| 375 | + MagicResponse |
| 376 | + Successful Response |
| 377 | +
|
| 378 | + Examples |
| 379 | + -------- |
| 380 | + import asyncio |
| 381 | +
|
| 382 | + from axiomatic import AsyncAxiomatic |
| 383 | +
|
| 384 | + client = AsyncAxiomatic( |
| 385 | + api_key="YOUR_API_KEY", |
| 386 | + ) |
| 387 | +
|
| 388 | +
|
| 389 | + async def main() -> None: |
| 390 | + await client.experimental.magic_request( |
| 391 | + query="query", |
| 392 | + ) |
| 393 | +
|
| 394 | +
|
| 395 | + asyncio.run(main()) |
| 396 | + """ |
| 397 | + _response = await self._client_wrapper.httpx_client.request( |
| 398 | + "experimental/circuit_assistant", |
| 399 | + method="POST", |
| 400 | + params={ |
| 401 | + "query": query, |
| 402 | + "cell": cell, |
| 403 | + }, |
| 404 | + request_options=request_options, |
| 405 | + ) |
| 406 | + try: |
| 407 | + if 200 <= _response.status_code < 300: |
| 408 | + return typing.cast( |
| 409 | + MagicResponse, |
| 410 | + parse_obj_as( |
| 411 | + type_=MagicResponse, # type: ignore |
| 412 | + object_=_response.json(), |
| 413 | + ), |
| 414 | + ) |
| 415 | + if _response.status_code == 422: |
| 416 | + raise UnprocessableEntityError( |
| 417 | + typing.cast( |
| 418 | + HttpValidationError, |
| 419 | + parse_obj_as( |
| 420 | + type_=HttpValidationError, # type: ignore |
| 421 | + object_=_response.json(), |
| 422 | + ), |
| 423 | + ) |
| 424 | + ) |
| 425 | + _response_json = _response.json() |
| 426 | + except JSONDecodeError: |
| 427 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 428 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
0 commit comments