simplai-sdk 0.1.0__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.
- billing/__init__.py +6 -0
- billing/api.py +55 -0
- billing/client.py +14 -0
- billing/schema.py +15 -0
- constants/__init__.py +90 -0
- core/__init__.py +53 -0
- core/agents/__init__.py +42 -0
- core/agents/execution/__init__.py +49 -0
- core/agents/execution/api.py +283 -0
- core/agents/execution/client.py +1139 -0
- core/agents/models.py +99 -0
- core/workflows/WORKFLOW_ARCHITECTURE.md +417 -0
- core/workflows/__init__.py +31 -0
- core/workflows/bulk/__init__.py +14 -0
- core/workflows/bulk/api.py +202 -0
- core/workflows/bulk/client.py +115 -0
- core/workflows/bulk/schema.py +58 -0
- core/workflows/models.py +49 -0
- core/workflows/scheduling/__init__.py +9 -0
- core/workflows/scheduling/api.py +179 -0
- core/workflows/scheduling/client.py +128 -0
- core/workflows/scheduling/schema.py +74 -0
- core/workflows/tool_execution/__init__.py +16 -0
- core/workflows/tool_execution/api.py +172 -0
- core/workflows/tool_execution/client.py +195 -0
- core/workflows/tool_execution/schema.py +40 -0
- exceptions/__init__.py +21 -0
- simplai_sdk/__init__.py +7 -0
- simplai_sdk/simplai.py +239 -0
- simplai_sdk-0.1.0.dist-info/METADATA +728 -0
- simplai_sdk-0.1.0.dist-info/RECORD +42 -0
- simplai_sdk-0.1.0.dist-info/WHEEL +5 -0
- simplai_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
- simplai_sdk-0.1.0.dist-info/top_level.txt +7 -0
- traces/__init__.py +1 -0
- traces/agents/__init__.py +55 -0
- traces/agents/api.py +350 -0
- traces/agents/client.py +697 -0
- traces/agents/models.py +249 -0
- traces/workflows/__init__.py +0 -0
- utils/__init__.py +0 -0
- utils/config.py +117 -0
simplai_sdk/simplai.py
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
from typing import Any, Callable, Dict, List, Optional, Union
|
|
2
|
+
|
|
3
|
+
from core import (
|
|
4
|
+
cancel_bulk_run,
|
|
5
|
+
cancel_execution,
|
|
6
|
+
download_bulk_run_result,
|
|
7
|
+
execute_and_wait_workflow,
|
|
8
|
+
execute_workflow,
|
|
9
|
+
get_bulk_run_status,
|
|
10
|
+
get_tool_result,
|
|
11
|
+
trigger_bulk_run,
|
|
12
|
+
)
|
|
13
|
+
from core.agents import (
|
|
14
|
+
agent_chat_async,
|
|
15
|
+
agent_chat_stream_async,
|
|
16
|
+
AgentResult,
|
|
17
|
+
AgentStreamChunk,
|
|
18
|
+
)
|
|
19
|
+
from core.workflows.scheduling import cancel_schedule_run as cancel_schedule_run_func, schedule_run as schedule_run_func
|
|
20
|
+
from billing import get_billing_detail
|
|
21
|
+
from traces.agents import get_trace_tree, TraceNode
|
|
22
|
+
from utils.config import get_api_key, get_base_url
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class SimplAI:
|
|
26
|
+
def __init__(self, api_key: Optional[str] = None, base_url: Optional[str] = None):
|
|
27
|
+
"""
|
|
28
|
+
Initialize SimplAI client.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
api_key: Optional API key. If not provided, loads from API_KEY env var or .env file.
|
|
32
|
+
base_url: Optional base URL. If not provided, loads from BASE_URL env var or uses default.
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
ValueError: If API key is not found in any source.
|
|
36
|
+
"""
|
|
37
|
+
self.api_key = get_api_key(api_key)
|
|
38
|
+
|
|
39
|
+
# ------------------------------------------------------------------
|
|
40
|
+
# WORKFLOWS
|
|
41
|
+
# ------------------------------------------------------------------
|
|
42
|
+
|
|
43
|
+
async def execute_workflow(
|
|
44
|
+
self,
|
|
45
|
+
workflow_id: str,
|
|
46
|
+
inputs: Dict[str, Any],
|
|
47
|
+
) -> Dict[str, str]:
|
|
48
|
+
return await execute_workflow(workflow_id, inputs, self.api_key)
|
|
49
|
+
|
|
50
|
+
async def trigger_bulk_run(
|
|
51
|
+
self,
|
|
52
|
+
workflow_id: str,
|
|
53
|
+
file_link: str,
|
|
54
|
+
batch_size: int,
|
|
55
|
+
input_mapping: List[Dict[str, str]],
|
|
56
|
+
) -> Dict[str, str]:
|
|
57
|
+
return await trigger_bulk_run(
|
|
58
|
+
workflow_id,
|
|
59
|
+
file_link,
|
|
60
|
+
batch_size,
|
|
61
|
+
input_mapping,
|
|
62
|
+
self.api_key,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
async def execute_and_wait_workflow(
|
|
66
|
+
self,
|
|
67
|
+
workflow_id: str,
|
|
68
|
+
inputs: Dict[str, Any],
|
|
69
|
+
timeout: float = 60.0,
|
|
70
|
+
poll_interval: float = 2.0,
|
|
71
|
+
) -> Dict[str, Any]:
|
|
72
|
+
return await execute_and_wait_workflow(
|
|
73
|
+
workflow_id,
|
|
74
|
+
inputs,
|
|
75
|
+
self.api_key,
|
|
76
|
+
timeout,
|
|
77
|
+
poll_interval,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
async def get_tool_result(self, execution_id: str) -> Dict[str, Any]:
|
|
81
|
+
return await get_tool_result(execution_id, self.api_key)
|
|
82
|
+
|
|
83
|
+
async def cancel_execution(self, execution_id: str) -> Dict[str, str]:
|
|
84
|
+
return await cancel_execution(execution_id, self.api_key)
|
|
85
|
+
|
|
86
|
+
async def get_bulk_run_status(self, bulk_run_id: str) -> Dict[str, str]:
|
|
87
|
+
return await get_bulk_run_status(bulk_run_id, self.api_key)
|
|
88
|
+
|
|
89
|
+
async def cancel_bulk_run(self, bulk_run_id: str) -> Dict[str, str]:
|
|
90
|
+
return await cancel_bulk_run(bulk_run_id, self.api_key)
|
|
91
|
+
|
|
92
|
+
async def download_bulk_run_result(self, bulk_run_id: str) -> str:
|
|
93
|
+
"""
|
|
94
|
+
Download the bulk run result as CSV text.
|
|
95
|
+
"""
|
|
96
|
+
return await download_bulk_run_result(bulk_run_id, self.api_key)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
async def agent_chat(
|
|
101
|
+
self,
|
|
102
|
+
agent_id: str,
|
|
103
|
+
message: str,
|
|
104
|
+
) -> AgentResult:
|
|
105
|
+
"""
|
|
106
|
+
High-level agent chat helper (async), matching workflow style.
|
|
107
|
+
|
|
108
|
+
Only required params here (agent_id, message).
|
|
109
|
+
All optional config is handled by core.agents via defaults.
|
|
110
|
+
"""
|
|
111
|
+
return await agent_chat_async(
|
|
112
|
+
agent_id=agent_id,
|
|
113
|
+
message=message,
|
|
114
|
+
api_key=self.api_key,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
async def agent_chat_stream(
|
|
118
|
+
self,
|
|
119
|
+
agent_id: str,
|
|
120
|
+
message: str,
|
|
121
|
+
on_chunk: Optional[Callable[[AgentStreamChunk], None]] = None,
|
|
122
|
+
) -> AgentResult:
|
|
123
|
+
"""
|
|
124
|
+
High-level streaming agent chat helper (async), workflow-style.
|
|
125
|
+
|
|
126
|
+
Only required call-specific params here.
|
|
127
|
+
All optional config is handled by core.agents via defaults.
|
|
128
|
+
|
|
129
|
+
Note: The first chunk will contain trace_id, node_id, and tree_id for tracing.
|
|
130
|
+
Access them via chunk.trace_id, chunk.node_id, and chunk.tree_id in the on_chunk callback.
|
|
131
|
+
Use get_trace_tree to fetch trace details.
|
|
132
|
+
"""
|
|
133
|
+
return await agent_chat_stream_async(
|
|
134
|
+
agent_id=agent_id,
|
|
135
|
+
message=message,
|
|
136
|
+
api_key=self.api_key,
|
|
137
|
+
on_chunk=on_chunk,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# ------------------------------------------------------------------
|
|
141
|
+
# TRACING
|
|
142
|
+
# ------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
def get_trace_tree(
|
|
145
|
+
self,
|
|
146
|
+
node_id: str,
|
|
147
|
+
trace_id: Optional[str] = None,
|
|
148
|
+
tree_id: Optional[str] = None,
|
|
149
|
+
max_depth: Optional[int] = None,
|
|
150
|
+
user_id: Optional[str] = None,
|
|
151
|
+
tenant_id: str = "1",
|
|
152
|
+
project_id: Optional[int] = None,
|
|
153
|
+
seller_id: Optional[str] = None,
|
|
154
|
+
client_id: Optional[str] = None,
|
|
155
|
+
seller_profile_id: Optional[str] = None,
|
|
156
|
+
raw_response: bool = False,
|
|
157
|
+
) -> Union[TraceNode, Dict[str, Any]]:
|
|
158
|
+
"""Get a trace sub-tree starting from a specific node.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
node_id: Node ID to start the tree from.
|
|
162
|
+
trace_id: Trace ID (same as tree_id). Either trace_id or tree_id must be provided.
|
|
163
|
+
tree_id: Tree ID of the trace (same as trace_id). Either trace_id or tree_id must be provided.
|
|
164
|
+
max_depth: Maximum depth to traverse (optional).
|
|
165
|
+
user_id: Optional user ID for trace operations.
|
|
166
|
+
tenant_id: Tenant ID (defaults to "1").
|
|
167
|
+
project_id: Optional project ID.
|
|
168
|
+
seller_id: Optional seller ID.
|
|
169
|
+
client_id: Optional client ID.
|
|
170
|
+
seller_profile_id: Optional seller profile ID.
|
|
171
|
+
raw_response: If True, return raw JSON response instead of parsed TraceNode.
|
|
172
|
+
|
|
173
|
+
Returns:
|
|
174
|
+
TraceNode representing the root of the sub-tree, or raw JSON dict if raw_response=True.
|
|
175
|
+
"""
|
|
176
|
+
# Use trace_id if provided, otherwise use tree_id
|
|
177
|
+
final_tree_id = trace_id or tree_id
|
|
178
|
+
if not final_tree_id:
|
|
179
|
+
raise ValueError("Either trace_id or tree_id must be provided")
|
|
180
|
+
|
|
181
|
+
return get_trace_tree(
|
|
182
|
+
api_key=self.api_key,
|
|
183
|
+
tree_id=final_tree_id,
|
|
184
|
+
node_id=node_id,
|
|
185
|
+
max_depth=max_depth,
|
|
186
|
+
user_id=user_id,
|
|
187
|
+
tenant_id=tenant_id,
|
|
188
|
+
project_id=project_id,
|
|
189
|
+
seller_id=seller_id,
|
|
190
|
+
client_id=client_id,
|
|
191
|
+
seller_profile_id=seller_profile_id,
|
|
192
|
+
raw_response=raw_response,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# ------------------------------------------------------------------
|
|
196
|
+
# SCHEDULING
|
|
197
|
+
# ------------------------------------------------------------------
|
|
198
|
+
|
|
199
|
+
async def schedule_run(
|
|
200
|
+
self,
|
|
201
|
+
workflow_id: str,
|
|
202
|
+
scheduled_run_type: str,
|
|
203
|
+
cron_expression: str,
|
|
204
|
+
time_zone: str,
|
|
205
|
+
input_mapping: List[Dict[str, str]],
|
|
206
|
+
file_url: Optional[str] = None,
|
|
207
|
+
batch_size: Optional[int] = None,
|
|
208
|
+
) -> Dict[str, str]:
|
|
209
|
+
return await schedule_run_func(
|
|
210
|
+
workflow_id=workflow_id,
|
|
211
|
+
scheduled_run_type=scheduled_run_type,
|
|
212
|
+
cron_expression=cron_expression,
|
|
213
|
+
time_zone=time_zone,
|
|
214
|
+
input_mapping=input_mapping,
|
|
215
|
+
api_key=self.api_key,
|
|
216
|
+
file_url=file_url,
|
|
217
|
+
batch_size=batch_size,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
async def cancel_schedule_run(
|
|
221
|
+
self,
|
|
222
|
+
job_master_id: Union[int, str],
|
|
223
|
+
unique_id: str,
|
|
224
|
+
) -> Dict[str, str]:
|
|
225
|
+
"""
|
|
226
|
+
Cancel a scheduled run by job_master_id and unique_id.
|
|
227
|
+
"""
|
|
228
|
+
return await cancel_schedule_run_func(
|
|
229
|
+
job_master_id=job_master_id,
|
|
230
|
+
unique_id=unique_id,
|
|
231
|
+
api_key=self.api_key,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
# ------------------------------------------------------------------
|
|
235
|
+
# BILLING
|
|
236
|
+
# ------------------------------------------------------------------
|
|
237
|
+
|
|
238
|
+
async def get_billing_detail(self, trace_id: str) -> Dict[str, Any]:
|
|
239
|
+
return await get_billing_detail(trace_id=trace_id, api_key=self.api_key)
|