Skip to content

feat(cli): enhance init with options #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-llamaindex"
version = "0.0.26"
version = "0.0.27"
description = "UiPath LlamaIndex SDK"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.10"
Expand All @@ -9,7 +9,7 @@ dependencies = [
"llama-index-embeddings-azure-openai>=0.3.8",
"llama-index-llms-azure-openai>=0.3.2",
"openinference-instrumentation-llama-index>=4.3.0",
"uipath>=2.0.65, <2.1.0",
"uipath>=2.0.71, <2.1.0",
]
classifiers = [
"Development Status :: 3 - Alpha",
Expand Down
46 changes: 37 additions & 9 deletions src/uipath_llamaindex/_cli/cli_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import os
import uuid
from typing import Any, Dict
from typing import Any, Callable, Dict, overload

from llama_index.core.workflow import StopEvent, Workflow
from llama_index.core.workflow.drawing import StepConfig # type: ignore
Expand Down Expand Up @@ -284,8 +284,14 @@ def get_event_style(event_type) -> str:
return "defaultEventStyle"


async def llamaindex_init_middleware_async(entrypoint: str) -> MiddlewareResult:
async def llamaindex_init_middleware_async(
entrypoint: str,
options: dict[str, Any] | None = None,
write_config: Callable[[Any], str] | None = None,
) -> MiddlewareResult:
"""Middleware to check for llama_index.json and create uipath.json with schemas"""
options = options or {}

config = LlamaIndexConfig()
if not config.exists:
return MiddlewareResult(
Expand All @@ -305,8 +311,9 @@ async def llamaindex_init_middleware_async(entrypoint: str) -> MiddlewareResult:
loaded_workflow = await workflow.load_workflow()
schema = generate_schema_from_workflow(loaded_workflow)
try:
should_infer_bindings = options.get("infer_bindings", True)
# Make sure the file path exists
if os.path.exists(workflow.file_path):
if os.path.exists(workflow.file_path) and should_infer_bindings:
file_bindings = generate_bindings_json(workflow.file_path)
# Merge bindings
if "resources" in file_bindings:
Expand Down Expand Up @@ -345,10 +352,13 @@ async def llamaindex_init_middleware_async(entrypoint: str) -> MiddlewareResult:

uipath_config = {"entryPoints": entrypoints, "bindings": all_bindings}

# Save the uipath.json file
config_path = "uipath.json"
with open(config_path, "w") as f:
json.dump(uipath_config, f, indent=2)
if write_config:
config_path = write_config(uipath_config)
else:
# Save the uipath.json file
config_path = "uipath.json"
with open(config_path, "w") as f:
json.dump(uipath_config, f, indent=4)

console.success(f" Created '{config_path}' file.")
return MiddlewareResult(should_continue=False)
Expand All @@ -361,6 +371,24 @@ async def llamaindex_init_middleware_async(entrypoint: str) -> MiddlewareResult:
)


def llamaindex_init_middleware(entrypoint: str) -> MiddlewareResult:
@overload
def llamaindex_init_middleware(entrypoint: str) -> MiddlewareResult: ...


@overload
def llamaindex_init_middleware(
entrypoint: str,
options: dict[str, Any],
write_config: Callable[[Any], str],
) -> MiddlewareResult: ...


def llamaindex_init_middleware(
entrypoint: str,
options: dict[str, Any] | None = None,
write_config: Callable[[Any], str] | None = None,
) -> MiddlewareResult:
"""Middleware to check for llama_index.json and create uipath.json with schemas"""
return asyncio.run(llamaindex_init_middleware_async(entrypoint))
return asyncio.run(
llamaindex_init_middleware_async(entrypoint, options, write_config)
)
Loading