Skip to content

Commit 7ffcd26

Browse files
committed
fix(response_format): added role mapping + changed default serialization
1 parent c4551b2 commit 7ffcd26

File tree

4 files changed

+433
-324
lines changed

4 files changed

+433
-324
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.1.73"
3+
version = "2.1.74"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath/_services/llm_gateway_service.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def __init__(self, config: Config, execution_context: ExecutionContext) -> None:
344344
@traced(name="llm_chat_completions", run_type="uipath")
345345
async def chat_completions(
346346
self,
347-
messages: List[Dict[str, str]],
347+
messages: Union[List[Dict[str, str]], List[tuple[str, str]]],
348348
model: str = ChatModels.gpt_4o_mini_2024_07_18,
349349
max_tokens: int = 4096,
350350
temperature: float = 0,
@@ -472,13 +472,30 @@ class Country(BaseModel):
472472
This service uses UiPath's normalized API format which provides consistent
473473
behavior across different underlying model providers and enhanced enterprise features.
474474
"""
475+
role_mapping = {"human": "user", "ai": "assistant"}
476+
converted_messages = []
477+
478+
for message in messages:
479+
if isinstance(message, tuple) and len(message) == 2:
480+
role, content = message
481+
mapped_role = role_mapping.get(role.lower(), role)
482+
converted_messages.append({"role": mapped_role, "content": content})
483+
elif isinstance(message, dict):
484+
role = message.get("role", "")
485+
mapped_role = role_mapping.get(role.lower(), role)
486+
converted_messages.append({**message, "role": mapped_role})
487+
else:
488+
raise ValueError(
489+
f"Invalid message format: {message}. Expected tuple (role, content) or dict with 'role' and 'content' keys."
490+
)
491+
475492
endpoint = EndpointManager.get_normalized_endpoint().format(
476493
model=model, api_version=api_version
477494
)
478495
endpoint = Endpoint("/" + endpoint)
479496

480497
request_body = {
481-
"messages": messages,
498+
"messages": converted_messages,
482499
"max_tokens": max_tokens,
483500
"temperature": temperature,
484501
"n": n,

0 commit comments

Comments
 (0)