airia 0.1.3__tar.gz → 0.1.5__tar.gz
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-0.1.3 → airia-0.1.5}/PKG-INFO +19 -3
- {airia-0.1.3 → airia-0.1.5}/README.md +18 -2
- airia-0.1.5/airia/client/__init__.py +4 -0
- airia-0.1.5/airia/client/async_client.py +464 -0
- airia-0.1.5/airia/client/base_client.py +188 -0
- airia-0.1.5/airia/client/sync_client.py +452 -0
- airia-0.1.5/airia/types/__init__.py +19 -0
- airia-0.1.5/airia/types/api_version.py +13 -0
- airia-0.1.5/airia/types/pipeline_execution.py +31 -0
- airia-0.1.5/airia/types/request_data.py +10 -0
- {airia-0.1.3 → airia-0.1.5}/airia.egg-info/PKG-INFO +19 -3
- {airia-0.1.3 → airia-0.1.5}/airia.egg-info/SOURCES.txt +8 -0
- {airia-0.1.3 → airia-0.1.5}/pyproject.toml +13 -17
- {airia-0.1.3 → airia-0.1.5}/LICENSE +0 -0
- {airia-0.1.3 → airia-0.1.5}/airia/__init__.py +0 -0
- {airia-0.1.3 → airia-0.1.5}/airia/exceptions.py +0 -0
- {airia-0.1.3 → airia-0.1.5}/airia/logs.py +0 -0
- {airia-0.1.3 → airia-0.1.5}/airia.egg-info/dependency_links.txt +0 -0
- {airia-0.1.3 → airia-0.1.5}/airia.egg-info/requires.txt +0 -0
- {airia-0.1.3 → airia-0.1.5}/airia.egg-info/top_level.txt +0 -0
- {airia-0.1.3 → airia-0.1.5}/setup.cfg +0 -0
- {airia-0.1.3 → airia-0.1.5}/tests/test_anthropic_gateway.py +0 -0
- {airia-0.1.3 → airia-0.1.5}/tests/test_execute_pipeline.py +0 -0
- {airia-0.1.3 → airia-0.1.5}/tests/test_openai_gateway.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: airia
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Python SDK for Airia API
|
|
5
5
|
Author-email: Airia LLC <support@airia.com>
|
|
6
6
|
License: MIT
|
|
@@ -176,6 +176,20 @@ This will create both wheel and source distribution in the `dist/` directory.
|
|
|
176
176
|
|
|
177
177
|
## Quick Start
|
|
178
178
|
|
|
179
|
+
### Client Instantiation
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
from airia import AiriaClient
|
|
183
|
+
|
|
184
|
+
client = AiriaClient(
|
|
185
|
+
base_url="https://api.airia.com", # Default: "https://api.airia.com"
|
|
186
|
+
api_key=None, # Or set AIRIA_API_KEY environment variable
|
|
187
|
+
timeout=30.0, # Request timeout in seconds (default: 30.0)
|
|
188
|
+
log_requests=False, # Enable request/response logging (default: False)
|
|
189
|
+
custom_logger=None # Use custom logger (default: None - uses built-in)
|
|
190
|
+
)
|
|
191
|
+
```
|
|
192
|
+
|
|
179
193
|
### Synchronous Usage
|
|
180
194
|
|
|
181
195
|
```python
|
|
@@ -208,7 +222,7 @@ response = client.execute_pipeline(
|
|
|
208
222
|
async_output=True
|
|
209
223
|
)
|
|
210
224
|
|
|
211
|
-
for c in
|
|
225
|
+
for c in response.stream:
|
|
212
226
|
print(c, end="")
|
|
213
227
|
```
|
|
214
228
|
|
|
@@ -244,7 +258,7 @@ async def main():
|
|
|
244
258
|
user_input="Tell me about quantum computing",
|
|
245
259
|
async_output=True
|
|
246
260
|
)
|
|
247
|
-
async for c in
|
|
261
|
+
async for c in response.stream:
|
|
248
262
|
print(c, end="")
|
|
249
263
|
|
|
250
264
|
asyncio.run(main())
|
|
@@ -292,6 +306,8 @@ response = client.anthropic.messages.create(
|
|
|
292
306
|
print(response.content[0].text)
|
|
293
307
|
```
|
|
294
308
|
|
|
309
|
+
You can set the Gateway URL by passing the `gateway_url` parameter when using the gateway constructors. The default values are `https://gateway.airia.ai/openai/v1` for OpenAI and `https://gateway.airia.ai/anthropic` for Anthropic.
|
|
310
|
+
|
|
295
311
|
### Asynchronous Gateway Usage
|
|
296
312
|
|
|
297
313
|
Both gateways also support asynchronous usage:
|
|
@@ -146,6 +146,20 @@ This will create both wheel and source distribution in the `dist/` directory.
|
|
|
146
146
|
|
|
147
147
|
## Quick Start
|
|
148
148
|
|
|
149
|
+
### Client Instantiation
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from airia import AiriaClient
|
|
153
|
+
|
|
154
|
+
client = AiriaClient(
|
|
155
|
+
base_url="https://api.airia.com", # Default: "https://api.airia.com"
|
|
156
|
+
api_key=None, # Or set AIRIA_API_KEY environment variable
|
|
157
|
+
timeout=30.0, # Request timeout in seconds (default: 30.0)
|
|
158
|
+
log_requests=False, # Enable request/response logging (default: False)
|
|
159
|
+
custom_logger=None # Use custom logger (default: None - uses built-in)
|
|
160
|
+
)
|
|
161
|
+
```
|
|
162
|
+
|
|
149
163
|
### Synchronous Usage
|
|
150
164
|
|
|
151
165
|
```python
|
|
@@ -178,7 +192,7 @@ response = client.execute_pipeline(
|
|
|
178
192
|
async_output=True
|
|
179
193
|
)
|
|
180
194
|
|
|
181
|
-
for c in
|
|
195
|
+
for c in response.stream:
|
|
182
196
|
print(c, end="")
|
|
183
197
|
```
|
|
184
198
|
|
|
@@ -214,7 +228,7 @@ async def main():
|
|
|
214
228
|
user_input="Tell me about quantum computing",
|
|
215
229
|
async_output=True
|
|
216
230
|
)
|
|
217
|
-
async for c in
|
|
231
|
+
async for c in response.stream:
|
|
218
232
|
print(c, end="")
|
|
219
233
|
|
|
220
234
|
asyncio.run(main())
|
|
@@ -262,6 +276,8 @@ response = client.anthropic.messages.create(
|
|
|
262
276
|
print(response.content[0].text)
|
|
263
277
|
```
|
|
264
278
|
|
|
279
|
+
You can set the Gateway URL by passing the `gateway_url` parameter when using the gateway constructors. The default values are `https://gateway.airia.ai/openai/v1` for OpenAI and `https://gateway.airia.ai/anthropic` for Anthropic.
|
|
280
|
+
|
|
265
281
|
### Asynchronous Gateway Usage
|
|
266
282
|
|
|
267
283
|
Both gateways also support asynchronous usage:
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
from typing import Any, AsyncIterator, Dict, List, Literal, Optional, overload
|
|
2
|
+
from urllib.parse import urljoin
|
|
3
|
+
|
|
4
|
+
import aiohttp
|
|
5
|
+
import loguru
|
|
6
|
+
|
|
7
|
+
from ..exceptions import AiriaAPIError
|
|
8
|
+
from ..types import (
|
|
9
|
+
ApiVersion,
|
|
10
|
+
PipelineExecutionDebugResponse,
|
|
11
|
+
PipelineExecutionResponse,
|
|
12
|
+
PipelineExecutionV1StreamedResponse,
|
|
13
|
+
PipelineExecutionV2AsyncStreamedResponse,
|
|
14
|
+
RequestData,
|
|
15
|
+
)
|
|
16
|
+
from .base_client import AiriaBaseClient
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AiriaAsyncClient(AiriaBaseClient):
|
|
20
|
+
"""Asynchronous client for interacting with the Airia API."""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
base_url: str = "https://api.airia.ai/",
|
|
25
|
+
api_key: Optional[str] = None,
|
|
26
|
+
timeout: float = 30.0,
|
|
27
|
+
log_requests: bool = False,
|
|
28
|
+
custom_logger: Optional["loguru.Logger"] = None,
|
|
29
|
+
):
|
|
30
|
+
"""
|
|
31
|
+
Initialize the asynchronous Airia API client.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
base_url: Base URL of the Airia API.
|
|
35
|
+
api_key: API key for authentication. If not provided, will attempt to use AIRIA_API_KEY environment variable.
|
|
36
|
+
timeout: Request timeout in seconds.
|
|
37
|
+
log_requests: Whether to log API requests and responses. Default is False.
|
|
38
|
+
custom_logger: Optional custom logger object to use for logging. If not provided, will use a default logger when `log_requests` is True.
|
|
39
|
+
"""
|
|
40
|
+
super().__init__(
|
|
41
|
+
base_url=base_url,
|
|
42
|
+
api_key=api_key,
|
|
43
|
+
timeout=timeout,
|
|
44
|
+
log_requests=log_requests,
|
|
45
|
+
custom_logger=custom_logger,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Session will be initialized in __aenter__
|
|
49
|
+
self.session = None
|
|
50
|
+
self.headers = {"Content-Type": "application/json"}
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def with_openai_gateway(
|
|
54
|
+
cls,
|
|
55
|
+
base_url: str = "https://api.airia.ai/",
|
|
56
|
+
gateway_url: str = "https://gateway.airia.ai/openai/v1",
|
|
57
|
+
api_key: Optional[str] = None,
|
|
58
|
+
timeout: float = 30.0,
|
|
59
|
+
log_requests: bool = False,
|
|
60
|
+
custom_logger: Optional["loguru.Logger"] = None,
|
|
61
|
+
**kwargs,
|
|
62
|
+
):
|
|
63
|
+
"""
|
|
64
|
+
Initialize the asynchronous Airia API client with AsyncOpenAI gateway capabilities.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
base_url: Base URL of the Airia API.
|
|
68
|
+
gateway_url: Base URL of the Airia Gateway API.
|
|
69
|
+
api_key: API key for authentication. If not provided, will attempt to use AIRIA_API_KEY environment variable.
|
|
70
|
+
timeout: Request timeout in seconds.
|
|
71
|
+
log_requests: Whether to log API requests and responses. Default is False.
|
|
72
|
+
custom_logger: Optional custom logger object to use for logging. If not provided, will use a default logger when `log_requests` is True.
|
|
73
|
+
**kwargs: Additional keyword arguments to pass to the AsyncOpenAI client initialization.
|
|
74
|
+
"""
|
|
75
|
+
from openai import AsyncOpenAI
|
|
76
|
+
|
|
77
|
+
api_key = cls._get_api_key(api_key)
|
|
78
|
+
cls.openai = AsyncOpenAI(
|
|
79
|
+
api_key=api_key,
|
|
80
|
+
base_url=gateway_url,
|
|
81
|
+
**kwargs,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
return cls(base_url, api_key, timeout, log_requests, custom_logger)
|
|
85
|
+
|
|
86
|
+
@classmethod
|
|
87
|
+
def with_anthropic_gateway(
|
|
88
|
+
cls,
|
|
89
|
+
base_url: str = "https://api.airia.ai/",
|
|
90
|
+
gateway_url: str = "https://gateway.airia.ai/anthropic",
|
|
91
|
+
api_key: Optional[str] = None,
|
|
92
|
+
timeout: float = 30.0,
|
|
93
|
+
log_requests: bool = False,
|
|
94
|
+
custom_logger: Optional["loguru.Logger"] = None,
|
|
95
|
+
**kwargs,
|
|
96
|
+
):
|
|
97
|
+
"""
|
|
98
|
+
Initialize the asynchronous Airia API client with AsyncAnthropic gateway capabilities.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
base_url: Base URL of the Airia API.
|
|
102
|
+
gateway_url: Base URL of the Airia Gateway API.
|
|
103
|
+
api_key: API key for authentication. If not provided, will attempt to use AIRIA_API_KEY environment variable.
|
|
104
|
+
timeout: Request timeout in seconds.
|
|
105
|
+
log_requests: Whether to log API requests and responses. Default is False.
|
|
106
|
+
custom_logger: Optional custom logger object to use for logging. If not provided, will use a default logger when `log_requests` is True.
|
|
107
|
+
**kwargs: Additional keyword arguments to pass to the AsyncAnthropic client initialization.
|
|
108
|
+
"""
|
|
109
|
+
from anthropic import AsyncAnthropic
|
|
110
|
+
|
|
111
|
+
api_key = cls._get_api_key(api_key)
|
|
112
|
+
cls.anthropic = AsyncAnthropic(
|
|
113
|
+
api_key=api_key,
|
|
114
|
+
base_url=gateway_url,
|
|
115
|
+
**kwargs,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return cls(base_url, api_key, timeout, log_requests, custom_logger)
|
|
119
|
+
|
|
120
|
+
async def __aenter__(self):
|
|
121
|
+
"""Async context manager entry point."""
|
|
122
|
+
self.session = aiohttp.ClientSession(headers=self.headers)
|
|
123
|
+
return self
|
|
124
|
+
|
|
125
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
126
|
+
"""Async context manager exit point."""
|
|
127
|
+
if self.session:
|
|
128
|
+
await self.session.close()
|
|
129
|
+
self.session = None
|
|
130
|
+
|
|
131
|
+
def _check_session(self):
|
|
132
|
+
"""Check if the client session is initialized."""
|
|
133
|
+
if not self.session:
|
|
134
|
+
raise RuntimeError(
|
|
135
|
+
"Client session not initialized. Use async with AiriaAsyncClient() as client: ..."
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
def _handle_exception(
|
|
139
|
+
self, e: aiohttp.ClientResponseError, url: str, correlation_id: str
|
|
140
|
+
):
|
|
141
|
+
# Log the error response if enabled
|
|
142
|
+
if self.log_requests:
|
|
143
|
+
self.logger.error(
|
|
144
|
+
f"API Error: {e.status} {e.message}\n"
|
|
145
|
+
f"URL: {url}\n"
|
|
146
|
+
f"Correlation ID: {correlation_id}"
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# Extract error details from response
|
|
150
|
+
error_message = e.message
|
|
151
|
+
|
|
152
|
+
# Make sure API key is not included in error messages
|
|
153
|
+
sanitized_message = (
|
|
154
|
+
error_message.replace(self.api_key, "[REDACTED]")
|
|
155
|
+
if self.api_key in error_message
|
|
156
|
+
else error_message
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# Raise custom exception with status code and sanitized message
|
|
160
|
+
raise AiriaAPIError(status_code=e.status, message=sanitized_message) from e
|
|
161
|
+
|
|
162
|
+
async def _make_request(
|
|
163
|
+
self, method: str, request_data: RequestData
|
|
164
|
+
) -> Dict[str, Any]:
|
|
165
|
+
"""
|
|
166
|
+
Makes an asynchronous HTTP request to the Airia API.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
method (str): The HTTP method (e.g., 'GET', 'POST')
|
|
170
|
+
request_data: A dictionary containing the following request information:
|
|
171
|
+
- url: The endpoint URL for the request
|
|
172
|
+
- headers: HTTP headers to include in the request
|
|
173
|
+
- payload: The JSON payload/body for the request
|
|
174
|
+
- correlation_id: Unique identifier for request tracing
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
resp ([Dict[str, Any]): The JSON response from the API as a dictionary.
|
|
178
|
+
|
|
179
|
+
Raises:
|
|
180
|
+
AiriaAPIError: If the API returns an error response, with details about the error
|
|
181
|
+
aiohttp.ClientResponseError: For HTTP-related errors
|
|
182
|
+
|
|
183
|
+
Note:
|
|
184
|
+
This is an internal method used by other client methods to make API requests.
|
|
185
|
+
It handles logging, error handling, and API key redaction in error messages.
|
|
186
|
+
"""
|
|
187
|
+
try:
|
|
188
|
+
# Make the request
|
|
189
|
+
async with self.session.request(
|
|
190
|
+
method=method,
|
|
191
|
+
url=request_data.url,
|
|
192
|
+
json=request_data.payload,
|
|
193
|
+
headers=request_data.headers,
|
|
194
|
+
timeout=self.timeout,
|
|
195
|
+
) as response:
|
|
196
|
+
# Log the response if enabled
|
|
197
|
+
if self.log_requests:
|
|
198
|
+
self.logger.info(
|
|
199
|
+
f"API Response: {response.status} {response.reason}\n"
|
|
200
|
+
f"URL: {request_data.url}\n"
|
|
201
|
+
f"Correlation ID: {request_data.correlation_id}"
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
# Check for HTTP errors
|
|
205
|
+
response.raise_for_status()
|
|
206
|
+
|
|
207
|
+
# Return the response as a dictionary
|
|
208
|
+
return await response.json()
|
|
209
|
+
|
|
210
|
+
except aiohttp.ClientResponseError as e:
|
|
211
|
+
self._handle_exception(e, request_data.url, request_data.correlation_id)
|
|
212
|
+
|
|
213
|
+
async def _make_request_stream(
|
|
214
|
+
self, method: str, request_data: RequestData
|
|
215
|
+
) -> AsyncIterator[str]:
|
|
216
|
+
"""
|
|
217
|
+
Makes an asynchronous HTTP request to the Airia API.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
method (str): The HTTP method (e.g., 'GET', 'POST')
|
|
221
|
+
request_data: A dictionary containing the following request information:
|
|
222
|
+
- url: The endpoint URL for the request
|
|
223
|
+
- headers: HTTP headers to include in the request
|
|
224
|
+
- payload: The JSON payload/body for the request
|
|
225
|
+
- correlation_id: Unique identifier for request tracing
|
|
226
|
+
|
|
227
|
+
Yields:
|
|
228
|
+
resp AsyncIterator[str]]: yields chunks of the response as they are received.
|
|
229
|
+
|
|
230
|
+
Raises:
|
|
231
|
+
AiriaAPIError: If the API returns an error response, with details about the error
|
|
232
|
+
aiohttp.ClientResponseError: For HTTP-related errors
|
|
233
|
+
|
|
234
|
+
Note:
|
|
235
|
+
This is an internal method used by other client methods to make API requests.
|
|
236
|
+
It handles logging, error handling, and API key redaction in error messages.
|
|
237
|
+
"""
|
|
238
|
+
try:
|
|
239
|
+
# Make the request
|
|
240
|
+
async with self.session.request(
|
|
241
|
+
method=method,
|
|
242
|
+
url=request_data.url,
|
|
243
|
+
json=request_data.payload,
|
|
244
|
+
headers=request_data.headers,
|
|
245
|
+
timeout=self.timeout,
|
|
246
|
+
chunked=True,
|
|
247
|
+
) as response:
|
|
248
|
+
# Log the response if enabled
|
|
249
|
+
if self.log_requests:
|
|
250
|
+
self.logger.info(
|
|
251
|
+
f"API Response: {response.status} {response.reason}\n"
|
|
252
|
+
f"URL: {request_data.url}\n"
|
|
253
|
+
f"Correlation ID: {request_data.correlation_id}"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Check for HTTP errors
|
|
257
|
+
response.raise_for_status()
|
|
258
|
+
|
|
259
|
+
# Yields the response content as a stream if streaming
|
|
260
|
+
async for chunk in response.content.iter_any():
|
|
261
|
+
yield chunk.decode("utf-8")
|
|
262
|
+
|
|
263
|
+
except aiohttp.ClientResponseError as e:
|
|
264
|
+
self._handle_exception(e, request_data.url, request_data.correlation_id)
|
|
265
|
+
|
|
266
|
+
@overload
|
|
267
|
+
async def execute_pipeline(
|
|
268
|
+
self,
|
|
269
|
+
pipeline_id: str,
|
|
270
|
+
user_input: str,
|
|
271
|
+
debug: Literal[False] = False,
|
|
272
|
+
user_id: Optional[str] = None,
|
|
273
|
+
conversation_id: Optional[str] = None,
|
|
274
|
+
async_output: Literal[False] = False,
|
|
275
|
+
include_tools_response: bool = False,
|
|
276
|
+
images: Optional[List[str]] = None,
|
|
277
|
+
files: Optional[List[str]] = None,
|
|
278
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
279
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
280
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
281
|
+
current_date_time: Optional[str] = None,
|
|
282
|
+
save_history: bool = True,
|
|
283
|
+
additional_info: Optional[List[Any]] = None,
|
|
284
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
285
|
+
correlation_id: Optional[str] = None,
|
|
286
|
+
api_version: str = ApiVersion.V2.value,
|
|
287
|
+
) -> PipelineExecutionResponse: ...
|
|
288
|
+
|
|
289
|
+
@overload
|
|
290
|
+
async def execute_pipeline(
|
|
291
|
+
self,
|
|
292
|
+
pipeline_id: str,
|
|
293
|
+
user_input: str,
|
|
294
|
+
debug: Literal[True] = True,
|
|
295
|
+
user_id: Optional[str] = None,
|
|
296
|
+
conversation_id: Optional[str] = None,
|
|
297
|
+
async_output: Literal[False] = False,
|
|
298
|
+
include_tools_response: bool = False,
|
|
299
|
+
images: Optional[List[str]] = None,
|
|
300
|
+
files: Optional[List[str]] = None,
|
|
301
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
302
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
303
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
304
|
+
current_date_time: Optional[str] = None,
|
|
305
|
+
save_history: bool = True,
|
|
306
|
+
additional_info: Optional[List[Any]] = None,
|
|
307
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
308
|
+
correlation_id: Optional[str] = None,
|
|
309
|
+
api_version: str = ApiVersion.V2.value,
|
|
310
|
+
) -> PipelineExecutionDebugResponse: ...
|
|
311
|
+
|
|
312
|
+
@overload
|
|
313
|
+
async def execute_pipeline(
|
|
314
|
+
self,
|
|
315
|
+
pipeline_id: str,
|
|
316
|
+
user_input: str,
|
|
317
|
+
debug: bool = False,
|
|
318
|
+
user_id: Optional[str] = None,
|
|
319
|
+
conversation_id: Optional[str] = None,
|
|
320
|
+
async_output: Literal[True] = True,
|
|
321
|
+
include_tools_response: bool = False,
|
|
322
|
+
images: Optional[List[str]] = None,
|
|
323
|
+
files: Optional[List[str]] = None,
|
|
324
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
325
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
326
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
327
|
+
current_date_time: Optional[str] = None,
|
|
328
|
+
save_history: bool = True,
|
|
329
|
+
additional_info: Optional[List[Any]] = None,
|
|
330
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
331
|
+
correlation_id: Optional[str] = None,
|
|
332
|
+
api_version: Literal["v2"] = ApiVersion.V2.value,
|
|
333
|
+
) -> PipelineExecutionV2AsyncStreamedResponse: ...
|
|
334
|
+
|
|
335
|
+
@overload
|
|
336
|
+
async def execute_pipeline(
|
|
337
|
+
self,
|
|
338
|
+
pipeline_id: str,
|
|
339
|
+
user_input: str,
|
|
340
|
+
debug: bool = False,
|
|
341
|
+
user_id: Optional[str] = None,
|
|
342
|
+
conversation_id: Optional[str] = None,
|
|
343
|
+
async_output: Literal[True] = True,
|
|
344
|
+
include_tools_response: bool = False,
|
|
345
|
+
images: Optional[List[str]] = None,
|
|
346
|
+
files: Optional[List[str]] = None,
|
|
347
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
348
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
349
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
350
|
+
current_date_time: Optional[str] = None,
|
|
351
|
+
save_history: bool = True,
|
|
352
|
+
additional_info: Optional[List[Any]] = None,
|
|
353
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
354
|
+
correlation_id: Optional[str] = None,
|
|
355
|
+
api_version: Literal["v1"] = ApiVersion.V1.value,
|
|
356
|
+
) -> PipelineExecutionV1StreamedResponse: ...
|
|
357
|
+
|
|
358
|
+
async def execute_pipeline(
|
|
359
|
+
self,
|
|
360
|
+
pipeline_id: str,
|
|
361
|
+
user_input: str,
|
|
362
|
+
debug: bool = False,
|
|
363
|
+
user_id: Optional[str] = None,
|
|
364
|
+
conversation_id: Optional[str] = None,
|
|
365
|
+
async_output: bool = False,
|
|
366
|
+
include_tools_response: bool = False,
|
|
367
|
+
images: Optional[List[str]] = None,
|
|
368
|
+
files: Optional[List[str]] = None,
|
|
369
|
+
data_source_folders: Optional[Dict[str, Any]] = None,
|
|
370
|
+
data_source_files: Optional[Dict[str, Any]] = None,
|
|
371
|
+
in_memory_messages: Optional[List[Dict[str, str]]] = None,
|
|
372
|
+
current_date_time: Optional[str] = None,
|
|
373
|
+
save_history: bool = True,
|
|
374
|
+
additional_info: Optional[List[Any]] = None,
|
|
375
|
+
prompt_variables: Optional[Dict[str, Any]] = None,
|
|
376
|
+
correlation_id: Optional[str] = None,
|
|
377
|
+
api_version: str = ApiVersion.V2.value,
|
|
378
|
+
) -> Dict[str, Any]:
|
|
379
|
+
"""
|
|
380
|
+
Execute a pipeline with the provided input asynchronously.
|
|
381
|
+
|
|
382
|
+
Args:
|
|
383
|
+
pipeline_id: The ID of the pipeline to execute.
|
|
384
|
+
user_input: input text to process.
|
|
385
|
+
debug: Whether debug mode execution is enabled. Default is False.
|
|
386
|
+
user_id: Optional ID of the user making the request (guid).
|
|
387
|
+
conversation_id: Optional conversation ID (guid).
|
|
388
|
+
async_output: Whether to stream the response. Default is False.
|
|
389
|
+
include_tools_response: Whether to return the initial LLM tool result. Default is False.
|
|
390
|
+
images: Optional list of images formatted as base64 strings.
|
|
391
|
+
files: Optional list of files formatted as base64 strings.
|
|
392
|
+
data_source_folders: Optional data source folders information.
|
|
393
|
+
data_source_files: Optional data source files information.
|
|
394
|
+
in_memory_messages: Optional list of in-memory messages, each with a role and message.
|
|
395
|
+
current_date_time: Optional current date and time in ISO format.
|
|
396
|
+
save_history: Whether to save the userInput and output to conversation history. Default is True.
|
|
397
|
+
additional_info: Optional additional information.
|
|
398
|
+
prompt_variables: Optional variables to be used in the prompt.
|
|
399
|
+
correlation_id: Optional correlation ID for request tracing. If not provided,
|
|
400
|
+
one will be generated automatically.
|
|
401
|
+
api_version: API version to use. Default is `v2`
|
|
402
|
+
|
|
403
|
+
Returns:
|
|
404
|
+
The API response as a dictionary.
|
|
405
|
+
|
|
406
|
+
Raises:
|
|
407
|
+
AiriaAPIError: If the API request fails with details about the error.
|
|
408
|
+
aiohttp.ClientError: For other request-related errors.
|
|
409
|
+
|
|
410
|
+
Example:
|
|
411
|
+
>>> async with AiriaAsyncClient(api_key="your_api_key") as client:
|
|
412
|
+
... response = await client.execute_pipeline(
|
|
413
|
+
... pipeline_id="pipeline_123",
|
|
414
|
+
... user_input="Tell me about quantum computing"
|
|
415
|
+
... )
|
|
416
|
+
>>> print(response.result)
|
|
417
|
+
"""
|
|
418
|
+
self._check_session()
|
|
419
|
+
|
|
420
|
+
request_data = self._pre_execute_pipeline(
|
|
421
|
+
pipeline_id=pipeline_id,
|
|
422
|
+
user_input=user_input,
|
|
423
|
+
debug=debug,
|
|
424
|
+
user_id=user_id,
|
|
425
|
+
conversation_id=conversation_id,
|
|
426
|
+
async_output=async_output,
|
|
427
|
+
include_tools_response=include_tools_response,
|
|
428
|
+
images=images,
|
|
429
|
+
files=files,
|
|
430
|
+
data_source_folders=data_source_folders,
|
|
431
|
+
data_source_files=data_source_files,
|
|
432
|
+
in_memory_messages=in_memory_messages,
|
|
433
|
+
current_date_time=current_date_time,
|
|
434
|
+
save_history=save_history,
|
|
435
|
+
additional_info=additional_info,
|
|
436
|
+
prompt_variables=prompt_variables,
|
|
437
|
+
correlation_id=correlation_id,
|
|
438
|
+
api_version=api_version,
|
|
439
|
+
)
|
|
440
|
+
stream = async_output and api_version == ApiVersion.V2.value
|
|
441
|
+
if stream:
|
|
442
|
+
resp = self._make_request_stream(method="POST", request_data=request_data)
|
|
443
|
+
else:
|
|
444
|
+
resp = await self._make_request("POST", request_data)
|
|
445
|
+
|
|
446
|
+
if not async_output:
|
|
447
|
+
if not debug:
|
|
448
|
+
return PipelineExecutionResponse(**resp)
|
|
449
|
+
return PipelineExecutionDebugResponse(**resp)
|
|
450
|
+
|
|
451
|
+
if api_version == ApiVersion.V1.value:
|
|
452
|
+
url = urljoin(
|
|
453
|
+
self.base_url, f"{api_version}/StreamSocketConfig/GenerateUrl"
|
|
454
|
+
)
|
|
455
|
+
request_data = self._prepare_request(
|
|
456
|
+
url,
|
|
457
|
+
{"socketIdentifier": resp},
|
|
458
|
+
request_data.headers["X-Correlation-ID"],
|
|
459
|
+
)
|
|
460
|
+
resp = await self._make_request("POST", request_data)
|
|
461
|
+
|
|
462
|
+
return PipelineExecutionV1StreamedResponse(**resp)
|
|
463
|
+
|
|
464
|
+
return PipelineExecutionV2AsyncStreamedResponse(stream=resp)
|