uipath 2.1.5__py3-none-any.whl → 2.1.6__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.
- uipath/_services/llm_gateway_service.py +149 -13
- {uipath-2.1.5.dist-info → uipath-2.1.6.dist-info}/METADATA +1 -1
- {uipath-2.1.5.dist-info → uipath-2.1.6.dist-info}/RECORD +6 -6
- {uipath-2.1.5.dist-info → uipath-2.1.6.dist-info}/WHEEL +0 -0
- {uipath-2.1.5.dist-info → uipath-2.1.6.dist-info}/entry_points.txt +0 -0
- {uipath-2.1.5.dist-info → uipath-2.1.6.dist-info}/licenses/LICENSE +0 -0
@@ -17,7 +17,9 @@ Classes:
|
|
17
17
|
"""
|
18
18
|
|
19
19
|
import json
|
20
|
-
from typing import Any, Dict, List, Optional
|
20
|
+
from typing import Any, Dict, List, Optional, Union
|
21
|
+
|
22
|
+
from pydantic import BaseModel
|
21
23
|
|
22
24
|
from .._config import Config
|
23
25
|
from .._execution_context import ExecutionContext
|
@@ -76,6 +78,67 @@ class EmbeddingModels(object):
|
|
76
78
|
text_embedding_ada_002 = "text-embedding-ada-002"
|
77
79
|
|
78
80
|
|
81
|
+
def _cleanup_schema(model_class: type[BaseModel]) -> Dict[str, Any]:
|
82
|
+
"""Clean up a Pydantic model schema for use with LLM Gateway.
|
83
|
+
|
84
|
+
This function converts a Pydantic model's JSON schema to a format that's
|
85
|
+
compatible with the LLM Gateway's JSON schema requirements by removing
|
86
|
+
titles and other metadata that might cause validation issues.
|
87
|
+
|
88
|
+
Args:
|
89
|
+
model_class (type[BaseModel]): A Pydantic BaseModel class to convert to schema.
|
90
|
+
|
91
|
+
Returns:
|
92
|
+
dict: A cleaned JSON schema dictionary suitable for LLM Gateway response_format.
|
93
|
+
|
94
|
+
Examples:
|
95
|
+
```python
|
96
|
+
from pydantic import BaseModel
|
97
|
+
from typing import List
|
98
|
+
|
99
|
+
class Country(BaseModel):
|
100
|
+
name: str
|
101
|
+
capital: str
|
102
|
+
languages: List[str]
|
103
|
+
|
104
|
+
schema = _cleanup_schema(Country)
|
105
|
+
# Returns a clean schema without titles and unnecessary metadata
|
106
|
+
```
|
107
|
+
"""
|
108
|
+
schema = model_class.model_json_schema()
|
109
|
+
|
110
|
+
def clean_properties(properties):
|
111
|
+
"""Clean property definitions by removing titles and cleaning nested items."""
|
112
|
+
cleaned_props = {}
|
113
|
+
for prop_name, prop_def in properties.items():
|
114
|
+
if isinstance(prop_def, dict):
|
115
|
+
cleaned_prop = {}
|
116
|
+
for key, value in prop_def.items():
|
117
|
+
if key == "title": # Skip title
|
118
|
+
continue
|
119
|
+
elif key == "items" and isinstance(value, dict):
|
120
|
+
# Clean nested items
|
121
|
+
cleaned_items = {}
|
122
|
+
for item_key, item_value in value.items():
|
123
|
+
if item_key != "title":
|
124
|
+
cleaned_items[item_key] = item_value
|
125
|
+
cleaned_prop[key] = cleaned_items
|
126
|
+
else:
|
127
|
+
cleaned_prop[key] = value
|
128
|
+
cleaned_props[prop_name] = cleaned_prop
|
129
|
+
return cleaned_props
|
130
|
+
|
131
|
+
# Create clean schema
|
132
|
+
clean_schema = {
|
133
|
+
"type": "object",
|
134
|
+
"properties": clean_properties(schema.get("properties", {})),
|
135
|
+
"required": schema.get("required", []),
|
136
|
+
"additionalProperties": False,
|
137
|
+
}
|
138
|
+
|
139
|
+
return clean_schema
|
140
|
+
|
141
|
+
|
79
142
|
class UiPathOpenAIService(BaseService):
|
80
143
|
"""Service for calling UiPath's LLM Gateway using OpenAI-compatible API.
|
81
144
|
|
@@ -146,7 +209,7 @@ class UiPathOpenAIService(BaseService):
|
|
146
209
|
model: str = ChatModels.gpt_4o_mini_2024_07_18,
|
147
210
|
max_tokens: int = 50,
|
148
211
|
temperature: float = 0,
|
149
|
-
response_format: Optional[Dict[str, Any]] = None,
|
212
|
+
response_format: Optional[Union[Dict[str, Any], type[BaseModel]]] = None,
|
150
213
|
api_version: str = API_VERSION,
|
151
214
|
):
|
152
215
|
"""Generate chat completions using UiPath's LLM Gateway service.
|
@@ -168,9 +231,11 @@ class UiPathOpenAIService(BaseService):
|
|
168
231
|
temperature (float, optional): Temperature for sampling, between 0 and 1.
|
169
232
|
Lower values (closer to 0) make output more deterministic and focused,
|
170
233
|
higher values make it more creative and random. Defaults to 0.
|
171
|
-
response_format (Optional[Dict[str, Any]], optional):
|
172
|
-
that the model must output.
|
173
|
-
|
234
|
+
response_format (Optional[Union[Dict[str, Any], type[BaseModel]]], optional):
|
235
|
+
An object specifying the format that the model must output. Can be either:
|
236
|
+
- A dictionary with response format configuration (traditional format)
|
237
|
+
- A Pydantic BaseModel class (automatically converted to JSON schema)
|
238
|
+
Used to enable JSON mode or other structured outputs. Defaults to None.
|
174
239
|
api_version (str, optional): The API version to use. Defaults to API_VERSION.
|
175
240
|
|
176
241
|
Returns:
|
@@ -198,11 +263,31 @@ class UiPathOpenAIService(BaseService):
|
|
198
263
|
max_tokens=200,
|
199
264
|
temperature=0.3
|
200
265
|
)
|
266
|
+
|
267
|
+
# Using Pydantic model for structured response
|
268
|
+
from pydantic import BaseModel
|
269
|
+
from typing import List
|
270
|
+
|
271
|
+
class Country(BaseModel):
|
272
|
+
name: str
|
273
|
+
capital: str
|
274
|
+
languages: List[str]
|
275
|
+
|
276
|
+
response = await service.chat_completions(
|
277
|
+
messages=[
|
278
|
+
{"role": "system", "content": "You are a helpful assistant. Respond with structured JSON."},
|
279
|
+
{"role": "user", "content": "Tell me about Canada."}
|
280
|
+
],
|
281
|
+
response_format=Country, # Pass BaseModel directly
|
282
|
+
max_tokens=1000
|
283
|
+
)
|
201
284
|
```
|
202
285
|
|
203
286
|
Note:
|
204
287
|
The conversation history can be included to provide context to the model.
|
205
288
|
Each message should have both 'role' and 'content' keys.
|
289
|
+
When using a Pydantic BaseModel as response_format, it will be automatically
|
290
|
+
converted to the appropriate JSON schema format for the LLM Gateway.
|
206
291
|
"""
|
207
292
|
endpoint = EndpointManager.get_passthrough_endpoint().format(
|
208
293
|
model=model, api_version=api_version
|
@@ -215,9 +300,24 @@ class UiPathOpenAIService(BaseService):
|
|
215
300
|
"temperature": temperature,
|
216
301
|
}
|
217
302
|
|
218
|
-
#
|
303
|
+
# Handle response_format - convert BaseModel to schema if needed
|
219
304
|
if response_format:
|
220
|
-
|
305
|
+
if isinstance(response_format, type) and issubclass(
|
306
|
+
response_format, BaseModel
|
307
|
+
):
|
308
|
+
# Convert Pydantic model to JSON schema format
|
309
|
+
cleaned_schema = _cleanup_schema(response_format)
|
310
|
+
request_body["response_format"] = {
|
311
|
+
"type": "json_schema",
|
312
|
+
"json_schema": {
|
313
|
+
"name": response_format.__name__.lower(),
|
314
|
+
"strict": True,
|
315
|
+
"schema": cleaned_schema,
|
316
|
+
},
|
317
|
+
}
|
318
|
+
else:
|
319
|
+
# Use provided dictionary format directly
|
320
|
+
request_body["response_format"] = response_format
|
221
321
|
|
222
322
|
response = await self.request_async(
|
223
323
|
"POST",
|
@@ -258,7 +358,7 @@ class UiPathLlmChatService(BaseService):
|
|
258
358
|
top_p: float = 1,
|
259
359
|
tools: Optional[List[ToolDefinition]] = None,
|
260
360
|
tool_choice: Optional[ToolChoice] = None,
|
261
|
-
response_format: Optional[Dict[str, Any]] = None,
|
361
|
+
response_format: Optional[Union[Dict[str, Any], type[BaseModel]]] = None,
|
262
362
|
api_version: str = NORMALIZED_API_VERSION,
|
263
363
|
):
|
264
364
|
"""Generate chat completions using UiPath's normalized LLM Gateway API.
|
@@ -295,9 +395,11 @@ class UiPathLlmChatService(BaseService):
|
|
295
395
|
tool_choice (Optional[ToolChoice], optional): Controls which tools the model can call.
|
296
396
|
Can be "auto" (model decides), "none" (no tools), or a specific tool choice.
|
297
397
|
Defaults to None.
|
298
|
-
response_format (Optional[Dict[str, Any]], optional):
|
299
|
-
that the model must output.
|
300
|
-
|
398
|
+
response_format (Optional[Union[Dict[str, Any], type[BaseModel]]], optional):
|
399
|
+
An object specifying the format that the model must output. Can be either:
|
400
|
+
- A dictionary with response format configuration (traditional format)
|
401
|
+
- A Pydantic BaseModel class (automatically converted to JSON schema)
|
402
|
+
Used to enable JSON mode or other structured outputs. Defaults to None.
|
301
403
|
api_version (str, optional): The normalized API version to use.
|
302
404
|
Defaults to NORMALIZED_API_VERSION.
|
303
405
|
|
@@ -349,6 +451,25 @@ class UiPathLlmChatService(BaseService):
|
|
349
451
|
presence_penalty=0.2,
|
350
452
|
n=3 # Generate 3 alternative responses
|
351
453
|
)
|
454
|
+
|
455
|
+
# Using Pydantic model for structured response
|
456
|
+
from pydantic import BaseModel
|
457
|
+
from typing import List
|
458
|
+
|
459
|
+
class Country(BaseModel):
|
460
|
+
name: str
|
461
|
+
capital: str
|
462
|
+
languages: List[str]
|
463
|
+
|
464
|
+
response = await service.chat_completions(
|
465
|
+
messages=[
|
466
|
+
{"role": "system", "content": "You are a helpful assistant. Respond with structured JSON."},
|
467
|
+
{"role": "user", "content": "Tell me about Canada."}
|
468
|
+
],
|
469
|
+
response_format=Country, # Pass BaseModel directly
|
470
|
+
max_tokens=1000
|
471
|
+
)
|
472
|
+
)
|
352
473
|
```
|
353
474
|
|
354
475
|
Note:
|
@@ -370,9 +491,24 @@ class UiPathLlmChatService(BaseService):
|
|
370
491
|
"top_p": top_p,
|
371
492
|
}
|
372
493
|
|
373
|
-
#
|
494
|
+
# Handle response_format - convert BaseModel to schema if needed
|
374
495
|
if response_format:
|
375
|
-
|
496
|
+
if isinstance(response_format, type) and issubclass(
|
497
|
+
response_format, BaseModel
|
498
|
+
):
|
499
|
+
# Convert Pydantic model to JSON schema format
|
500
|
+
cleaned_schema = _cleanup_schema(response_format)
|
501
|
+
request_body["response_format"] = {
|
502
|
+
"type": "json_schema",
|
503
|
+
"json_schema": {
|
504
|
+
"name": response_format.__name__.lower(),
|
505
|
+
"strict": True,
|
506
|
+
"schema": cleaned_schema,
|
507
|
+
},
|
508
|
+
}
|
509
|
+
else:
|
510
|
+
# Use provided dictionary format directly
|
511
|
+
request_body["response_format"] = response_format
|
376
512
|
|
377
513
|
# Add tools if provided - convert to UiPath format
|
378
514
|
if tools:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: uipath
|
3
|
-
Version: 2.1.
|
3
|
+
Version: 2.1.6
|
4
4
|
Summary: Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools.
|
5
5
|
Project-URL: Homepage, https://uipath.com
|
6
6
|
Project-URL: Repository, https://github.com/UiPath/uipath-python
|
@@ -60,7 +60,7 @@ uipath/_services/connections_service.py,sha256=qh-HNL_GJsyPUD0wSJZRF8ZdrTE9l4HrI
|
|
60
60
|
uipath/_services/context_grounding_service.py,sha256=EBf7lIIYz_s1ubf_07OAZXQHjS8kpZ2vqxo4mI3VL-A,25009
|
61
61
|
uipath/_services/folder_service.py,sha256=9JqgjKhWD-G_KUnfUTP2BADxL6OK9QNZsBsWZHAULdE,2749
|
62
62
|
uipath/_services/jobs_service.py,sha256=CnDd7BM4AMqcMIR1qqu5ohhxf9m0AF4dnGoF4EX38kw,30872
|
63
|
-
uipath/_services/llm_gateway_service.py,sha256=
|
63
|
+
uipath/_services/llm_gateway_service.py,sha256=TZDxpd99K9IT1QeyNle5994lGeGfQRWj1icTXB6zBOY,24300
|
64
64
|
uipath/_services/processes_service.py,sha256=Pk6paw7e_a-WvVcfKDLuyj1p--pvNRTXwZNYIwDdYzo,5726
|
65
65
|
uipath/_services/queues_service.py,sha256=VaG3dWL2QK6AJBOLoW2NQTpkPfZjsqsYPl9-kfXPFzA,13534
|
66
66
|
uipath/_utils/__init__.py,sha256=VdcpnENJIa0R6Y26NoxY64-wUVyvb4pKfTh1wXDQeMk,526
|
@@ -99,8 +99,8 @@ uipath/tracing/_traced.py,sha256=qeVDrds2OUnpdUIA0RhtF0kg2dlAZhyC1RRkI-qivTM,185
|
|
99
99
|
uipath/tracing/_utils.py,sha256=ZeensQexnw69jVcsVrGyED7mPlAU-L1agDGm6_1A3oc,10388
|
100
100
|
uipath/utils/__init__.py,sha256=VD-KXFpF_oWexFg6zyiWMkxl2HM4hYJMIUDZ1UEtGx0,105
|
101
101
|
uipath/utils/_endpoints_manager.py,sha256=hiGEu6vyfQJoeiiql6w21TNiG6tADUfXlVBimxPU1-Q,4160
|
102
|
-
uipath-2.1.
|
103
|
-
uipath-2.1.
|
104
|
-
uipath-2.1.
|
105
|
-
uipath-2.1.
|
106
|
-
uipath-2.1.
|
102
|
+
uipath-2.1.6.dist-info/METADATA,sha256=kc-2b_9OI9fOEfr3hnwPnnM8B4QAQjeiHM3-HZQgT-0,6366
|
103
|
+
uipath-2.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
104
|
+
uipath-2.1.6.dist-info/entry_points.txt,sha256=9C2_29U6Oq1ExFu7usihR-dnfIVNSKc-0EFbh0rskB4,43
|
105
|
+
uipath-2.1.6.dist-info/licenses/LICENSE,sha256=-KBavWXepyDjimmzH5fVAsi-6jNVpIKFc2kZs0Ri4ng,1058
|
106
|
+
uipath-2.1.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|