|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, cast |
| 3 | +from uuid import UUID |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ... import errors |
| 8 | +from ...client import AuthenticatedClient, Client |
| 9 | +from ...models.ai_chat_response import AiChatResponse |
| 10 | +from ...types import UNSET, Response, Unset |
| 11 | + |
| 12 | + |
| 13 | +def _get_kwargs( |
| 14 | + *, |
| 15 | + message: str, |
| 16 | + session_id: UUID | Unset = UNSET, |
| 17 | + incident_id: UUID | Unset = UNSET, |
| 18 | + alert_id: UUID | Unset = UNSET, |
| 19 | +) -> dict[str, Any]: |
| 20 | + |
| 21 | + params: dict[str, Any] = {} |
| 22 | + |
| 23 | + params["message"] = message |
| 24 | + |
| 25 | + json_session_id: str | Unset = UNSET |
| 26 | + if not isinstance(session_id, Unset): |
| 27 | + json_session_id = str(session_id) |
| 28 | + params["session_id"] = json_session_id |
| 29 | + |
| 30 | + json_incident_id: str | Unset = UNSET |
| 31 | + if not isinstance(incident_id, Unset): |
| 32 | + json_incident_id = str(incident_id) |
| 33 | + params["incident_id"] = json_incident_id |
| 34 | + |
| 35 | + json_alert_id: str | Unset = UNSET |
| 36 | + if not isinstance(alert_id, Unset): |
| 37 | + json_alert_id = str(alert_id) |
| 38 | + params["alert_id"] = json_alert_id |
| 39 | + |
| 40 | + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} |
| 41 | + |
| 42 | + _kwargs: dict[str, Any] = { |
| 43 | + "method": "post", |
| 44 | + "url": "/v1/ai/chat", |
| 45 | + "params": params, |
| 46 | + } |
| 47 | + |
| 48 | + return _kwargs |
| 49 | + |
| 50 | + |
| 51 | +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> AiChatResponse | Any | None: |
| 52 | + if response.status_code == 200: |
| 53 | + response_200 = AiChatResponse.from_dict(response.json()) |
| 54 | + |
| 55 | + return response_200 |
| 56 | + |
| 57 | + if response.status_code == 403: |
| 58 | + response_403 = cast(Any, None) |
| 59 | + return response_403 |
| 60 | + |
| 61 | + if response.status_code == 422: |
| 62 | + response_422 = cast(Any, None) |
| 63 | + return response_422 |
| 64 | + |
| 65 | + if client.raise_on_unexpected_status: |
| 66 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 67 | + else: |
| 68 | + return None |
| 69 | + |
| 70 | + |
| 71 | +def _build_response( |
| 72 | + *, client: AuthenticatedClient | Client, response: httpx.Response |
| 73 | +) -> Response[AiChatResponse | Any]: |
| 74 | + return Response( |
| 75 | + status_code=HTTPStatus(response.status_code), |
| 76 | + content=response.content, |
| 77 | + headers=response.headers, |
| 78 | + parsed=_parse_response(client=client, response=response), |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | +def sync_detailed( |
| 83 | + *, |
| 84 | + client: AuthenticatedClient, |
| 85 | + message: str, |
| 86 | + session_id: UUID | Unset = UNSET, |
| 87 | + incident_id: UUID | Unset = UNSET, |
| 88 | + alert_id: UUID | Unset = UNSET, |
| 89 | +) -> Response[AiChatResponse | Any]: |
| 90 | + """Send AI chat message |
| 91 | +
|
| 92 | + Send a message to the AI assistant and receive a synchronous reply. Optionally bind the conversation |
| 93 | + to an incident or alert for context-aware responses. Requires `ai.chat:write` OAuth scope or an API |
| 94 | + key. |
| 95 | +
|
| 96 | + Args: |
| 97 | + message (str): |
| 98 | + session_id (UUID | Unset): |
| 99 | + incident_id (UUID | Unset): |
| 100 | + alert_id (UUID | Unset): |
| 101 | +
|
| 102 | + Raises: |
| 103 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 104 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 105 | +
|
| 106 | + Returns: |
| 107 | + Response[AiChatResponse | Any] |
| 108 | + """ |
| 109 | + |
| 110 | + kwargs = _get_kwargs( |
| 111 | + message=message, |
| 112 | + session_id=session_id, |
| 113 | + incident_id=incident_id, |
| 114 | + alert_id=alert_id, |
| 115 | + ) |
| 116 | + |
| 117 | + response = client.get_httpx_client().request( |
| 118 | + **kwargs, |
| 119 | + ) |
| 120 | + |
| 121 | + return _build_response(client=client, response=response) |
| 122 | + |
| 123 | + |
| 124 | +def sync( |
| 125 | + *, |
| 126 | + client: AuthenticatedClient, |
| 127 | + message: str, |
| 128 | + session_id: UUID | Unset = UNSET, |
| 129 | + incident_id: UUID | Unset = UNSET, |
| 130 | + alert_id: UUID | Unset = UNSET, |
| 131 | +) -> AiChatResponse | Any | None: |
| 132 | + """Send AI chat message |
| 133 | +
|
| 134 | + Send a message to the AI assistant and receive a synchronous reply. Optionally bind the conversation |
| 135 | + to an incident or alert for context-aware responses. Requires `ai.chat:write` OAuth scope or an API |
| 136 | + key. |
| 137 | +
|
| 138 | + Args: |
| 139 | + message (str): |
| 140 | + session_id (UUID | Unset): |
| 141 | + incident_id (UUID | Unset): |
| 142 | + alert_id (UUID | Unset): |
| 143 | +
|
| 144 | + Raises: |
| 145 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 146 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 147 | +
|
| 148 | + Returns: |
| 149 | + AiChatResponse | Any |
| 150 | + """ |
| 151 | + |
| 152 | + return sync_detailed( |
| 153 | + client=client, |
| 154 | + message=message, |
| 155 | + session_id=session_id, |
| 156 | + incident_id=incident_id, |
| 157 | + alert_id=alert_id, |
| 158 | + ).parsed |
| 159 | + |
| 160 | + |
| 161 | +async def asyncio_detailed( |
| 162 | + *, |
| 163 | + client: AuthenticatedClient, |
| 164 | + message: str, |
| 165 | + session_id: UUID | Unset = UNSET, |
| 166 | + incident_id: UUID | Unset = UNSET, |
| 167 | + alert_id: UUID | Unset = UNSET, |
| 168 | +) -> Response[AiChatResponse | Any]: |
| 169 | + """Send AI chat message |
| 170 | +
|
| 171 | + Send a message to the AI assistant and receive a synchronous reply. Optionally bind the conversation |
| 172 | + to an incident or alert for context-aware responses. Requires `ai.chat:write` OAuth scope or an API |
| 173 | + key. |
| 174 | +
|
| 175 | + Args: |
| 176 | + message (str): |
| 177 | + session_id (UUID | Unset): |
| 178 | + incident_id (UUID | Unset): |
| 179 | + alert_id (UUID | Unset): |
| 180 | +
|
| 181 | + Raises: |
| 182 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 183 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 184 | +
|
| 185 | + Returns: |
| 186 | + Response[AiChatResponse | Any] |
| 187 | + """ |
| 188 | + |
| 189 | + kwargs = _get_kwargs( |
| 190 | + message=message, |
| 191 | + session_id=session_id, |
| 192 | + incident_id=incident_id, |
| 193 | + alert_id=alert_id, |
| 194 | + ) |
| 195 | + |
| 196 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 197 | + |
| 198 | + return _build_response(client=client, response=response) |
| 199 | + |
| 200 | + |
| 201 | +async def asyncio( |
| 202 | + *, |
| 203 | + client: AuthenticatedClient, |
| 204 | + message: str, |
| 205 | + session_id: UUID | Unset = UNSET, |
| 206 | + incident_id: UUID | Unset = UNSET, |
| 207 | + alert_id: UUID | Unset = UNSET, |
| 208 | +) -> AiChatResponse | Any | None: |
| 209 | + """Send AI chat message |
| 210 | +
|
| 211 | + Send a message to the AI assistant and receive a synchronous reply. Optionally bind the conversation |
| 212 | + to an incident or alert for context-aware responses. Requires `ai.chat:write` OAuth scope or an API |
| 213 | + key. |
| 214 | +
|
| 215 | + Args: |
| 216 | + message (str): |
| 217 | + session_id (UUID | Unset): |
| 218 | + incident_id (UUID | Unset): |
| 219 | + alert_id (UUID | Unset): |
| 220 | +
|
| 221 | + Raises: |
| 222 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 223 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 224 | +
|
| 225 | + Returns: |
| 226 | + AiChatResponse | Any |
| 227 | + """ |
| 228 | + |
| 229 | + return ( |
| 230 | + await asyncio_detailed( |
| 231 | + client=client, |
| 232 | + message=message, |
| 233 | + session_id=session_id, |
| 234 | + incident_id=incident_id, |
| 235 | + alert_id=alert_id, |
| 236 | + ) |
| 237 | + ).parsed |
0 commit comments