Skip to content

Commit c30a320

Browse files
feat: map user messages
1 parent ae2c145 commit c30a320

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

packages/uipath-llamaindex/src/uipath_llamaindex/runtime/chat/messages.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from datetime import datetime, timezone
3+
from typing import Any
34
from uuid import uuid4
45

56
from llama_index.core.agent.workflow.workflow_events import (
@@ -40,6 +41,38 @@ def __init__(self, runtime_id: str) -> None:
4041
# tool_id -> message_id for correlating ToolCallResult with its parent AI message
4142
self._tool_id_to_message_id: dict[str, str] = {}
4243

44+
@staticmethod
45+
def map_input(input: dict[str, Any]) -> dict[str, Any]:
46+
"""Map UiPath chat message format to LlamaIndex expected format.
47+
48+
If the input already has 'user_msg', return it unchanged.
49+
If the input has a 'messages' array (UiPath chat format), extract the
50+
text content from the first message's contentParts and map it to
51+
'user_msg'.
52+
"""
53+
if "user_msg" in input:
54+
return input
55+
56+
messages = input.get("messages")
57+
if not messages or not isinstance(messages, list):
58+
return input
59+
60+
first_message = messages[0]
61+
content_parts = first_message.get("contentParts", [])
62+
63+
text_parts = [
64+
part["data"]["inline"]
65+
for part in content_parts
66+
if part.get("mimeType") == "text/plain"
67+
and isinstance(part.get("data"), dict)
68+
and part["data"].get("inline")
69+
]
70+
71+
if text_parts:
72+
return {"user_msg": " ".join(text_parts)}
73+
74+
return input
75+
4376
def get_timestamp(self) -> str:
4477
"""Format current time as ISO 8601 UTC with milliseconds: 2025-01-04T10:30:00.123Z"""
4578
return (

packages/uipath-llamaindex/src/uipath_llamaindex/runtime/runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def _run_workflow(
140140
"""
141141
Core workflow execution logic used by both execute() and stream().
142142
"""
143-
workflow_input = input or {}
143+
workflow_input = UiPathChatMessagesMapper.map_input(input or {})
144144
is_resuming = bool(options and options.resume)
145145

146146
if is_resuming:

0 commit comments

Comments
 (0)