airia 0.1.13__py3-none-any.whl → 0.1.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airia/client/_request_handler/__init__.py +4 -0
- airia/client/_request_handler/async_request_handler.py +272 -0
- airia/client/_request_handler/base_request_handler.py +108 -0
- airia/client/_request_handler/sync_request_handler.py +255 -0
- airia/client/async_client.py +25 -678
- airia/client/base_client.py +2 -368
- airia/client/conversations/__init__.py +4 -0
- airia/client/conversations/async_conversations.py +187 -0
- airia/client/conversations/base_conversations.py +135 -0
- airia/client/conversations/sync_conversations.py +182 -0
- airia/client/pipeline_execution/__init__.py +4 -0
- airia/client/pipeline_execution/async_pipeline_execution.py +178 -0
- airia/client/pipeline_execution/base_pipeline_execution.py +96 -0
- airia/client/pipeline_execution/sync_pipeline_execution.py +178 -0
- airia/client/pipelines_config/__init__.py +4 -0
- airia/client/pipelines_config/async_pipelines_config.py +127 -0
- airia/client/pipelines_config/base_pipelines_config.py +76 -0
- airia/client/pipelines_config/sync_pipelines_config.py +127 -0
- airia/client/project/__init__.py +4 -0
- airia/client/project/async_project.py +122 -0
- airia/client/project/base_project.py +74 -0
- airia/client/project/sync_project.py +120 -0
- airia/client/store/__init__.py +4 -0
- airia/client/store/async_store.py +377 -0
- airia/client/store/base_store.py +243 -0
- airia/client/store/sync_store.py +352 -0
- airia/client/sync_client.py +25 -656
- airia/constants.py +1 -1
- airia/exceptions.py +8 -8
- airia/logs.py +9 -9
- airia/types/_request_data.py +11 -4
- airia/types/api/__init__.py +0 -27
- airia/types/api/conversations/__init__.py +3 -0
- airia/types/api/{conversations.py → conversations/_conversations.py} +49 -12
- airia/types/api/pipeline_execution/__init__.py +13 -0
- airia/types/api/{pipeline_execution.py → pipeline_execution/_pipeline_execution.py} +30 -13
- airia/types/api/pipelines_config/__init__.py +3 -0
- airia/types/api/pipelines_config/get_pipeline_config.py +401 -0
- airia/types/api/project/__init__.py +3 -0
- airia/types/api/{get_projects.py → project/get_projects.py} +16 -4
- airia/types/api/store/__init__.py +4 -0
- airia/types/api/store/get_file.py +145 -0
- airia/types/api/store/get_files.py +21 -0
- airia/types/sse/__init__.py +1 -0
- airia/types/sse/sse_messages.py +55 -21
- airia/utils/sse_parser.py +5 -4
- {airia-0.1.13.dist-info → airia-0.1.14.dist-info}/METADATA +4 -2
- airia-0.1.14.dist-info/RECORD +55 -0
- airia/types/api/get_pipeline_config.py +0 -214
- airia-0.1.13.dist-info/RECORD +0 -24
- {airia-0.1.13.dist-info → airia-0.1.14.dist-info}/WHEEL +0 -0
- {airia-0.1.13.dist-info → airia-0.1.14.dist-info}/licenses/LICENSE +0 -0
- {airia-0.1.13.dist-info → airia-0.1.14.dist-info}/top_level.txt +0 -0
airia/client/async_client.py
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import weakref
|
|
3
|
-
from typing import Any, AsyncIterator, Dict, List, Literal, Optional, overload
|
|
1
|
+
from typing import Optional
|
|
4
2
|
|
|
5
|
-
import aiohttp
|
|
6
3
|
import loguru
|
|
7
4
|
|
|
8
5
|
from ..constants import (
|
|
@@ -11,20 +8,13 @@ from ..constants import (
|
|
|
11
8
|
DEFAULT_OPENAI_GATEWAY_URL,
|
|
12
9
|
DEFAULT_TIMEOUT,
|
|
13
10
|
)
|
|
14
|
-
from
|
|
15
|
-
from ..types._api_version import ApiVersion
|
|
16
|
-
from ..types._request_data import RequestData
|
|
17
|
-
from ..types.api import (
|
|
18
|
-
CreateConversationResponse,
|
|
19
|
-
GetConversationResponse,
|
|
20
|
-
GetPipelineConfigResponse,
|
|
21
|
-
PipelineExecutionAsyncStreamedResponse,
|
|
22
|
-
PipelineExecutionDebugResponse,
|
|
23
|
-
PipelineExecutionResponse,
|
|
24
|
-
ProjectItem,
|
|
25
|
-
)
|
|
26
|
-
from ..utils.sse_parser import async_parse_sse_stream_chunked
|
|
11
|
+
from ._request_handler import AsyncRequestHandler
|
|
27
12
|
from .base_client import AiriaBaseClient
|
|
13
|
+
from .conversations import AsyncConversations
|
|
14
|
+
from .pipeline_execution import AsyncPipelineExecution
|
|
15
|
+
from .pipelines_config import AsyncPipelinesConfig
|
|
16
|
+
from .project import AsyncProject
|
|
17
|
+
from .store import AsyncStore
|
|
28
18
|
|
|
29
19
|
|
|
30
20
|
class AiriaAsyncClient(AiriaBaseClient):
|
|
@@ -59,32 +49,19 @@ class AiriaAsyncClient(AiriaBaseClient):
|
|
|
59
49
|
custom_logger=custom_logger,
|
|
60
50
|
)
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
loop = asyncio.get_event_loop()
|
|
76
|
-
if loop.is_closed():
|
|
77
|
-
raise RuntimeError("Event loop is closed")
|
|
78
|
-
except RuntimeError:
|
|
79
|
-
loop = asyncio.new_event_loop()
|
|
80
|
-
asyncio.set_event_loop(loop)
|
|
81
|
-
|
|
82
|
-
# Close the session
|
|
83
|
-
if not loop.is_running():
|
|
84
|
-
loop.run_until_complete(session.close())
|
|
85
|
-
else:
|
|
86
|
-
# If loop is running, schedule the close operation
|
|
87
|
-
asyncio.create_task(session.close())
|
|
52
|
+
self._request_handler = AsyncRequestHandler(
|
|
53
|
+
logger=self.logger,
|
|
54
|
+
timeout=self.timeout,
|
|
55
|
+
base_url=self.base_url,
|
|
56
|
+
api_key=self.api_key,
|
|
57
|
+
bearer_token=self.bearer_token,
|
|
58
|
+
log_requests=self.log_requests,
|
|
59
|
+
)
|
|
60
|
+
self.pipeline_execution = AsyncPipelineExecution(self._request_handler)
|
|
61
|
+
self.pipelines_config = AsyncPipelinesConfig(self._request_handler)
|
|
62
|
+
self.project = AsyncProject(self._request_handler)
|
|
63
|
+
self.conversations = AsyncConversations(self._request_handler)
|
|
64
|
+
self.store = AsyncStore(self._request_handler)
|
|
88
65
|
|
|
89
66
|
@classmethod
|
|
90
67
|
def with_openai_gateway(
|
|
@@ -193,641 +170,11 @@ class AiriaAsyncClient(AiriaBaseClient):
|
|
|
193
170
|
custom_logger=custom_logger,
|
|
194
171
|
)
|
|
195
172
|
|
|
196
|
-
def
|
|
197
|
-
self, e: aiohttp.ClientResponseError, url: str, correlation_id: str
|
|
198
|
-
):
|
|
199
|
-
# Log the error response if enabled
|
|
200
|
-
if self.log_requests:
|
|
201
|
-
self.logger.error(
|
|
202
|
-
f"API Error: {e.status} {e.message}\n"
|
|
203
|
-
f"URL: {url}\n"
|
|
204
|
-
f"Correlation ID: {correlation_id}"
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
# Extract error details from response
|
|
208
|
-
error_message = e.message
|
|
209
|
-
|
|
210
|
-
# Make sure sensitive auth information is not included in error messages
|
|
211
|
-
sanitized_message = error_message
|
|
212
|
-
if self.api_key and self.api_key in sanitized_message:
|
|
213
|
-
sanitized_message = sanitized_message.replace(self.api_key, "[REDACTED]")
|
|
214
|
-
if self.bearer_token and self.bearer_token in sanitized_message:
|
|
215
|
-
sanitized_message = sanitized_message.replace(
|
|
216
|
-
self.bearer_token, "[REDACTED]"
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
# Raise custom exception with status code and sanitized message
|
|
220
|
-
raise AiriaAPIError(status_code=e.status, message=sanitized_message) from e
|
|
221
|
-
|
|
222
|
-
async def _make_request(
|
|
223
|
-
self, method: str, request_data: RequestData, return_json: bool = True
|
|
224
|
-
) -> Optional[Dict[str, Any]]:
|
|
173
|
+
async def close(self):
|
|
225
174
|
"""
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
Args:
|
|
229
|
-
method (str): The HTTP method (e.g., 'GET', 'POST')
|
|
230
|
-
request_data: A dictionary containing the following request information:
|
|
231
|
-
- url: The endpoint URL for the request
|
|
232
|
-
- headers: HTTP headers to include in the request
|
|
233
|
-
- payload: The JSON payload/body for the request
|
|
234
|
-
- correlation_id: Unique identifier for request tracing
|
|
235
|
-
return_json (bool): Whether to return the response as JSON. Default is True.
|
|
236
|
-
|
|
237
|
-
Returns:
|
|
238
|
-
resp ([Dict[str, Any]): The JSON response from the API as a dictionary.
|
|
239
|
-
|
|
240
|
-
Raises:
|
|
241
|
-
AiriaAPIError: If the API returns an error response, with details about the error
|
|
242
|
-
aiohttp.ClientResponseError: For HTTP-related errors
|
|
175
|
+
Closes the aiohttp session to free up system resources.
|
|
243
176
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
It handles logging, error handling, and API key redaction in error messages.
|
|
177
|
+
This method should be called when the RequestHandler is no longer needed to ensure
|
|
178
|
+
proper cleanup of the underlying session and its resources.
|
|
247
179
|
"""
|
|
248
|
-
|
|
249
|
-
# Make the request
|
|
250
|
-
async with self.session.request(
|
|
251
|
-
method=method,
|
|
252
|
-
url=request_data.url,
|
|
253
|
-
json=request_data.payload,
|
|
254
|
-
params=request_data.params,
|
|
255
|
-
headers=request_data.headers,
|
|
256
|
-
timeout=self.timeout,
|
|
257
|
-
) as response:
|
|
258
|
-
# Log the response if enabled
|
|
259
|
-
if self.log_requests:
|
|
260
|
-
self.logger.info(
|
|
261
|
-
f"API Response: {response.status} {response.reason}\n"
|
|
262
|
-
f"URL: {request_data.url}\n"
|
|
263
|
-
f"Correlation ID: {request_data.correlation_id}"
|
|
264
|
-
)
|
|
265
|
-
|
|
266
|
-
# Check for HTTP errors
|
|
267
|
-
response.raise_for_status()
|
|
268
|
-
|
|
269
|
-
# Return the response as a dictionary
|
|
270
|
-
if return_json:
|
|
271
|
-
return await response.json()
|
|
272
|
-
|
|
273
|
-
except aiohttp.ClientResponseError as e:
|
|
274
|
-
self._handle_exception(e, request_data.url, request_data.correlation_id)
|
|
275
|
-
|
|
276
|
-
async def _make_request_stream(
|
|
277
|
-
self, method: str, request_data: RequestData
|
|
278
|
-
) -> AsyncIterator[str]:
|
|
279
|
-
"""
|
|
280
|
-
Makes an asynchronous HTTP request to the Airia API.
|
|
281
|
-
|
|
282
|
-
Args:
|
|
283
|
-
method (str): The HTTP method (e.g., 'GET', 'POST')
|
|
284
|
-
request_data: A dictionary containing the following request information:
|
|
285
|
-
- url: The endpoint URL for the request
|
|
286
|
-
- headers: HTTP headers to include in the request
|
|
287
|
-
- payload: The JSON payload/body for the request
|
|
288
|
-
- correlation_id: Unique identifier for request tracing
|
|
289
|
-
|
|
290
|
-
Yields:
|
|
291
|
-
resp AsyncIterator[str]]: yields chunks of the response as they are received.
|
|
292
|
-
|
|
293
|
-
Raises:
|
|
294
|
-
AiriaAPIError: If the API returns an error response, with details about the error
|
|
295
|
-
aiohttp.ClientResponseError: For HTTP-related errors
|
|
296
|
-
|
|
297
|
-
Note:
|
|
298
|
-
This is an internal method used by other client methods to make API requests.
|
|
299
|
-
It handles logging, error handling, and API key redaction in error messages.
|
|
300
|
-
"""
|
|
301
|
-
try:
|
|
302
|
-
# Make the request
|
|
303
|
-
async with self.session.request(
|
|
304
|
-
method=method,
|
|
305
|
-
url=request_data.url,
|
|
306
|
-
json=request_data.payload,
|
|
307
|
-
params=request_data.params,
|
|
308
|
-
headers=request_data.headers,
|
|
309
|
-
timeout=self.timeout,
|
|
310
|
-
chunked=True,
|
|
311
|
-
) as response:
|
|
312
|
-
# Log the response if enabled
|
|
313
|
-
if self.log_requests:
|
|
314
|
-
self.logger.info(
|
|
315
|
-
f"API Response: {response.status} {response.reason}\n"
|
|
316
|
-
f"URL: {request_data.url}\n"
|
|
317
|
-
f"Correlation ID: {request_data.correlation_id}"
|
|
318
|
-
)
|
|
319
|
-
|
|
320
|
-
# Check for HTTP errors
|
|
321
|
-
response.raise_for_status()
|
|
322
|
-
|
|
323
|
-
# Yields the response content as a stream if streaming
|
|
324
|
-
async for message in async_parse_sse_stream_chunked(
|
|
325
|
-
response.content.iter_any()
|
|
326
|
-
):
|
|
327
|
-
yield message
|
|
328
|
-
|
|
329
|
-
except aiohttp.ClientResponseError as e:
|
|
330
|
-
self._handle_exception(e, request_data.url, request_data.correlation_id)
|
|
331
|
-
|
|
332
|
-
@overload
|
|
333
|
-
async def execute_pipeline(
|
|
334
|
-
self,
|
|
335
|
-
pipeline_id: str,
|
|
336
|
-
user_input: str,
|
|
337
|
-
debug: Literal[False] = False,
|
|
338
|
-
user_id: Optional[str] = None,
|
|
339
|
-
conversation_id: Optional[str] = None,
|
|
340
|
-
async_output: Literal[False] = False,
|
|
341
|
-
include_tools_response: bool = False,
|
|
342
|
-
images: Optional[List[str]] = None,
|
|
343
|
-
files: Optional[List[str]] = None,
|
|
344
|
-
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
345
|
-
data_source_files: Optional[Dict[str, Any]] = None,
|
|
346
|
-
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
347
|
-
current_date_time: Optional[str] = None,
|
|
348
|
-
save_history: bool = True,
|
|
349
|
-
additional_info: Optional[List[Any]] = None,
|
|
350
|
-
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
351
|
-
correlation_id: Optional[str] = None,
|
|
352
|
-
) -> PipelineExecutionResponse: ...
|
|
353
|
-
|
|
354
|
-
@overload
|
|
355
|
-
async def execute_pipeline(
|
|
356
|
-
self,
|
|
357
|
-
pipeline_id: str,
|
|
358
|
-
user_input: str,
|
|
359
|
-
debug: Literal[True] = True,
|
|
360
|
-
user_id: Optional[str] = None,
|
|
361
|
-
conversation_id: Optional[str] = None,
|
|
362
|
-
async_output: Literal[False] = False,
|
|
363
|
-
include_tools_response: bool = False,
|
|
364
|
-
images: Optional[List[str]] = None,
|
|
365
|
-
files: Optional[List[str]] = None,
|
|
366
|
-
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
367
|
-
data_source_files: Optional[Dict[str, Any]] = None,
|
|
368
|
-
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
369
|
-
current_date_time: Optional[str] = None,
|
|
370
|
-
save_history: bool = True,
|
|
371
|
-
additional_info: Optional[List[Any]] = None,
|
|
372
|
-
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
373
|
-
correlation_id: Optional[str] = None,
|
|
374
|
-
) -> PipelineExecutionDebugResponse: ...
|
|
375
|
-
|
|
376
|
-
@overload
|
|
377
|
-
async def execute_pipeline(
|
|
378
|
-
self,
|
|
379
|
-
pipeline_id: str,
|
|
380
|
-
user_input: str,
|
|
381
|
-
debug: bool = False,
|
|
382
|
-
user_id: Optional[str] = None,
|
|
383
|
-
conversation_id: Optional[str] = None,
|
|
384
|
-
async_output: Literal[True] = True,
|
|
385
|
-
include_tools_response: bool = False,
|
|
386
|
-
images: Optional[List[str]] = None,
|
|
387
|
-
files: Optional[List[str]] = None,
|
|
388
|
-
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
389
|
-
data_source_files: Optional[Dict[str, Any]] = None,
|
|
390
|
-
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
391
|
-
current_date_time: Optional[str] = None,
|
|
392
|
-
save_history: bool = True,
|
|
393
|
-
additional_info: Optional[List[Any]] = None,
|
|
394
|
-
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
395
|
-
correlation_id: Optional[str] = None,
|
|
396
|
-
) -> PipelineExecutionAsyncStreamedResponse: ...
|
|
397
|
-
|
|
398
|
-
async def execute_pipeline(
|
|
399
|
-
self,
|
|
400
|
-
pipeline_id: str,
|
|
401
|
-
user_input: str,
|
|
402
|
-
debug: bool = False,
|
|
403
|
-
user_id: Optional[str] = None,
|
|
404
|
-
conversation_id: Optional[str] = None,
|
|
405
|
-
async_output: bool = False,
|
|
406
|
-
include_tools_response: bool = False,
|
|
407
|
-
images: Optional[List[str]] = None,
|
|
408
|
-
files: Optional[List[str]] = None,
|
|
409
|
-
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
410
|
-
data_source_files: Optional[Dict[str, Any]] = None,
|
|
411
|
-
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
412
|
-
current_date_time: Optional[str] = None,
|
|
413
|
-
save_history: bool = True,
|
|
414
|
-
additional_info: Optional[List[Any]] = None,
|
|
415
|
-
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
416
|
-
correlation_id: Optional[str] = None,
|
|
417
|
-
) -> Dict[str, Any]:
|
|
418
|
-
"""
|
|
419
|
-
Execute a pipeline with the provided input asynchronously.
|
|
420
|
-
|
|
421
|
-
Args:
|
|
422
|
-
pipeline_id: The ID of the pipeline to execute.
|
|
423
|
-
user_input: input text to process.
|
|
424
|
-
debug: Whether debug mode execution is enabled. Default is False.
|
|
425
|
-
user_id: Optional ID of the user making the request (guid).
|
|
426
|
-
conversation_id: Optional conversation ID (guid).
|
|
427
|
-
async_output: Whether to stream the response. Default is False.
|
|
428
|
-
include_tools_response: Whether to return the initial LLM tool result. Default is False.
|
|
429
|
-
images: Optional list of images formatted as base64 strings.
|
|
430
|
-
files: Optional list of files formatted as base64 strings.
|
|
431
|
-
data_source_folders: Optional data source folders information.
|
|
432
|
-
data_source_files: Optional data source files information.
|
|
433
|
-
in_memory_messages: Optional list of in-memory messages, each with a role and message.
|
|
434
|
-
current_date_time: Optional current date and time in ISO format.
|
|
435
|
-
save_history: Whether to save the userInput and output to conversation history. Default is True.
|
|
436
|
-
additional_info: Optional additional information.
|
|
437
|
-
prompt_variables: Optional variables to be used in the prompt.
|
|
438
|
-
correlation_id: Optional correlation ID for request tracing. If not provided,
|
|
439
|
-
one will be generated automatically.
|
|
440
|
-
|
|
441
|
-
Returns:
|
|
442
|
-
The API response as a dictionary.
|
|
443
|
-
|
|
444
|
-
Raises:
|
|
445
|
-
AiriaAPIError: If the API request fails with details about the error.
|
|
446
|
-
aiohttp.ClientError: For other request-related errors.
|
|
447
|
-
|
|
448
|
-
Example:
|
|
449
|
-
>>> client = AiriaAsyncClient(api_key="your_api_key")
|
|
450
|
-
... response = await client.execute_pipeline(
|
|
451
|
-
... pipeline_id="pipeline_123",
|
|
452
|
-
... user_input="Tell me about quantum computing"
|
|
453
|
-
... )
|
|
454
|
-
>>> print(response.result)
|
|
455
|
-
"""
|
|
456
|
-
request_data = self._pre_execute_pipeline(
|
|
457
|
-
pipeline_id=pipeline_id,
|
|
458
|
-
user_input=user_input,
|
|
459
|
-
debug=debug,
|
|
460
|
-
user_id=user_id,
|
|
461
|
-
conversation_id=conversation_id,
|
|
462
|
-
async_output=async_output,
|
|
463
|
-
include_tools_response=include_tools_response,
|
|
464
|
-
images=images,
|
|
465
|
-
files=files,
|
|
466
|
-
data_source_folders=data_source_folders,
|
|
467
|
-
data_source_files=data_source_files,
|
|
468
|
-
in_memory_messages=in_memory_messages,
|
|
469
|
-
current_date_time=current_date_time,
|
|
470
|
-
save_history=save_history,
|
|
471
|
-
additional_info=additional_info,
|
|
472
|
-
prompt_variables=prompt_variables,
|
|
473
|
-
correlation_id=correlation_id,
|
|
474
|
-
api_version=ApiVersion.V2.value,
|
|
475
|
-
)
|
|
476
|
-
resp = (
|
|
477
|
-
self._make_request_stream(method="POST", request_data=request_data)
|
|
478
|
-
if async_output
|
|
479
|
-
else await self._make_request("POST", request_data=request_data)
|
|
480
|
-
)
|
|
481
|
-
|
|
482
|
-
if not async_output:
|
|
483
|
-
if not debug:
|
|
484
|
-
return PipelineExecutionResponse(**resp)
|
|
485
|
-
return PipelineExecutionDebugResponse(**resp)
|
|
486
|
-
|
|
487
|
-
return PipelineExecutionAsyncStreamedResponse(stream=resp)
|
|
488
|
-
|
|
489
|
-
async def get_projects(
|
|
490
|
-
self, correlation_id: Optional[str] = None
|
|
491
|
-
) -> List[ProjectItem]:
|
|
492
|
-
"""
|
|
493
|
-
Retrieve a list of all projects accessible to the authenticated user.
|
|
494
|
-
|
|
495
|
-
This method fetches comprehensive information about all projects that the
|
|
496
|
-
current user has access to, including project metadata, creation details,
|
|
497
|
-
and status information.
|
|
498
|
-
|
|
499
|
-
Args:
|
|
500
|
-
correlation_id (str, optional): A unique identifier for request tracing
|
|
501
|
-
and logging. If not provided, one will be automatically generated.
|
|
502
|
-
|
|
503
|
-
Returns:
|
|
504
|
-
List[ProjectItem]: A list of ProjectItem objects containing project
|
|
505
|
-
information. Returns an empty list if no projects are accessible
|
|
506
|
-
or found.
|
|
507
|
-
|
|
508
|
-
Raises:
|
|
509
|
-
AiriaAPIError: If the API request fails, including cases where:
|
|
510
|
-
- Authentication fails (401)
|
|
511
|
-
- Access is forbidden (403)
|
|
512
|
-
- Server errors (5xx)
|
|
513
|
-
|
|
514
|
-
Example:
|
|
515
|
-
```python
|
|
516
|
-
from airia import AiriaAsyncClient
|
|
517
|
-
|
|
518
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
519
|
-
|
|
520
|
-
# Get all accessible projects
|
|
521
|
-
projects = await client.get_projects()
|
|
522
|
-
|
|
523
|
-
for project in projects:
|
|
524
|
-
print(f"Project: {project.name}")
|
|
525
|
-
print(f"ID: {project.id}")
|
|
526
|
-
print(f"Description: {project.description}")
|
|
527
|
-
print(f"Created: {project.created_at}")
|
|
528
|
-
print("---")
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
Note:
|
|
532
|
-
The returned projects are filtered based on the authenticated user's
|
|
533
|
-
permissions. Users will only see projects they have been granted
|
|
534
|
-
access to.
|
|
535
|
-
"""
|
|
536
|
-
request_data = self._pre_get_projects(
|
|
537
|
-
correlation_id=correlation_id, api_version=ApiVersion.V1.value
|
|
538
|
-
)
|
|
539
|
-
resp = await self._make_request("GET", request_data)
|
|
540
|
-
|
|
541
|
-
if "items" not in resp or len(resp["items"]) == 0:
|
|
542
|
-
return []
|
|
543
|
-
|
|
544
|
-
return [ProjectItem(**item) for item in resp["items"]]
|
|
545
|
-
|
|
546
|
-
async def get_active_pipelines_ids(
|
|
547
|
-
self, project_id: Optional[str] = None, correlation_id: Optional[str] = None
|
|
548
|
-
) -> List[str]:
|
|
549
|
-
"""
|
|
550
|
-
Retrieve a list of active pipeline IDs.
|
|
551
|
-
|
|
552
|
-
This method fetches the IDs of all active pipelines, optionally filtered by project.
|
|
553
|
-
Active pipelines are those that are currently deployed and available for execution.
|
|
554
|
-
|
|
555
|
-
Args:
|
|
556
|
-
project_id (str, optional): The unique identifier of the project to filter
|
|
557
|
-
pipelines by. If not provided, returns active pipelines from all projects
|
|
558
|
-
accessible to the authenticated user.
|
|
559
|
-
correlation_id (str, optional): A unique identifier for request tracing
|
|
560
|
-
and logging. If not provided, one will be automatically generated.
|
|
561
|
-
|
|
562
|
-
Returns:
|
|
563
|
-
List[str]: A list of pipeline IDs that are currently active. Returns an
|
|
564
|
-
empty list if no active pipelines are found.
|
|
565
|
-
|
|
566
|
-
Raises:
|
|
567
|
-
AiriaAPIError: If the API request fails, including cases where:
|
|
568
|
-
- The project_id doesn't exist (404)
|
|
569
|
-
- Authentication fails (401)
|
|
570
|
-
- Access is forbidden (403)
|
|
571
|
-
- Server errors (5xx)
|
|
572
|
-
|
|
573
|
-
Example:
|
|
574
|
-
```python
|
|
575
|
-
from airia import AiriaAsyncClient
|
|
576
|
-
|
|
577
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
578
|
-
|
|
579
|
-
# Get all active pipeline IDs
|
|
580
|
-
pipeline_ids = await client.get_active_pipelines_ids()
|
|
581
|
-
print(f"Found {len(pipeline_ids)} active pipelines")
|
|
582
|
-
|
|
583
|
-
# Get active pipeline IDs for a specific project
|
|
584
|
-
project_pipelines = await client.get_active_pipelines_ids(
|
|
585
|
-
project_id="your_project_id"
|
|
586
|
-
)
|
|
587
|
-
print(f"Project has {len(project_pipelines)} active pipelines")
|
|
588
|
-
```
|
|
589
|
-
|
|
590
|
-
Note:
|
|
591
|
-
Only pipelines with active versions are returned. Inactive or archived
|
|
592
|
-
pipelines are not included in the results.
|
|
593
|
-
"""
|
|
594
|
-
request_data = self._pre_get_active_pipelines_ids(
|
|
595
|
-
project_id=project_id,
|
|
596
|
-
correlation_id=correlation_id,
|
|
597
|
-
api_version=ApiVersion.V1.value,
|
|
598
|
-
)
|
|
599
|
-
resp = await self._make_request("GET", request_data)
|
|
600
|
-
|
|
601
|
-
if "items" not in resp or len(resp["items"]) == 0:
|
|
602
|
-
return []
|
|
603
|
-
|
|
604
|
-
pipeline_ids = [r["activeVersion"]["pipelineId"] for r in resp["items"]]
|
|
605
|
-
|
|
606
|
-
return pipeline_ids
|
|
607
|
-
|
|
608
|
-
async def get_pipeline_config(
|
|
609
|
-
self, pipeline_id: str, correlation_id: Optional[str] = None
|
|
610
|
-
) -> GetPipelineConfigResponse:
|
|
611
|
-
"""
|
|
612
|
-
Retrieve configuration details for a specific pipeline.
|
|
613
|
-
|
|
614
|
-
This method fetches comprehensive information about a pipeline including its
|
|
615
|
-
deployment details, execution statistics, version information, and metadata.
|
|
616
|
-
|
|
617
|
-
Args:
|
|
618
|
-
pipeline_id (str): The unique identifier of the pipeline to retrieve
|
|
619
|
-
configuration for.
|
|
620
|
-
correlation_id (str, optional): A unique identifier for request tracing
|
|
621
|
-
and logging. If not provided, one will be automatically generated.
|
|
622
|
-
|
|
623
|
-
Returns:
|
|
624
|
-
GetPipelineConfigResponse: A response object containing the pipeline
|
|
625
|
-
configuration.
|
|
626
|
-
|
|
627
|
-
Raises:
|
|
628
|
-
AiriaAPIError: If the API request fails, including cases where:
|
|
629
|
-
- The pipeline_id doesn't exist (404)
|
|
630
|
-
- Authentication fails (401)
|
|
631
|
-
- Access is forbidden (403)
|
|
632
|
-
- Server errors (5xx)
|
|
633
|
-
|
|
634
|
-
Example:
|
|
635
|
-
```python
|
|
636
|
-
from airia import AiriaAsyncClient
|
|
637
|
-
|
|
638
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
639
|
-
|
|
640
|
-
# Get pipeline configuration
|
|
641
|
-
config = await client.get_pipeline_config(
|
|
642
|
-
pipeline_id="your_pipeline_id"
|
|
643
|
-
)
|
|
644
|
-
|
|
645
|
-
print(f"Pipeline: {config.deployment_name}")
|
|
646
|
-
print(f"Description: {config.deployment_description}")
|
|
647
|
-
print(f"Success rate: {config.execution_stats.success_count}")
|
|
648
|
-
print(f"Active version: {config.active_version.version_number}")
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
Note:
|
|
652
|
-
This method only retrieves configuration information and does not
|
|
653
|
-
execute the pipeline. Use execute_pipeline() to run the pipeline.
|
|
654
|
-
"""
|
|
655
|
-
request_data = self._pre_get_pipeline_config(
|
|
656
|
-
pipeline_id=pipeline_id,
|
|
657
|
-
correlation_id=correlation_id,
|
|
658
|
-
api_version=ApiVersion.V1.value,
|
|
659
|
-
)
|
|
660
|
-
resp = await self._make_request("GET", request_data)
|
|
661
|
-
|
|
662
|
-
return GetPipelineConfigResponse(**resp)
|
|
663
|
-
|
|
664
|
-
async def create_conversation(
|
|
665
|
-
self,
|
|
666
|
-
user_id: str,
|
|
667
|
-
title: Optional[str] = None,
|
|
668
|
-
deployment_id: Optional[str] = None,
|
|
669
|
-
data_source_files: Dict[str, Any] = {},
|
|
670
|
-
is_bookmarked: bool = False,
|
|
671
|
-
correlation_id: Optional[str] = None,
|
|
672
|
-
) -> CreateConversationResponse:
|
|
673
|
-
"""
|
|
674
|
-
Create a new conversation.
|
|
675
|
-
|
|
676
|
-
Args:
|
|
677
|
-
user_id (str): The unique identifier of the user creating the conversation.
|
|
678
|
-
title (str, optional): The title for the conversation. If not provided,
|
|
679
|
-
the conversation will be created without a title.
|
|
680
|
-
deployment_id (str, optional): The unique identifier of the deployment
|
|
681
|
-
to associate with the conversation. If not provided, the conversation
|
|
682
|
-
will not be associated with any specific deployment.
|
|
683
|
-
data_source_files (dict): Configuration for data source files
|
|
684
|
-
to be associated with the conversation. If not provided, no data
|
|
685
|
-
source files will be associated.
|
|
686
|
-
is_bookmarked (bool): Whether the conversation should be bookmarked.
|
|
687
|
-
Defaults to False.
|
|
688
|
-
correlation_id (str, optional): A unique identifier for request tracing
|
|
689
|
-
and logging. If not provided, one will be automatically generated.
|
|
690
|
-
|
|
691
|
-
Returns:
|
|
692
|
-
CreateConversationResponse: A response object containing the created
|
|
693
|
-
conversation details including its ID, creation timestamp, and
|
|
694
|
-
all provided parameters.
|
|
695
|
-
|
|
696
|
-
Raises:
|
|
697
|
-
AiriaAPIError: If the API request fails, including cases where:
|
|
698
|
-
- The user_id doesn't exist (404)
|
|
699
|
-
- The deployment_id is invalid (404)
|
|
700
|
-
- Authentication fails (401)
|
|
701
|
-
- Access is forbidden (403)
|
|
702
|
-
- Server errors (5xx)
|
|
703
|
-
|
|
704
|
-
Example:
|
|
705
|
-
```python
|
|
706
|
-
from airia import AiriaAsyncClient
|
|
707
|
-
|
|
708
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
709
|
-
|
|
710
|
-
# Create a basic conversation
|
|
711
|
-
conversation = await client.create_conversation(
|
|
712
|
-
user_id="user_123"
|
|
713
|
-
)
|
|
714
|
-
print(f"Created conversation: {conversation.conversation_id}")
|
|
715
|
-
|
|
716
|
-
# Create a conversation with all options
|
|
717
|
-
conversation = await client.create_conversation(
|
|
718
|
-
user_id="user_123",
|
|
719
|
-
title="My Research Session",
|
|
720
|
-
deployment_id="deployment_456",
|
|
721
|
-
data_source_files={"documents": ["doc1.pdf", "doc2.txt"]},
|
|
722
|
-
is_bookmarked=True
|
|
723
|
-
)
|
|
724
|
-
print(f"Created bookmarked conversation: {conversation.conversation_id}")
|
|
725
|
-
```
|
|
726
|
-
|
|
727
|
-
Note:
|
|
728
|
-
The user_id is required and must correspond to a valid user in the system.
|
|
729
|
-
All other parameters are optional and can be set to None or their default values.
|
|
730
|
-
"""
|
|
731
|
-
request_data = self._pre_create_conversation(
|
|
732
|
-
user_id=user_id,
|
|
733
|
-
title=title,
|
|
734
|
-
deployment_id=deployment_id,
|
|
735
|
-
data_source_files=data_source_files,
|
|
736
|
-
is_bookmarked=is_bookmarked,
|
|
737
|
-
correlation_id=correlation_id,
|
|
738
|
-
api_version=ApiVersion.V1.value,
|
|
739
|
-
)
|
|
740
|
-
resp = await self._make_request("POST", request_data)
|
|
741
|
-
|
|
742
|
-
return CreateConversationResponse(**resp)
|
|
743
|
-
|
|
744
|
-
async def get_conversation(
|
|
745
|
-
self, conversation_id: str, correlation_id: Optional[str] = None
|
|
746
|
-
) -> GetConversationResponse:
|
|
747
|
-
"""
|
|
748
|
-
Retrieve detailed information about a specific conversation by its ID.
|
|
749
|
-
|
|
750
|
-
This method fetches comprehensive information about a conversation including
|
|
751
|
-
all messages, metadata, policy redactions, and execution status.
|
|
752
|
-
|
|
753
|
-
Args:
|
|
754
|
-
conversation_id (str): The unique identifier of the conversation to retrieve.
|
|
755
|
-
correlation_id (str, optional): A unique identifier for request tracing
|
|
756
|
-
and logging. If not provided, one will be automatically generated.
|
|
757
|
-
|
|
758
|
-
Returns:
|
|
759
|
-
GetConversationResponse: A response object containing the conversation
|
|
760
|
-
details including user ID, messages, title, deployment information,
|
|
761
|
-
data source files, bookmark status, policy redactions, and execution status.
|
|
762
|
-
|
|
763
|
-
Raises:
|
|
764
|
-
AiriaAPIError: If the API request fails, including cases where:
|
|
765
|
-
- The conversation_id doesn't exist (404)
|
|
766
|
-
- Authentication fails (401)
|
|
767
|
-
- Access is forbidden (403)
|
|
768
|
-
- Server errors (5xx)
|
|
769
|
-
|
|
770
|
-
Example:
|
|
771
|
-
```python
|
|
772
|
-
from airia import AiriaAsyncClient
|
|
773
|
-
|
|
774
|
-
async def main():
|
|
775
|
-
client = AiriaAsyncClient(api_key="your_api_key")
|
|
776
|
-
|
|
777
|
-
# Get conversation details
|
|
778
|
-
conversation = await client.get_conversation(
|
|
779
|
-
conversation_id="conversation_123"
|
|
780
|
-
)
|
|
781
|
-
|
|
782
|
-
print(f"Conversation: {conversation.title}")
|
|
783
|
-
print(f"User: {conversation.user_id}")
|
|
784
|
-
print(f"Messages: {len(conversation.messages)}")
|
|
785
|
-
print(f"Bookmarked: {conversation.is_bookmarked}")
|
|
786
|
-
|
|
787
|
-
# Access individual messages
|
|
788
|
-
for message in conversation.messages:
|
|
789
|
-
print(f"[{message.role}]: {message.message}")
|
|
790
|
-
|
|
791
|
-
asyncio.run(main())
|
|
792
|
-
```
|
|
793
|
-
|
|
794
|
-
Note:
|
|
795
|
-
This method only retrieves conversation information and does not
|
|
796
|
-
modify or execute any operations on the conversation.
|
|
797
|
-
"""
|
|
798
|
-
request_data = self._pre_get_conversation(
|
|
799
|
-
conversation_id=conversation_id,
|
|
800
|
-
correlation_id=correlation_id,
|
|
801
|
-
api_version=ApiVersion.V1.value,
|
|
802
|
-
)
|
|
803
|
-
resp = await self._make_request("GET", request_data)
|
|
804
|
-
|
|
805
|
-
return GetConversationResponse(**resp)
|
|
806
|
-
|
|
807
|
-
async def delete_conversation(
|
|
808
|
-
self,
|
|
809
|
-
conversation_id: str,
|
|
810
|
-
correlation_id: Optional[str] = None,
|
|
811
|
-
) -> None:
|
|
812
|
-
"""
|
|
813
|
-
Delete a conversation by its ID.
|
|
814
|
-
|
|
815
|
-
This method permanently removes a conversation and all associated data
|
|
816
|
-
from the Airia platform. This action cannot be undone.
|
|
817
|
-
|
|
818
|
-
Args:
|
|
819
|
-
conversation_id: The unique identifier of the conversation to delete
|
|
820
|
-
correlation_id: Optional correlation ID for request tracing
|
|
821
|
-
|
|
822
|
-
Returns:
|
|
823
|
-
None: This method returns nothing upon successful deletion
|
|
824
|
-
|
|
825
|
-
Raises:
|
|
826
|
-
AiriaAPIError: If the API request fails or the conversation doesn't exist
|
|
827
|
-
"""
|
|
828
|
-
request_data = self._pre_delete_conversation(
|
|
829
|
-
conversation_id=conversation_id,
|
|
830
|
-
correlation_id=correlation_id,
|
|
831
|
-
api_version=ApiVersion.V1.value,
|
|
832
|
-
)
|
|
833
|
-
await self._make_request("DELETE", request_data, return_json=False)
|
|
180
|
+
await self._request_handler.close()
|