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