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
|
@@ -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
|
|
@@ -0,0 +1,182 @@
|
|
|
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 RequestHandler
|
|
9
|
+
from .base_conversations import BaseConversations
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Conversations(BaseConversations):
|
|
13
|
+
def __init__(self, request_handler: RequestHandler):
|
|
14
|
+
super().__init__(request_handler)
|
|
15
|
+
|
|
16
|
+
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 AiriaClient
|
|
59
|
+
|
|
60
|
+
client = AiriaClient(api_key="your_api_key")
|
|
61
|
+
|
|
62
|
+
# Create a basic conversation
|
|
63
|
+
conversation = client.conversations.create_conversation(
|
|
64
|
+
user_id="user_123"
|
|
65
|
+
)
|
|
66
|
+
print(f"Created conversation: {conversation.id}")
|
|
67
|
+
|
|
68
|
+
# Create a conversation with all options
|
|
69
|
+
conversation = 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.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 = self._request_handler.make_request("POST", request_data)
|
|
93
|
+
|
|
94
|
+
return CreateConversationResponse(**resp)
|
|
95
|
+
|
|
96
|
+
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 AiriaClient
|
|
125
|
+
|
|
126
|
+
client = AiriaClient(api_key="your_api_key")
|
|
127
|
+
|
|
128
|
+
# Get conversation details
|
|
129
|
+
conversation = client.conversations.get_conversation(
|
|
130
|
+
conversation_id="conversation_123"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
print(f"Conversation: {conversation.title}")
|
|
134
|
+
print(f"User: {conversation.user_id}")
|
|
135
|
+
print(f"Messages: {len(conversation.messages)}")
|
|
136
|
+
print(f"Bookmarked: {conversation.is_bookmarked}")
|
|
137
|
+
|
|
138
|
+
# Access individual messages
|
|
139
|
+
for message in conversation.messages:
|
|
140
|
+
print(f"[{message.role}]: {message.message}")
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Note:
|
|
144
|
+
This method only retrieves conversation information and does not
|
|
145
|
+
modify or execute any operations on the conversation.
|
|
146
|
+
"""
|
|
147
|
+
request_data = self._pre_get_conversation(
|
|
148
|
+
conversation_id=conversation_id,
|
|
149
|
+
correlation_id=correlation_id,
|
|
150
|
+
api_version=ApiVersion.V1.value,
|
|
151
|
+
)
|
|
152
|
+
resp = self._request_handler.make_request("GET", request_data)
|
|
153
|
+
|
|
154
|
+
return GetConversationResponse(**resp)
|
|
155
|
+
|
|
156
|
+
def delete_conversation(
|
|
157
|
+
self,
|
|
158
|
+
conversation_id: str,
|
|
159
|
+
correlation_id: Optional[str] = None,
|
|
160
|
+
) -> None:
|
|
161
|
+
"""
|
|
162
|
+
Delete a conversation by its ID.
|
|
163
|
+
|
|
164
|
+
This method permanently removes a conversation and all associated data
|
|
165
|
+
from the Airia platform. This action cannot be undone.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
conversation_id: The unique identifier of the conversation to delete
|
|
169
|
+
correlation_id: Optional correlation ID for request tracing
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
None: This method returns nothing upon successful deletion
|
|
173
|
+
|
|
174
|
+
Raises:
|
|
175
|
+
AiriaAPIError: If the API request fails or the conversation doesn't exist
|
|
176
|
+
"""
|
|
177
|
+
request_data = self._pre_delete_conversation(
|
|
178
|
+
conversation_id=conversation_id,
|
|
179
|
+
correlation_id=correlation_id,
|
|
180
|
+
api_version=ApiVersion.V1.value,
|
|
181
|
+
)
|
|
182
|
+
self._request_handler.make_request("DELETE", request_data, return_json=False)
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
from typing import Any, Dict, List, Literal, Optional, Union, overload
|
|
2
|
+
|
|
3
|
+
from ...types._api_version import ApiVersion
|
|
4
|
+
from ...types.api.pipeline_execution import (
|
|
5
|
+
PipelineExecutionAsyncStreamedResponse,
|
|
6
|
+
PipelineExecutionDebugResponse,
|
|
7
|
+
PipelineExecutionResponse,
|
|
8
|
+
)
|
|
9
|
+
from .._request_handler import AsyncRequestHandler
|
|
10
|
+
from .base_pipeline_execution import BasePipelineExecution
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AsyncPipelineExecution(BasePipelineExecution):
|
|
14
|
+
def __init__(self, request_handler: AsyncRequestHandler):
|
|
15
|
+
super().__init__(request_handler)
|
|
16
|
+
|
|
17
|
+
@overload
|
|
18
|
+
async def execute_pipeline(
|
|
19
|
+
self,
|
|
20
|
+
pipeline_id: str,
|
|
21
|
+
user_input: str,
|
|
22
|
+
debug: Literal[False] = False,
|
|
23
|
+
user_id: Optional[str] = None,
|
|
24
|
+
conversation_id: Optional[str] = None,
|
|
25
|
+
async_output: Literal[False] = False,
|
|
26
|
+
include_tools_response: bool = False,
|
|
27
|
+
images: Optional[List[str]] = None,
|
|
28
|
+
files: Optional[List[str]] = None,
|
|
29
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
30
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
31
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
32
|
+
current_date_time: Optional[str] = None,
|
|
33
|
+
save_history: bool = True,
|
|
34
|
+
additional_info: Optional[List[Any]] = None,
|
|
35
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
36
|
+
correlation_id: Optional[str] = None,
|
|
37
|
+
) -> PipelineExecutionResponse: ...
|
|
38
|
+
|
|
39
|
+
@overload
|
|
40
|
+
async def execute_pipeline(
|
|
41
|
+
self,
|
|
42
|
+
pipeline_id: str,
|
|
43
|
+
user_input: str,
|
|
44
|
+
debug: Literal[True] = True,
|
|
45
|
+
user_id: Optional[str] = None,
|
|
46
|
+
conversation_id: Optional[str] = None,
|
|
47
|
+
async_output: Literal[False] = False,
|
|
48
|
+
include_tools_response: bool = False,
|
|
49
|
+
images: Optional[List[str]] = None,
|
|
50
|
+
files: Optional[List[str]] = None,
|
|
51
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
52
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
53
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
54
|
+
current_date_time: Optional[str] = None,
|
|
55
|
+
save_history: bool = True,
|
|
56
|
+
additional_info: Optional[List[Any]] = None,
|
|
57
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
58
|
+
correlation_id: Optional[str] = None,
|
|
59
|
+
) -> PipelineExecutionDebugResponse: ...
|
|
60
|
+
|
|
61
|
+
@overload
|
|
62
|
+
async def execute_pipeline(
|
|
63
|
+
self,
|
|
64
|
+
pipeline_id: str,
|
|
65
|
+
user_input: str,
|
|
66
|
+
debug: bool = False,
|
|
67
|
+
user_id: Optional[str] = None,
|
|
68
|
+
conversation_id: Optional[str] = None,
|
|
69
|
+
async_output: Literal[True] = True,
|
|
70
|
+
include_tools_response: bool = False,
|
|
71
|
+
images: Optional[List[str]] = None,
|
|
72
|
+
files: Optional[List[str]] = None,
|
|
73
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
74
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
75
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
76
|
+
current_date_time: Optional[str] = None,
|
|
77
|
+
save_history: bool = True,
|
|
78
|
+
additional_info: Optional[List[Any]] = None,
|
|
79
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
80
|
+
correlation_id: Optional[str] = None,
|
|
81
|
+
) -> PipelineExecutionAsyncStreamedResponse: ...
|
|
82
|
+
|
|
83
|
+
async def execute_pipeline(
|
|
84
|
+
self,
|
|
85
|
+
pipeline_id: str,
|
|
86
|
+
user_input: str,
|
|
87
|
+
debug: bool = False,
|
|
88
|
+
user_id: Optional[str] = None,
|
|
89
|
+
conversation_id: Optional[str] = None,
|
|
90
|
+
async_output: bool = False,
|
|
91
|
+
include_tools_response: bool = False,
|
|
92
|
+
images: Optional[List[str]] = None,
|
|
93
|
+
files: Optional[List[str]] = None,
|
|
94
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
95
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
96
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
97
|
+
current_date_time: Optional[str] = None,
|
|
98
|
+
save_history: bool = True,
|
|
99
|
+
additional_info: Optional[List[Any]] = None,
|
|
100
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
101
|
+
correlation_id: Optional[str] = None,
|
|
102
|
+
) -> Union[
|
|
103
|
+
PipelineExecutionDebugResponse,
|
|
104
|
+
PipelineExecutionResponse,
|
|
105
|
+
PipelineExecutionAsyncStreamedResponse,
|
|
106
|
+
]:
|
|
107
|
+
"""
|
|
108
|
+
Execute a pipeline with the provided input asynchronously.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
pipeline_id: The ID of the pipeline to execute.
|
|
112
|
+
user_input: input text to process.
|
|
113
|
+
debug: Whether debug mode execution is enabled. Default is False.
|
|
114
|
+
user_id: Optional ID of the user making the request (guid).
|
|
115
|
+
conversation_id: Optional conversation ID (guid).
|
|
116
|
+
async_output: Whether to stream the response. Default is False.
|
|
117
|
+
include_tools_response: Whether to return the initial LLM tool result. Default is False.
|
|
118
|
+
images: Optional list of images formatted as base64 strings.
|
|
119
|
+
files: Optional list of files formatted as base64 strings.
|
|
120
|
+
data_source_folders: Optional data source folders information.
|
|
121
|
+
data_source_files: Optional data source files information.
|
|
122
|
+
in_memory_messages: Optional list of in-memory messages, each with a role and message.
|
|
123
|
+
current_date_time: Optional current date and time in ISO format.
|
|
124
|
+
save_history: Whether to save the userInput and output to conversation history. Default is True.
|
|
125
|
+
additional_info: Optional additional information.
|
|
126
|
+
prompt_variables: Optional variables to be used in the prompt.
|
|
127
|
+
correlation_id: Optional correlation ID for request tracing. If not provided,
|
|
128
|
+
one will be generated automatically.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
Response containing the result of the execution.
|
|
132
|
+
|
|
133
|
+
Raises:
|
|
134
|
+
AiriaAPIError: If the API request fails with details about the error.
|
|
135
|
+
aiohttp.ClientError: For other request-related errors.
|
|
136
|
+
|
|
137
|
+
Example:
|
|
138
|
+
```python
|
|
139
|
+
client = AiriaAsyncClient(api_key="your_api_key")
|
|
140
|
+
response = await client.pipeline_execution.execute_pipeline(
|
|
141
|
+
pipeline_id="pipeline_123",
|
|
142
|
+
user_input="Tell me about quantum computing"
|
|
143
|
+
)
|
|
144
|
+
print(response.result)
|
|
145
|
+
```
|
|
146
|
+
"""
|
|
147
|
+
request_data = self._pre_execute_pipeline(
|
|
148
|
+
pipeline_id=pipeline_id,
|
|
149
|
+
user_input=user_input,
|
|
150
|
+
debug=debug,
|
|
151
|
+
user_id=user_id,
|
|
152
|
+
conversation_id=conversation_id,
|
|
153
|
+
async_output=async_output,
|
|
154
|
+
include_tools_response=include_tools_response,
|
|
155
|
+
images=images,
|
|
156
|
+
files=files,
|
|
157
|
+
data_source_folders=data_source_folders,
|
|
158
|
+
data_source_files=data_source_files,
|
|
159
|
+
in_memory_messages=in_memory_messages,
|
|
160
|
+
current_date_time=current_date_time,
|
|
161
|
+
save_history=save_history,
|
|
162
|
+
additional_info=additional_info,
|
|
163
|
+
prompt_variables=prompt_variables,
|
|
164
|
+
correlation_id=correlation_id,
|
|
165
|
+
api_version=ApiVersion.V2.value,
|
|
166
|
+
)
|
|
167
|
+
resp = (
|
|
168
|
+
self._request_handler.make_request_stream("POST", request_data)
|
|
169
|
+
if async_output
|
|
170
|
+
else await self._request_handler.make_request("POST", request_data)
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
if not async_output:
|
|
174
|
+
if not debug:
|
|
175
|
+
return PipelineExecutionResponse(**resp)
|
|
176
|
+
return PipelineExecutionDebugResponse(**resp)
|
|
177
|
+
|
|
178
|
+
return PipelineExecutionAsyncStreamedResponse(stream=resp)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from typing import Any, Dict, List, 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 BasePipelineExecution:
|
|
9
|
+
def __init__(self, request_handler: Union[RequestHandler, AsyncRequestHandler]):
|
|
10
|
+
self._request_handler = request_handler
|
|
11
|
+
|
|
12
|
+
def _pre_execute_pipeline(
|
|
13
|
+
self,
|
|
14
|
+
pipeline_id: str,
|
|
15
|
+
user_input: str,
|
|
16
|
+
debug: bool = False,
|
|
17
|
+
user_id: Optional[str] = None,
|
|
18
|
+
conversation_id: Optional[str] = None,
|
|
19
|
+
async_output: bool = False,
|
|
20
|
+
include_tools_response: bool = False,
|
|
21
|
+
images: Optional[List[str]] = None,
|
|
22
|
+
files: Optional[List[str]] = None,
|
|
23
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
24
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
25
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
26
|
+
current_date_time: Optional[str] = None,
|
|
27
|
+
save_history: bool = True,
|
|
28
|
+
additional_info: Optional[List[Any]] = None,
|
|
29
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
30
|
+
correlation_id: Optional[str] = None,
|
|
31
|
+
api_version: str = ApiVersion.V2.value,
|
|
32
|
+
):
|
|
33
|
+
"""
|
|
34
|
+
Prepare request data for pipeline execution endpoint.
|
|
35
|
+
|
|
36
|
+
This internal method constructs the URL and payload for pipeline execution
|
|
37
|
+
requests, validating the API version and preparing all request components.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
pipeline_id: ID of the pipeline to execute
|
|
41
|
+
user_input: Input text to process
|
|
42
|
+
debug: Whether to enable debug mode
|
|
43
|
+
user_id: Optional user identifier
|
|
44
|
+
conversation_id: Optional conversation identifier
|
|
45
|
+
async_output: Whether to enable streaming output
|
|
46
|
+
include_tools_response: Whether to include tool responses
|
|
47
|
+
images: Optional list of base64-encoded images
|
|
48
|
+
files: Optional list of base64-encoded files
|
|
49
|
+
data_source_folders: Optional data source folder configuration
|
|
50
|
+
data_source_files: Optional data source files configuration
|
|
51
|
+
in_memory_messages: Optional list of in-memory messages
|
|
52
|
+
current_date_time: Optional current date/time in ISO format
|
|
53
|
+
save_history: Whether to save to conversation history
|
|
54
|
+
additional_info: Optional additional information
|
|
55
|
+
prompt_variables: Optional prompt variables
|
|
56
|
+
correlation_id: Optional correlation ID for tracing
|
|
57
|
+
api_version: API version to use for the request
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
RequestData: Prepared request data for the pipeline execution endpoint
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
ValueError: If an invalid API version is provided
|
|
64
|
+
"""
|
|
65
|
+
if api_version not in ApiVersion.as_list():
|
|
66
|
+
raise ValueError(
|
|
67
|
+
f"Invalid API version: {api_version}. Valid versions are: {', '.join(ApiVersion.as_list())}"
|
|
68
|
+
)
|
|
69
|
+
url = urljoin(
|
|
70
|
+
self._request_handler.base_url,
|
|
71
|
+
f"{api_version}/PipelineExecution/{pipeline_id}",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
payload = {
|
|
75
|
+
"userInput": user_input,
|
|
76
|
+
"debug": debug,
|
|
77
|
+
"userId": user_id,
|
|
78
|
+
"conversationId": conversation_id,
|
|
79
|
+
"asyncOutput": async_output,
|
|
80
|
+
"includeToolsResponse": include_tools_response,
|
|
81
|
+
"images": images,
|
|
82
|
+
"files": files,
|
|
83
|
+
"dataSourceFolders": data_source_folders,
|
|
84
|
+
"dataSourceFiles": data_source_files,
|
|
85
|
+
"inMemoryMessages": in_memory_messages,
|
|
86
|
+
"currentDateTime": current_date_time,
|
|
87
|
+
"saveHistory": save_history,
|
|
88
|
+
"additionalInfo": additional_info,
|
|
89
|
+
"promptVariables": prompt_variables,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
request_data = self._request_handler.prepare_request(
|
|
93
|
+
url=url, payload=payload, correlation_id=correlation_id
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
return request_data
|