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.
Files changed (58) hide show
  1. airia/client/_request_handler/__init__.py +4 -0
  2. airia/client/_request_handler/async_request_handler.py +272 -0
  3. airia/client/_request_handler/base_request_handler.py +108 -0
  4. airia/client/_request_handler/sync_request_handler.py +255 -0
  5. airia/client/async_client.py +25 -584
  6. airia/client/base_client.py +2 -209
  7. airia/client/conversations/__init__.py +4 -0
  8. airia/client/conversations/async_conversations.py +187 -0
  9. airia/client/conversations/base_conversations.py +135 -0
  10. airia/client/conversations/sync_conversations.py +182 -0
  11. airia/client/pipeline_execution/__init__.py +4 -0
  12. airia/client/pipeline_execution/async_pipeline_execution.py +178 -0
  13. airia/client/pipeline_execution/base_pipeline_execution.py +96 -0
  14. airia/client/pipeline_execution/sync_pipeline_execution.py +178 -0
  15. airia/client/pipelines_config/__init__.py +4 -0
  16. airia/client/pipelines_config/async_pipelines_config.py +127 -0
  17. airia/client/pipelines_config/base_pipelines_config.py +76 -0
  18. airia/client/pipelines_config/sync_pipelines_config.py +127 -0
  19. airia/client/project/__init__.py +4 -0
  20. airia/client/project/async_project.py +122 -0
  21. airia/client/project/base_project.py +74 -0
  22. airia/client/project/sync_project.py +120 -0
  23. airia/client/store/__init__.py +4 -0
  24. airia/client/store/async_store.py +377 -0
  25. airia/client/store/base_store.py +243 -0
  26. airia/client/store/sync_store.py +352 -0
  27. airia/client/sync_client.py +25 -563
  28. airia/constants.py +13 -2
  29. airia/exceptions.py +8 -8
  30. airia/logs.py +10 -32
  31. airia/types/__init__.py +0 -0
  32. airia/types/_request_data.py +29 -2
  33. airia/types/api/__init__.py +0 -19
  34. airia/types/api/conversations/__init__.py +3 -0
  35. airia/types/api/conversations/_conversations.py +115 -0
  36. airia/types/api/pipeline_execution/__init__.py +13 -0
  37. airia/types/api/pipeline_execution/_pipeline_execution.py +76 -0
  38. airia/types/api/pipelines_config/__init__.py +3 -0
  39. airia/types/api/pipelines_config/get_pipeline_config.py +401 -0
  40. airia/types/api/project/__init__.py +3 -0
  41. airia/types/api/project/get_projects.py +91 -0
  42. airia/types/api/store/__init__.py +4 -0
  43. airia/types/api/store/get_file.py +145 -0
  44. airia/types/api/store/get_files.py +21 -0
  45. airia/types/sse/__init__.py +8 -0
  46. airia/types/sse/sse_messages.py +209 -0
  47. airia/utils/sse_parser.py +40 -7
  48. airia-0.1.14.dist-info/METADATA +221 -0
  49. airia-0.1.14.dist-info/RECORD +55 -0
  50. airia/types/api/conversations.py +0 -14
  51. airia/types/api/get_pipeline_config.py +0 -183
  52. airia/types/api/get_projects.py +0 -35
  53. airia/types/api/pipeline_execution.py +0 -29
  54. airia-0.1.12.dist-info/METADATA +0 -705
  55. airia-0.1.12.dist-info/RECORD +0 -23
  56. {airia-0.1.12.dist-info → airia-0.1.14.dist-info}/WHEEL +0 -0
  57. {airia-0.1.12.dist-info → airia-0.1.14.dist-info}/licenses/LICENSE +0 -0
  58. {airia-0.1.12.dist-info → airia-0.1.14.dist-info}/top_level.txt +0 -0
@@ -1,14 +1,10 @@
1
- import json
2
1
  import os
3
- from typing import Any, Dict, List, Optional
4
- from urllib.parse import urljoin
2
+ from typing import Optional
5
3
 
6
4
  import loguru
7
5
 
8
6
  from ..constants import DEFAULT_BASE_URL, DEFAULT_TIMEOUT
9
- from ..logs import configure_logging, set_correlation_id
10
- from ..types._api_version import ApiVersion
11
- from ..types._request_data import RequestData
7
+ from ..logs import configure_logging
12
8
 
13
9
 
14
10
  class AiriaBaseClient:
@@ -89,206 +85,3 @@ class AiriaBaseClient:
89
85
  raise ValueError(
90
86
  "Authentication required. Provide either api_key (or set AIRIA_API_KEY environment variable) or bearer_token."
91
87
  )
92
-
93
- def _prepare_request(
94
- self,
95
- url: str,
96
- payload: Optional[Dict[str, Any]] = None,
97
- params: Optional[Dict[str, Any]] = None,
98
- correlation_id: Optional[str] = None,
99
- ):
100
- # Set correlation ID if provided or generate a new one
101
- correlation_id = set_correlation_id(correlation_id)
102
-
103
- # Set up base headers
104
- headers = {
105
- "X-Correlation-ID": correlation_id,
106
- "Content-Type": "application/json",
107
- }
108
-
109
- # Add authentication header based on the method used
110
- if self.api_key:
111
- headers["X-API-KEY"] = self.api_key
112
- elif self.bearer_token:
113
- headers["Authorization"] = f"Bearer {self.bearer_token}"
114
-
115
- # Log the request if enabled
116
- if self.log_requests:
117
- # Create a sanitized copy of headers and params for logging
118
- log_headers = headers.copy()
119
- log_params = params.copy() if params is not None else {}
120
-
121
- # Filter out sensitive headers
122
- if "X-API-KEY" in log_headers:
123
- log_headers["X-API-KEY"] = "[REDACTED]"
124
- if "Authorization" in log_headers:
125
- log_headers["Authorization"] = "[REDACTED]"
126
-
127
- # Process payload for logging
128
- log_payload = payload.copy() if payload is not None else {}
129
- if "images" in log_payload and log_payload["images"] is not None:
130
- log_payload["images"] = f"{len(log_payload['images'])} images"
131
- if "files" in log_payload and log_payload["files"] is not None:
132
- log_payload["files"] = f"{len(log_payload['files'])} files"
133
- log_payload = json.dumps(log_payload)
134
-
135
- self.logger.info(
136
- f"API Request: POST {url}\n"
137
- f"Headers: {json.dumps(log_headers)}\n"
138
- f"Payload: {log_payload}"
139
- f"Params: {json.dumps(log_params)}\n"
140
- )
141
-
142
- return RequestData(
143
- **{
144
- "url": url,
145
- "payload": payload,
146
- "headers": headers,
147
- "params": params,
148
- "correlation_id": correlation_id,
149
- }
150
- )
151
-
152
- def _pre_execute_pipeline(
153
- self,
154
- pipeline_id: str,
155
- user_input: str,
156
- debug: bool = False,
157
- user_id: Optional[str] = None,
158
- conversation_id: Optional[str] = None,
159
- async_output: bool = False,
160
- include_tools_response: bool = False,
161
- images: Optional[List[str]] = None,
162
- files: Optional[List[str]] = None,
163
- data_source_folders: Optional[Dict[str, Any]] = None,
164
- data_source_files: Optional[Dict[str, Any]] = None,
165
- in_memory_messages: Optional[List[Dict[str, str]]] = None,
166
- current_date_time: Optional[str] = None,
167
- save_history: bool = True,
168
- additional_info: Optional[List[Any]] = None,
169
- prompt_variables: Optional[Dict[str, Any]] = None,
170
- correlation_id: Optional[str] = None,
171
- api_version: str = ApiVersion.V2.value,
172
- ):
173
- if api_version not in ApiVersion.as_list():
174
- raise ValueError(
175
- f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
176
- )
177
- url = urljoin(self.base_url, f"{api_version}/PipelineExecution/{pipeline_id}")
178
-
179
- payload = {
180
- "userInput": user_input,
181
- "debug": debug,
182
- "userId": user_id,
183
- "conversationId": conversation_id,
184
- "asyncOutput": async_output,
185
- "includeToolsResponse": include_tools_response,
186
- "images": images,
187
- "files": files,
188
- "dataSourceFolders": data_source_folders,
189
- "dataSourceFiles": data_source_files,
190
- "inMemoryMessages": in_memory_messages,
191
- "currentDateTime": current_date_time,
192
- "saveHistory": save_history,
193
- "additionalInfo": additional_info,
194
- "promptVariables": prompt_variables,
195
- }
196
-
197
- request_data = self._prepare_request(
198
- url=url, payload=payload, correlation_id=correlation_id
199
- )
200
-
201
- return request_data
202
-
203
- def _pre_get_projects(
204
- self,
205
- correlation_id: Optional[str] = None,
206
- api_version: str = ApiVersion.V1.value,
207
- ):
208
- if api_version not in ApiVersion.as_list():
209
- raise ValueError(
210
- f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
211
- )
212
- url = urljoin(self.base_url, f"{api_version}/Project/paginated")
213
- request_data = self._prepare_request(url, correlation_id=correlation_id)
214
-
215
- return request_data
216
-
217
- def _pre_get_active_pipelines_ids(
218
- self,
219
- project_id: Optional[str] = None,
220
- correlation_id: Optional[str] = None,
221
- api_version: str = ApiVersion.V1.value,
222
- ):
223
- if api_version not in ApiVersion.as_list():
224
- raise ValueError(
225
- f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
226
- )
227
- url = urljoin(self.base_url, f"{api_version}/PipelinesConfig")
228
- params = {"projectId": project_id} if project_id is not None else None
229
- request_data = self._prepare_request(
230
- url, params=params, correlation_id=correlation_id
231
- )
232
-
233
- return request_data
234
-
235
- def _pre_get_pipeline_config(
236
- self,
237
- pipeline_id: str,
238
- correlation_id: Optional[str] = None,
239
- api_version: str = ApiVersion.V1.value,
240
- ):
241
- if api_version not in ApiVersion.as_list():
242
- raise ValueError(
243
- f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
244
- )
245
- url = urljoin(
246
- self.base_url, f"{api_version}/PipelinesConfig/export/{pipeline_id}"
247
- )
248
- request_data = self._prepare_request(url, correlation_id=correlation_id)
249
-
250
- return request_data
251
-
252
- def _pre_create_conversation(
253
- self,
254
- user_id: str,
255
- title: Optional[str] = None,
256
- deployment_id: Optional[str] = None,
257
- data_source_files: Dict[str, Any] = {},
258
- is_bookmarked: bool = False,
259
- correlation_id: Optional[str] = None,
260
- api_version: str = ApiVersion.V1.value,
261
- ):
262
- if api_version not in ApiVersion.as_list():
263
- raise ValueError(
264
- f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
265
- )
266
- url = urljoin(self.base_url, f"{api_version}/Conversations")
267
-
268
- payload = {
269
- "userId": user_id,
270
- "title": title,
271
- "deploymentId": deployment_id,
272
- "dataSourceFiles": data_source_files,
273
- "isBookmarked": is_bookmarked,
274
- }
275
-
276
- request_data = self._prepare_request(
277
- url=url, payload=payload, correlation_id=correlation_id
278
- )
279
-
280
- return request_data
281
-
282
- def _pre_get_projects(
283
- self,
284
- correlation_id: Optional[str] = None,
285
- api_version: str = ApiVersion.V1.value,
286
- ):
287
- if api_version not in ApiVersion.as_list():
288
- raise ValueError(
289
- f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
290
- )
291
- url = urljoin(self.base_url, f"{api_version}/Project/paginated")
292
- request_data = self._prepare_request(url, correlation_id=correlation_id)
293
-
294
- return request_data
@@ -0,0 +1,4 @@
1
+ from .async_conversations import AsyncConversations
2
+ from .sync_conversations import Conversations
3
+
4
+ __all__ = ["Conversations", "AsyncConversations"]
@@ -0,0 +1,187 @@
1
+ from typing import Any, Dict, Optional
2
+
3
+ from ...types._api_version import ApiVersion
4
+ from ...types.api.conversations import (
5
+ CreateConversationResponse,
6
+ GetConversationResponse,
7
+ )
8
+ from .._request_handler import AsyncRequestHandler
9
+ from .base_conversations import BaseConversations
10
+
11
+
12
+ class AsyncConversations(BaseConversations):
13
+ def __init__(self, request_handler: AsyncRequestHandler):
14
+ super().__init__(request_handler)
15
+
16
+ async def create_conversation(
17
+ self,
18
+ user_id: str,
19
+ title: Optional[str] = None,
20
+ deployment_id: Optional[str] = None,
21
+ data_source_files: Dict[str, Any] = {},
22
+ is_bookmarked: bool = False,
23
+ correlation_id: Optional[str] = None,
24
+ ) -> CreateConversationResponse:
25
+ """
26
+ Create a new conversation.
27
+
28
+ Args:
29
+ user_id (str): The unique identifier of the user creating the conversation.
30
+ title (str, optional): The title for the conversation. If not provided,
31
+ the conversation will be created without a title.
32
+ deployment_id (str, optional): The unique identifier of the deployment
33
+ to associate with the conversation. If not provided, the conversation
34
+ will not be associated with any specific deployment.
35
+ data_source_files (dict): Configuration for data source files
36
+ to be associated with the conversation. If not provided, no data
37
+ source files will be associated.
38
+ is_bookmarked (bool): Whether the conversation should be bookmarked.
39
+ Defaults to False.
40
+ correlation_id (str, optional): A unique identifier for request tracing
41
+ and logging. If not provided, one will be automatically generated.
42
+
43
+ Returns:
44
+ CreateConversationResponse: A response object containing the created
45
+ conversation details including its ID, creation timestamp, and
46
+ all provided parameters.
47
+
48
+ Raises:
49
+ AiriaAPIError: If the API request fails, including cases where:
50
+ - The user_id doesn't exist (404)
51
+ - The deployment_id is invalid (404)
52
+ - Authentication fails (401)
53
+ - Access is forbidden (403)
54
+ - Server errors (5xx)
55
+
56
+ Example:
57
+ ```python
58
+ from airia import AiriaAsyncClient
59
+
60
+ client = AiriaAsyncClient(api_key="your_api_key")
61
+
62
+ # Create a basic conversation
63
+ conversation = await client.conversations.create_conversation(
64
+ user_id="user_123"
65
+ )
66
+ print(f"Created conversation: {conversation.conversation_id}")
67
+
68
+ # Create a conversation with all options
69
+ conversation = await client.conversations.create_conversation(
70
+ user_id="user_123",
71
+ title="My Research Session",
72
+ deployment_id="deployment_456",
73
+ data_source_files={"documents": ["doc1.pdf", "doc2.txt"]},
74
+ is_bookmarked=True
75
+ )
76
+ print(f"Created bookmarked conversation: {conversation.conversation_id}")
77
+ ```
78
+
79
+ Note:
80
+ The user_id is required and must correspond to a valid user in the system.
81
+ All other parameters are optional and can be set to None or their default values.
82
+ """
83
+ request_data = self._pre_create_conversation(
84
+ user_id=user_id,
85
+ title=title,
86
+ deployment_id=deployment_id,
87
+ data_source_files=data_source_files,
88
+ is_bookmarked=is_bookmarked,
89
+ correlation_id=correlation_id,
90
+ api_version=ApiVersion.V1.value,
91
+ )
92
+ resp = await self._request_handler.make_request("POST", request_data)
93
+
94
+ return CreateConversationResponse(**resp)
95
+
96
+ async def get_conversation(
97
+ self, conversation_id: str, correlation_id: Optional[str] = None
98
+ ) -> GetConversationResponse:
99
+ """
100
+ Retrieve detailed information about a specific conversation by its ID.
101
+
102
+ This method fetches comprehensive information about a conversation including
103
+ all messages, metadata, policy redactions, and execution status.
104
+
105
+ Args:
106
+ conversation_id (str): The unique identifier of the conversation to retrieve.
107
+ correlation_id (str, optional): A unique identifier for request tracing
108
+ and logging. If not provided, one will be automatically generated.
109
+
110
+ Returns:
111
+ GetConversationResponse: A response object containing the conversation
112
+ details including user ID, messages, title, deployment information,
113
+ data source files, bookmark status, policy redactions, and execution status.
114
+
115
+ Raises:
116
+ AiriaAPIError: If the API request fails, including cases where:
117
+ - The conversation_id doesn't exist (404)
118
+ - Authentication fails (401)
119
+ - Access is forbidden (403)
120
+ - Server errors (5xx)
121
+
122
+ Example:
123
+ ```python
124
+ from airia import AiriaAsyncClient
125
+
126
+ async def main():
127
+ client = AiriaAsyncClient(api_key="your_api_key")
128
+
129
+ # Get conversation details
130
+ conversation = await client.conversations.get_conversation(
131
+ conversation_id="conversation_123"
132
+ )
133
+
134
+ print(f"Conversation: {conversation.title}")
135
+ print(f"User: {conversation.user_id}")
136
+ print(f"Messages: {len(conversation.messages)}")
137
+ print(f"Bookmarked: {conversation.is_bookmarked}")
138
+
139
+ # Access individual messages
140
+ for message in conversation.messages:
141
+ print(f"[{message.role}]: {message.message}")
142
+
143
+ asyncio.run(main())
144
+ ```
145
+
146
+ Note:
147
+ This method only retrieves conversation information and does not
148
+ modify or execute any operations on the conversation.
149
+ """
150
+ request_data = self._pre_get_conversation(
151
+ conversation_id=conversation_id,
152
+ correlation_id=correlation_id,
153
+ api_version=ApiVersion.V1.value,
154
+ )
155
+ resp = await self._request_handler.make_request("GET", request_data)
156
+
157
+ return GetConversationResponse(**resp)
158
+
159
+ async def delete_conversation(
160
+ self,
161
+ conversation_id: str,
162
+ correlation_id: Optional[str] = None,
163
+ ) -> None:
164
+ """
165
+ Delete a conversation by its ID.
166
+
167
+ This method permanently removes a conversation and all associated data
168
+ from the Airia platform. This action cannot be undone.
169
+
170
+ Args:
171
+ conversation_id: The unique identifier of the conversation to delete
172
+ correlation_id: Optional correlation ID for request tracing
173
+
174
+ Returns:
175
+ None: This method returns nothing upon successful deletion
176
+
177
+ Raises:
178
+ AiriaAPIError: If the API request fails or the conversation doesn't exist
179
+ """
180
+ request_data = self._pre_delete_conversation(
181
+ conversation_id=conversation_id,
182
+ correlation_id=correlation_id,
183
+ api_version=ApiVersion.V1.value,
184
+ )
185
+ await self._request_handler.make_request(
186
+ "DELETE", request_data, return_json=False
187
+ )
@@ -0,0 +1,135 @@
1
+ from typing import Any, Dict, Optional, Union
2
+ from urllib.parse import urljoin
3
+
4
+ from ...types._api_version import ApiVersion
5
+ from .._request_handler import AsyncRequestHandler, RequestHandler
6
+
7
+
8
+ class BaseConversations:
9
+ def __init__(self, request_handler: Union[RequestHandler, AsyncRequestHandler]):
10
+ self._request_handler = request_handler
11
+
12
+ def _pre_create_conversation(
13
+ self,
14
+ user_id: str,
15
+ title: Optional[str] = None,
16
+ deployment_id: Optional[str] = None,
17
+ data_source_files: Dict[str, Any] = {},
18
+ is_bookmarked: bool = False,
19
+ correlation_id: Optional[str] = None,
20
+ api_version: str = ApiVersion.V1.value,
21
+ ):
22
+ """
23
+ Prepare request data for creating a new conversation.
24
+
25
+ This internal method constructs the URL and payload for conversation creation
26
+ requests, including all conversation metadata and settings.
27
+
28
+ Args:
29
+ user_id: ID of the user creating the conversation
30
+ title: Optional title for the conversation
31
+ deployment_id: Optional deployment to associate with the conversation
32
+ data_source_files: Optional data source files configuration
33
+ is_bookmarked: Whether the conversation should be bookmarked
34
+ correlation_id: Optional correlation ID for tracing
35
+ api_version: API version to use for the request
36
+
37
+ Returns:
38
+ RequestData: Prepared request data for the conversation creation endpoint
39
+
40
+ Raises:
41
+ ValueError: If an invalid API version is provided
42
+ """
43
+ if api_version not in ApiVersion.as_list():
44
+ raise ValueError(
45
+ f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
46
+ )
47
+ url = urljoin(self._request_handler.base_url, f"{api_version}/Conversations")
48
+
49
+ payload = {
50
+ "userId": user_id,
51
+ "title": title,
52
+ "deploymentId": deployment_id,
53
+ "dataSourceFiles": data_source_files,
54
+ "isBookmarked": is_bookmarked,
55
+ }
56
+
57
+ request_data = self._request_handler.prepare_request(
58
+ url=url, payload=payload, correlation_id=correlation_id
59
+ )
60
+
61
+ return request_data
62
+
63
+ def _pre_get_conversation(
64
+ self,
65
+ conversation_id: str,
66
+ correlation_id: Optional[str] = None,
67
+ api_version: str = ApiVersion.V1.value,
68
+ ):
69
+ """
70
+ Prepare request data for retrieving a conversation by ID.
71
+
72
+ This internal method constructs the URL for conversation retrieval
73
+ requests using the provided conversation identifier.
74
+
75
+ Args:
76
+ conversation_id: ID of the conversation to retrieve
77
+ correlation_id: Optional correlation ID for tracing
78
+ api_version: API version to use for the request
79
+
80
+ Returns:
81
+ RequestData: Prepared request data for the conversation retrieval endpoint
82
+
83
+ Raises:
84
+ ValueError: If an invalid API version is provided
85
+ """
86
+ if api_version not in ApiVersion.as_list():
87
+ raise ValueError(
88
+ f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
89
+ )
90
+ url = urljoin(
91
+ self._request_handler.base_url,
92
+ f"{api_version}/Conversations/{conversation_id}",
93
+ )
94
+ request_data = self._request_handler.prepare_request(
95
+ url, correlation_id=correlation_id
96
+ )
97
+
98
+ return request_data
99
+
100
+ def _pre_delete_conversation(
101
+ self,
102
+ conversation_id: str,
103
+ correlation_id: Optional[str] = None,
104
+ api_version: str = ApiVersion.V1.value,
105
+ ):
106
+ """
107
+ Prepare request data for deleting a conversation by ID.
108
+
109
+ This internal method constructs the URL for conversation deletion
110
+ requests using the provided conversation identifier.
111
+
112
+ Args:
113
+ conversation_id: ID of the conversation to delete
114
+ correlation_id: Optional correlation ID for tracing
115
+ api_version: API version to use for the request
116
+
117
+ Returns:
118
+ RequestData: Prepared request data for the conversation deletion endpoint
119
+
120
+ Raises:
121
+ ValueError: If an invalid API version is provided
122
+ """
123
+ if api_version not in ApiVersion.as_list():
124
+ raise ValueError(
125
+ f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
126
+ )
127
+ url = urljoin(
128
+ self._request_handler.base_url,
129
+ f"{api_version}/Conversations/{conversation_id}",
130
+ )
131
+ request_data = self._request_handler.prepare_request(
132
+ url, correlation_id=correlation_id
133
+ )
134
+
135
+ return request_data