uipath 2.0.74__py3-none-any.whl → 2.0.75__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.

Potentially problematic release.


This version of uipath might be problematic. Click here for more details.

@@ -10,9 +10,9 @@ from ..models.llm_gateway import (
10
10
  TextEmbedding,
11
11
  ToolChoice,
12
12
  ToolDefinition,
13
- UsageInfo,
14
13
  )
15
14
  from ..tracing._traced import traced
15
+ from ..utils import EndpointManager
16
16
  from ._base_service import BaseService
17
17
 
18
18
  # Common constants
@@ -54,36 +54,12 @@ class UiPathOpenAIService(BaseService):
54
54
  def __init__(self, config: Config, execution_context: ExecutionContext) -> None:
55
55
  super().__init__(config=config, execution_context=execution_context)
56
56
 
57
- @traced(name="llm_embeddings_usage", run_type="uipath")
58
- async def embeddings_usage(
59
- self, input: str, embedding_model: str = EmbeddingModels.text_embedding_ada_002
60
- ):
61
- """Embedd the input text using llm gateway service.
62
-
63
- Args:
64
- input (str): The input text to embedd.
65
- embedding_model (str, optional): The embedding model to use. Defaults to text-embedding-ada-002.
66
-
67
- Returns:
68
- EmbeddingUsageInfo: The embedding usage information.
69
- """
70
- endpoint = Endpoint(
71
- f"/llmgateway_/openai/deployments/{embedding_model}/embeddings/usage"
72
- )
73
-
74
- response = await self.request_async(
75
- "POST",
76
- endpoint,
77
- content=json.dumps({"input": input}),
78
- params={"api-version": API_VERSION},
79
- headers=DEFAULT_LLM_HEADERS,
80
- )
81
-
82
- return UsageInfo.model_validate(response.json())
83
-
84
57
  @traced(name="llm_embeddings", run_type="uipath")
85
58
  async def embeddings(
86
- self, input: str, embedding_model: str = EmbeddingModels.text_embedding_ada_002
59
+ self,
60
+ input: str,
61
+ embedding_model: str = EmbeddingModels.text_embedding_ada_002,
62
+ openai_api_version: str = API_VERSION,
87
63
  ):
88
64
  """Embed the input text using llm gateway service.
89
65
 
@@ -93,9 +69,10 @@ class UiPathOpenAIService(BaseService):
93
69
  Returns:
94
70
  TextEmbedding: The embedding response.
95
71
  """
96
- endpoint = Endpoint(
97
- f"/llmgateway_/openai/deployments/{embedding_model}/embeddings"
72
+ endpoint = EndpointManager.get_embeddings_endpoint().format(
73
+ model=embedding_model, api_version=openai_api_version
98
74
  )
75
+ endpoint = Endpoint("/" + endpoint)
99
76
 
100
77
  response = await self.request_async(
101
78
  "POST",
@@ -114,6 +91,7 @@ class UiPathOpenAIService(BaseService):
114
91
  model: str = ChatModels.gpt_4o_mini_2024_07_18,
115
92
  max_tokens: int = 50,
116
93
  temperature: float = 0,
94
+ api_version: str = API_VERSION,
117
95
  ):
118
96
  """Get chat completions using llm gateway service.
119
97
 
@@ -139,59 +117,10 @@ class UiPathOpenAIService(BaseService):
139
117
  Returns:
140
118
  ChatCompletion: The chat completion response.
141
119
  """
142
- endpoint = Endpoint(f"/llmgateway_/openai/deployments/{model}/chat/completions")
143
-
144
- request_body = {
145
- "messages": messages,
146
- "max_tokens": max_tokens,
147
- "temperature": temperature,
148
- }
149
-
150
- response = await self.request_async(
151
- "POST",
152
- endpoint,
153
- content=json.dumps(request_body),
154
- params={"api-version": API_VERSION},
155
- headers=DEFAULT_LLM_HEADERS,
156
- )
157
-
158
- return ChatCompletion.model_validate(response.json())
159
-
160
- @traced(name="llm_chat_completions_usage", run_type="uipath")
161
- async def chat_completions_usage(
162
- self,
163
- messages: List[Dict[str, str]],
164
- model: str = ChatModels.gpt_4o_mini_2024_07_18,
165
- max_tokens: int = 50,
166
- temperature: float = 0,
167
- ):
168
- """Get chat completions usage using llm gateway service.
169
-
170
- Args:
171
- messages (List[Dict[str, str]]): List of message dictionaries with 'role' and 'content' keys.
172
- The supported roles are 'system', 'user', and 'assistant'.
173
-
174
- Example:
175
- ```
176
- [
177
- {"role": "system", "content": "You are a helpful Python programming assistant."},
178
- {"role": "user", "content": "How do I read a file in Python?"},
179
- {"role": "assistant", "content": "You can use the built-in open() function."},
180
- {"role": "user", "content": "Can you show an example?"}
181
- ]
182
- ```
183
- The conversation history can be included to provide context to the model.
184
- model (str, optional): The model to use for chat completion. Defaults to ChatModels.gpt_4o_mini_2024_07_18.
185
- max_tokens (int, optional): Maximum number of tokens to generate. Defaults to 50.
186
- temperature (float, optional): Temperature for sampling, between 0 and 1.
187
- Lower values make output more deterministic. Defaults to 0.
188
-
189
- Returns:
190
- ChatCompletion: The chat completion usage response.
191
- """
192
- endpoint = Endpoint(
193
- f"/llmgateway_/openai/deployments/{model}/chat/completions/usage"
120
+ endpoint = EndpointManager.get_passthrough_endpoint().format(
121
+ model=model, api_version=api_version
194
122
  )
123
+ endpoint = Endpoint("/" + endpoint)
195
124
 
196
125
  request_body = {
197
126
  "messages": messages,
@@ -207,7 +136,7 @@ class UiPathOpenAIService(BaseService):
207
136
  headers=DEFAULT_LLM_HEADERS,
208
137
  )
209
138
 
210
- return UsageInfo.model_validate(response.json())
139
+ return ChatCompletion.model_validate(response.json())
211
140
 
212
141
 
213
142
  class UiPathLlmChatService(BaseService):
@@ -229,6 +158,7 @@ class UiPathLlmChatService(BaseService):
229
158
  top_p: float = 1,
230
159
  tools: Optional[List[ToolDefinition]] = None,
231
160
  tool_choice: Optional[ToolChoice] = None,
161
+ api_version: str = NORMALIZED_API_VERSION,
232
162
  ):
233
163
  """Get chat completions using UiPath's normalized LLM Gateway API.
234
164
 
@@ -250,7 +180,10 @@ class UiPathLlmChatService(BaseService):
250
180
  Returns:
251
181
  ChatCompletion: The chat completion response.
252
182
  """
253
- endpoint = Endpoint("/llmgateway_/api/chat/completions")
183
+ endpoint = EndpointManager.get_normalized_endpoint().format(
184
+ model=model, api_version=api_version
185
+ )
186
+ endpoint = Endpoint("/" + endpoint)
254
187
 
255
188
  request_body = {
256
189
  "messages": messages,
@@ -21,11 +21,6 @@ class TextEmbedding(BaseModel):
21
21
  usage: EmbeddingUsage
22
22
 
23
23
 
24
- class UsageInfo(BaseModel):
25
- encoding: str
26
- prompt_tokens: int
27
-
28
-
29
24
  class ToolCall(BaseModel):
30
25
  id: str
31
26
  name: str
@@ -0,0 +1,5 @@
1
+ from ._endpoints_manager import EndpointManager # noqa: D104
2
+
3
+ __all__ = [
4
+ "EndpointManager",
5
+ ]
@@ -0,0 +1,88 @@
1
+ import logging
2
+ import os
3
+ from enum import Enum
4
+ from typing import Optional
5
+
6
+ import httpx
7
+
8
+ loggger = logging.getLogger(__name__)
9
+
10
+
11
+ class UiPathEndpoints(Enum):
12
+ AH_NORMALIZED_COMPLETION_ENDPOINT = "agenthub_/llm/api/chat/completions"
13
+ AH_PASSTHROUGH_COMPLETION_ENDPOINT = "agenthub_/llm/openai/deployments/{model}/chat/completions?api-version={api_version}"
14
+ AH_EMBEDDING_ENDPOINT = (
15
+ "agenthub_/llm/openai/deployments/{model}/embeddings?api-version={api_version}"
16
+ )
17
+ AH_CAPABILITIES_ENDPOINT = "agenthub_/llm/api/capabilities"
18
+
19
+ NORMALIZED_COMPLETION_ENDPOINT = "llmgateway_/api/chat/completions"
20
+ PASSTHROUGH_COMPLETION_ENDPOINT = "llmgateway_/openai/deployments/{model}/chat/completions?api-version={api_version}"
21
+ EMBEDDING_ENDPOINT = (
22
+ "llmgateway_/openai/deployments/{model}/embeddings?api-version={api_version}"
23
+ )
24
+
25
+
26
+ class EndpointManager:
27
+ """Manages and caches the UiPath endpoints.
28
+ This class provides functionality to determine which UiPath endpoints to use based on
29
+ the availability of AgentHub. It checks for AgentHub capabilities and caches the result
30
+ to avoid repeated network calls.
31
+ Class Attributes:
32
+ _base_url (str): The base URL for UiPath services, retrieved from the UIPATH_URL
33
+ environment variable.
34
+ _agenthub_available (Optional[bool]): Cached result of AgentHub availability check.
35
+
36
+ Methods:
37
+ is_agenthub_available(): Checks if AgentHub is available, caching the result.
38
+ get_passthrough_endpoint(): Returns the appropriate passthrough completion endpoint.
39
+ get_normalized_endpoint(): Returns the appropriate normalized completion endpoint.
40
+ get_embeddings_endpoint(): Returns the appropriate embeddings endpoint.
41
+ All endpoint methods automatically select between AgentHub and standard endpoints
42
+ based on availability.
43
+ """ # noqa: D205
44
+
45
+ _base_url = os.getenv("UIPATH_URL", "")
46
+ _agenthub_available: Optional[bool] = None
47
+
48
+ @classmethod
49
+ def is_agenthub_available(cls) -> bool:
50
+ """Check if AgentHub is available and cache the result."""
51
+ if cls._agenthub_available is None:
52
+ cls._agenthub_available = cls._check_agenthub()
53
+ return cls._agenthub_available
54
+
55
+ @classmethod
56
+ def _check_agenthub(cls) -> bool:
57
+ """Perform the actual check for AgentHub capabilities."""
58
+ try:
59
+ with httpx.Client() as http_client:
60
+ base_url = os.getenv("UIPATH_URL", "")
61
+ capabilities_url = f"{base_url.rstrip('/')}/{UiPathEndpoints.AH_CAPABILITIES_ENDPOINT.value}"
62
+ loggger.debug(f"Checking AgentHub capabilities at {capabilities_url}")
63
+ response = http_client.get(capabilities_url)
64
+ return response.status_code == 200
65
+ except Exception as e:
66
+ loggger.error(f"Error checking AgentHub capabilities: {e}", exc_info=True)
67
+ return False
68
+
69
+ @classmethod
70
+ def get_passthrough_endpoint(cls) -> str:
71
+ if cls.is_agenthub_available():
72
+ return UiPathEndpoints.AH_PASSTHROUGH_COMPLETION_ENDPOINT.value
73
+
74
+ return UiPathEndpoints.PASSTHROUGH_COMPLETION_ENDPOINT.value
75
+
76
+ @classmethod
77
+ def get_normalized_endpoint(cls) -> str:
78
+ if cls.is_agenthub_available():
79
+ return UiPathEndpoints.AH_NORMALIZED_COMPLETION_ENDPOINT.value
80
+
81
+ return UiPathEndpoints.NORMALIZED_COMPLETION_ENDPOINT.value
82
+
83
+ @classmethod
84
+ def get_embeddings_endpoint(cls) -> str:
85
+ if cls.is_agenthub_available():
86
+ return UiPathEndpoints.AH_EMBEDDING_ENDPOINT.value
87
+
88
+ return UiPathEndpoints.EMBEDDING_ENDPOINT.value
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uipath
3
- Version: 2.0.74
3
+ Version: 2.0.75
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
@@ -56,7 +56,7 @@ uipath/_services/connections_service.py,sha256=qh-HNL_GJsyPUD0wSJZRF8ZdrTE9l4HrI
56
56
  uipath/_services/context_grounding_service.py,sha256=EBf7lIIYz_s1ubf_07OAZXQHjS8kpZ2vqxo4mI3VL-A,25009
57
57
  uipath/_services/folder_service.py,sha256=9JqgjKhWD-G_KUnfUTP2BADxL6OK9QNZsBsWZHAULdE,2749
58
58
  uipath/_services/jobs_service.py,sha256=CnDd7BM4AMqcMIR1qqu5ohhxf9m0AF4dnGoF4EX38kw,30872
59
- uipath/_services/llm_gateway_service.py,sha256=ySg3sflIoXmY9K7txlSm7bkuI2qzBT0kAKmGlFBk5KA,12032
59
+ uipath/_services/llm_gateway_service.py,sha256=ZdKRLdEVL8Zkcl9NDT5AKADxnjqeMIuOe5H2Oy7hYKw,9421
60
60
  uipath/_services/processes_service.py,sha256=b-c4ynjcgS0ymp130r0lI93z7DF989u8HWOmWCux754,5727
61
61
  uipath/_services/queues_service.py,sha256=VaG3dWL2QK6AJBOLoW2NQTpkPfZjsqsYPl9-kfXPFzA,13534
62
62
  uipath/_utils/__init__.py,sha256=VdcpnENJIa0R6Y26NoxY64-wUVyvb4pKfTh1wXDQeMk,526
@@ -83,7 +83,7 @@ uipath/models/errors.py,sha256=gPyU4sKYn57v03aOVqm97mnU9Do2e7bwMQwiSQVp9qc,461
83
83
  uipath/models/exceptions.py,sha256=jav4egsVRfC1jN_FLnV7FVgWZapSepSKZQCxMe94Pac,590
84
84
  uipath/models/interrupt_models.py,sha256=UzuVTMVesI204YQ4qFQFaN-gN3kksddkrujofcaC7zQ,881
85
85
  uipath/models/job.py,sha256=f9L6_kg_VP0dAYvdcz1DWEWzy4NZPdlpHREod0uNK1E,3099
86
- uipath/models/llm_gateway.py,sha256=0sl5Wtve94V14H3AHwmJSoXAhoc-Fai3wJxP8HrnBPg,1994
86
+ uipath/models/llm_gateway.py,sha256=rUIus7BrUuuRriXqSJUE9FnjOyQ7pYpaX6hWEYvA6AA,1923
87
87
  uipath/models/processes.py,sha256=Atvfrt6X4TYST3iA62jpS_Uxc3hg6uah11p-RaKZ6dk,2029
88
88
  uipath/models/queues.py,sha256=N_s0GKucbyjh0RnO8SxPk6wlRgvq8KIIYsfaoIY46tM,6446
89
89
  uipath/telemetry/__init__.py,sha256=Wna32UFzZR66D-RzTKlPWlvji9i2HJb82NhHjCCXRjY,61
@@ -93,8 +93,10 @@ uipath/tracing/__init__.py,sha256=GKRINyWdHVrDsI-8mrZDLdf0oey6GHGlNZTOADK-kgc,22
93
93
  uipath/tracing/_otel_exporters.py,sha256=x0PDPmDKJcxashsuehVsSsqBCzRr6WsNFaq_3_HS5F0,3014
94
94
  uipath/tracing/_traced.py,sha256=qeVDrds2OUnpdUIA0RhtF0kg2dlAZhyC1RRkI-qivTM,18528
95
95
  uipath/tracing/_utils.py,sha256=ZeensQexnw69jVcsVrGyED7mPlAU-L1agDGm6_1A3oc,10388
96
- uipath-2.0.74.dist-info/METADATA,sha256=7nWW75xzek2vV6C_UQZiJKFUMFkwdxDP58_y3FYn-n0,6462
97
- uipath-2.0.74.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
98
- uipath-2.0.74.dist-info/entry_points.txt,sha256=9C2_29U6Oq1ExFu7usihR-dnfIVNSKc-0EFbh0rskB4,43
99
- uipath-2.0.74.dist-info/licenses/LICENSE,sha256=-KBavWXepyDjimmzH5fVAsi-6jNVpIKFc2kZs0Ri4ng,1058
100
- uipath-2.0.74.dist-info/RECORD,,
96
+ uipath/utils/__init__.py,sha256=VD-KXFpF_oWexFg6zyiWMkxl2HM4hYJMIUDZ1UEtGx0,105
97
+ uipath/utils/_endpoints_manager.py,sha256=zcOsYwyoRzDuvdhdHwNabrqXRqC6e5J_GdEOriT7Dek,3768
98
+ uipath-2.0.75.dist-info/METADATA,sha256=uAREv1kvwTRpAZSOumymODhJBi_oIWm8uR1Krr1UMM0,6462
99
+ uipath-2.0.75.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
100
+ uipath-2.0.75.dist-info/entry_points.txt,sha256=9C2_29U6Oq1ExFu7usihR-dnfIVNSKc-0EFbh0rskB4,43
101
+ uipath-2.0.75.dist-info/licenses/LICENSE,sha256=-KBavWXepyDjimmzH5fVAsi-6jNVpIKFc2kZs0Ri4ng,1058
102
+ uipath-2.0.75.dist-info/RECORD,,