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