Skip to content

Commit 32be775

Browse files
authored
Merge pull request #5 from UiPath/fix/run_workflow
Basic uipath run implementation
2 parents 1c609d7 + c9c663a commit 32be775

4 files changed

Lines changed: 42 additions & 11 deletions

File tree

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-llamaindex"
3-
version = "0.0.2"
3+
version = "0.0.3"
44
description = "UiPath LlamaIndex SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath_llamaindex/_cli/_runtime/_runtime.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ async def execute(self) -> Optional[UiPathRuntimeResult]:
3434
Dictionary with execution results
3535
3636
Raises:
37-
UiPathLlamaRuntimeError: If execution fails
37+
UiPathLlamaIndexRuntimeError: If execution fails
3838
"""
3939
await self.validate()
4040

4141
try:
42-
a = 2
42+
output = await self.context.workflow.run(self.context.input_json)
43+
44+
self.context.result = UiPathRuntimeResult(
45+
output=self._serialize_object(output)
46+
)
47+
48+
return self.context.result
4349

4450
except Exception as e:
4551
if isinstance(e, UiPathLlamaIndexRuntimeError):
@@ -98,17 +104,17 @@ async def validate(self) -> None:
98104
UiPathErrorCategory.DEPLOYMENT,
99105
)
100106

101-
# Get the specified graph
102-
self.graph_config = self.context.config.get_workflow(self.context.entrypoint)
103-
if not self.graph_config:
107+
# Get the specified workflow configuration
108+
self.workflow_config = self.context.config.get_workflow(self.context.entrypoint)
109+
if not self.workflow_config:
104110
raise UiPathLlamaIndexRuntimeError(
105111
"WORKFLOW_NOT_FOUND",
106112
"Workflow not found",
107113
f"Workflow '{self.context.entrypoint}' not found.",
108114
UiPathErrorCategory.DEPLOYMENT,
109115
)
110116
try:
111-
self.context.workflow = await self.graph_config.load_workflow()
117+
self.context.workflow = await self.workflow_config.load_workflow()
112118
except ImportError as e:
113119
raise UiPathLlamaIndexRuntimeError(
114120
"WORKFLOW_IMPORT_ERROR",
@@ -120,7 +126,7 @@ async def validate(self) -> None:
120126
raise UiPathLlamaIndexRuntimeError(
121127
"WORKFLOW_TYPE_ERROR",
122128
"Invalid workflow type",
123-
f"Workflow '{self.context.entrypoint}' is not a valid Workflow: {str(e)}",
129+
f"Workflow '{self.context.entrypoint}' is not a valid `Workflow`: {str(e)}",
124130
UiPathErrorCategory.USER,
125131
) from e
126132
except ValueError as e:
@@ -141,3 +147,28 @@ async def validate(self) -> None:
141147
async def cleanup(self) -> None:
142148
"""Clean up all resources."""
143149
pass
150+
151+
def _serialize_object(self, obj):
152+
"""Recursively serializes an object and all its nested components."""
153+
# Handle Pydantic models
154+
if hasattr(obj, "dict"):
155+
return self._serialize_object(obj.dict())
156+
elif hasattr(obj, "model_dump"):
157+
return self._serialize_object(obj.model_dump(by_alias=True))
158+
elif hasattr(obj, "to_dict"):
159+
return self._serialize_object(obj.to_dict())
160+
# Handle dictionaries
161+
elif isinstance(obj, dict):
162+
return {k: self._serialize_object(v) for k, v in obj.items()}
163+
# Handle lists
164+
elif isinstance(obj, list):
165+
return [self._serialize_object(item) for item in obj]
166+
# Handle other iterable objects (convert to dict first)
167+
elif hasattr(obj, "__iter__") and not isinstance(obj, (str, bytes)):
168+
try:
169+
return self._serialize_object(dict(obj))
170+
except (TypeError, ValueError):
171+
return obj
172+
# Return primitive types as is
173+
else:
174+
return obj

src/uipath_llamaindex/_cli/cli_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def generate_schema_from_workflow(workflow: Workflow) -> Dict[str, Any]:
115115
# For output schema, check if it's the base StopEvent or a custom subclass
116116
if stop_event_class is StopEvent:
117117
# For base StopEvent, just use Any type for the result
118-
schema["output"] = {"type": "object", "properties": {}}
118+
schema["output"] = {"type": "object", "properties": {}, "required": []}
119119
else:
120120
# For custom StopEvent subclasses, extract their Pydantic schema
121121
try:

src/uipath_llamaindex/_cli/cli_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def llamaindex_run_middleware(
2525
if not config.exists:
2626
return MiddlewareResult(
2727
should_continue=True
28-
) # Continue with normal flow if no llama.json
28+
) # Continue with normal flow if no llama_index.json
2929

3030
try:
3131

@@ -54,7 +54,7 @@ async def execute():
5454
)
5555

5656
env["UIPATH_REQUESTING_PRODUCT"] = "uipath-python-sdk"
57-
env["UIPATH_REQUESTING_FEATURE"] = "llama"
57+
env["UIPATH_REQUESTING_FEATURE"] = "llamaindex"
5858

5959
async with UiPathLlamaIndexRuntime.from_context(context) as runtime:
6060
await runtime.execute()

0 commit comments

Comments
 (0)