Skip to content

Commit aa965f7

Browse files
committed
fix: uipath new
1 parent 058d224 commit aa965f7

6 files changed

Lines changed: 144 additions & 86 deletions

File tree

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
"""UiPath OpenAI Agents SDK."""
1+
"""
2+
UiPath OpenAI Agents SDK.
3+
4+
NOTE: This module uses lazy imports via __getattr__ to avoid loading heavy
5+
dependencies (openai SDK) at import time. This significantly improves CLI
6+
startup performance.
7+
8+
Do NOT add eager imports like:
9+
from .chat import UiPathChatOpenAI # BAD - loads openai SDK immediately
10+
11+
Instead, all exports are loaded on-demand when first accessed.
12+
"""
13+
14+
15+
def __getattr__(name):
16+
if name == "UiPathChatOpenAI":
17+
from .chat import UiPathChatOpenAI
18+
19+
return UiPathChatOpenAI
20+
if name == "register_middleware":
21+
from .middlewares import register_middleware
22+
23+
return register_middleware
24+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
225

3-
from .chat import UiPathChatOpenAI
4-
from .middlewares import register_middleware
526

627
__version__ = "0.1.0"
728
__all__ = ["register_middleware", "UiPathChatOpenAI"]
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from agents import Agent
2-
from openai import OpenAI
1+
from agents import Agent, function_tool
2+
from agents.models import _openai_shared
33

4+
from uipath_openai_agents.chat import UiPathChatOpenAI
5+
from uipath_openai_agents.chat.supported_models import OpenAIModels
46

7+
8+
@function_tool
59
def get_weather(location: str) -> str:
610
"""Get the current weather for a location.
711

@@ -12,17 +16,19 @@ def get_weather(location: str) -> str:
1216
Weather information for the location
1317
"""
1418
# This is a mock implementation
15-
return f"The weather in {location} is sunny and 72�F"
19+
return f"The weather in {location} is sunny and 32 degrees Celsius."
20+
1621

22+
MODEL = OpenAIModels.gpt_5_2_2025_12_11
1723

18-
# Initialize the OpenAI client
19-
client = OpenAI()
24+
# Initialize the UiPath OpenAI client
25+
uipath_openai_client = UiPathChatOpenAI(model_name=MODEL)
26+
_openai_shared.set_default_openai_client(uipath_openai_client.async_client)
2027

2128
# Create an agent with tools
2229
agent = Agent(
2330
name="weather_agent",
2431
instructions="You are a helpful weather assistant. Use the get_weather tool to provide weather information.",
25-
model="gpt-4o-mini",
32+
model=MODEL,
2633
tools=[get_weather],
27-
client=client,
2834
)

packages/uipath-openai-agents/src/uipath_openai_agents/_cli/cli_new.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def generate_pyproject(target_directory, project_name):
3939
description = "{project_name}"
4040
authors = [{{ name = "John Doe", email = "john.doe@myemail.com" }}]
4141
dependencies = [
42-
"uipath-openai-agents>=0.1.0",
43-
"openai>=1.0.0"
42+
"uipath-openai-agents>=0.0.1, <0.1.0",
4443
]
4544
requires-python = ">=3.11"
4645
"""
@@ -63,9 +62,6 @@ def openai_agents_new_middleware(name: str) -> MiddlewareResult:
6362
console.success("Created 'AGENTS.md' file.")
6463
generate_pyproject(directory, name)
6564
console.success("Created 'pyproject.toml' file.")
66-
console.config(
67-
f""" Please ensure to define {click.style("OPENAI_API_KEY", fg="bright_yellow")} in your .env file. """
68-
)
6965
init_command = """uipath init"""
7066
run_command = """uipath run agent '{"message": "What is the weather in San Francisco?"}'"""
7167
console.hint(
Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
1-
"""UiPath OpenAI Chat models."""
1+
"""
2+
UiPath OpenAI Chat module.
23
3-
from .openai import UiPathChatOpenAI
4+
NOTE: This module uses lazy imports via __getattr__ to avoid loading heavy
5+
dependencies (openai SDK, httpx) at import time. This significantly
6+
improves CLI startup performance.
47
5-
__all__ = ["UiPathChatOpenAI"]
8+
Do NOT add eager imports like:
9+
from .openai import UiPathChatOpenAI # BAD - loads openai SDK immediately
10+
11+
Instead, all exports are loaded on-demand when first accessed.
12+
"""
13+
14+
15+
def __getattr__(name):
16+
if name == "UiPathChatOpenAI":
17+
from .openai import UiPathChatOpenAI
18+
19+
return UiPathChatOpenAI
20+
if name in ("OpenAIModels", "GeminiModels", "BedrockModels"):
21+
from . import supported_models
22+
23+
return getattr(supported_models, name)
24+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
25+
26+
27+
__all__ = [
28+
"UiPathChatOpenAI",
29+
"OpenAIModels",
30+
"GeminiModels",
31+
"BedrockModels",
32+
]
Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,60 @@
1-
"""Supported OpenAI model definitions for UiPath LLM Gateway."""
1+
"""Supported model definitions for UiPath LLM Gateway.
22
3+
OpenAI Agents SDK supports other LLM providers (Bedrock, Gemini, etc.)
4+
through LiteLLM integration, so we provide model definitions for all supported providers.
5+
"""
36

4-
class OpenAIModels:
5-
"""OpenAI model names supported by UiPath LLM Gateway.
7+
from enum import StrEnum
68

7-
These are specific model versions required by UiPath.
8-
Generic names like "gpt-4o" are not supported - use specific versions.
9-
"""
109

11-
# GPT-4o Models (recommended)
12-
gpt_4o_2024_11_20 = "gpt-4o-2024-11-20"
13-
gpt_4o_2024_08_06 = "gpt-4o-2024-08-06"
10+
class OpenAIModels(StrEnum):
11+
"""Supported OpenAI model identifiers."""
12+
13+
# GPT-4o models
1414
gpt_4o_2024_05_13 = "gpt-4o-2024-05-13"
15+
gpt_4o_2024_08_06 = "gpt-4o-2024-08-06"
16+
gpt_4o_2024_11_20 = "gpt-4o-2024-11-20"
1517
gpt_4o_mini_2024_07_18 = "gpt-4o-mini-2024-07-18"
1618

17-
# GPT-4.1 Models
19+
# GPT-4.1 models
1820
gpt_4_1_2025_04_14 = "gpt-4.1-2025-04-14"
1921
gpt_4_1_mini_2025_04_14 = "gpt-4.1-mini-2025-04-14"
2022
gpt_4_1_nano_2025_04_14 = "gpt-4.1-nano-2025-04-14"
2123

22-
# GPT-4 Models
23-
gpt_4 = "gpt-4"
24-
gpt_4_32k = "gpt-4-32k"
25-
gpt_4_turbo_2024_04_09 = "gpt-4-turbo-2024-04-09"
26-
gpt_4_1106_preview = "gpt-4-1106-Preview"
27-
gpt_4_vision_preview = "gpt-4-vision-preview"
28-
29-
# GPT-3.5 Models
30-
gpt_35_turbo = "gpt-35-turbo"
31-
gpt_35_turbo_0125 = "gpt-35-turbo-0125"
32-
gpt_35_turbo_1106 = "gpt-35-turbo-1106"
33-
gpt_35_turbo_16k = "gpt-35-turbo-16k"
34-
35-
# GPT-5 Models
24+
# GPT-5 models
3625
gpt_5_2025_08_07 = "gpt-5-2025-08-07"
3726
gpt_5_chat_2025_08_07 = "gpt-5-chat-2025-08-07"
3827
gpt_5_mini_2025_08_07 = "gpt-5-mini-2025-08-07"
3928
gpt_5_nano_2025_08_07 = "gpt-5-nano-2025-08-07"
29+
30+
# GPT-5.1 models
4031
gpt_5_1_2025_11_13 = "gpt-5.1-2025-11-13"
32+
33+
# GPT-5.2 models
4134
gpt_5_2_2025_12_11 = "gpt-5.2-2025-12-11"
4235

43-
# o3 Models
44-
o3_mini_2025_01_31 = "o3-mini-2025-01-31"
45-
46-
# Other Models
47-
computer_use_preview_2025_03_11 = "computer-use-preview-2025-03-11"
48-
text_davinci_003 = "text-davinci-003"
49-
50-
# Embedding Models
51-
text_embedding_3_large = "text-embedding-3-large"
52-
text_embedding_3_large_community_ecs = "text-embedding-3-large-community-ecs"
53-
text_embedding_ada_002 = "text-embedding-ada-002"
54-
55-
# Model aliases - maps generic names to specific versions
56-
MODEL_ALIASES = {
57-
# Map gpt-4.1 variants to gpt-4o (most capable available model)
58-
"gpt-4.1": gpt_4o_2024_11_20,
59-
"gpt-4.1-mini": gpt_4o_mini_2024_07_18,
60-
"gpt-4.1-nano": gpt_4o_mini_2024_07_18,
61-
"gpt-4.1-2025-04-14": gpt_4o_2024_11_20, # Map invalid model to valid one
62-
"gpt-4.1-mini-2025-04-14": gpt_4o_mini_2024_07_18,
63-
"gpt-4.1-nano-2025-04-14": gpt_4o_mini_2024_07_18,
64-
# Generic model mappings
65-
"gpt-4o": gpt_4o_2024_11_20,
66-
"gpt-4o-mini": gpt_4o_mini_2024_07_18,
67-
"gpt-5": gpt_5_2025_08_07,
68-
"gpt-5-mini": gpt_5_mini_2025_08_07,
69-
"gpt-5-nano": gpt_5_nano_2025_08_07,
70-
"gpt-5.1": gpt_5_1_2025_11_13,
71-
"gpt-5.2": gpt_5_2_2025_12_11,
72-
"o3-mini": o3_mini_2025_01_31,
73-
}
74-
75-
@classmethod
76-
def normalize_model_name(cls, model_name: str) -> str:
77-
"""Normalize a model name to UiPath-specific version."""
78-
return cls.MODEL_ALIASES.get(model_name, model_name)
36+
37+
class GeminiModels(StrEnum):
38+
"""Supported Google Gemini model identifiers."""
39+
40+
# Gemini 2 models
41+
gemini_2_5_pro = "gemini-2.5-pro"
42+
gemini_2_5_flash = "gemini-2.5-flash"
43+
gemini_2_0_flash_001 = "gemini-2.0-flash-001"
44+
45+
# Gemini 3 models
46+
gemini_3_pro_preview = "gemini-3-pro-preview"
47+
48+
49+
class BedrockModels(StrEnum):
50+
"""Supported AWS Bedrock model identifiers."""
51+
52+
# Claude 3.7 models
53+
anthropic_claude_3_7_sonnet = "anthropic.claude-3-7-sonnet-20250219-v1:0"
54+
55+
# Claude 4 models
56+
anthropic_claude_sonnet_4 = "anthropic.claude-sonnet-4-20250514-v1:0"
57+
58+
# Claude 4.5 models
59+
anthropic_claude_sonnet_4_5 = "anthropic.claude-sonnet-4-5-20250929-v1:0"
60+
anthropic_claude_haiku_4_5 = "anthropic.claude-haiku-4-5-20251001-v1:0"

packages/uipath-openai-agents/src/uipath_openai_agents/runtime/__init__.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
"""UiPath OpenAI Agents Runtime."""
1+
"""
2+
UiPath OpenAI Agents Runtime.
3+
4+
NOTE: This module uses lazy imports for most exports to avoid loading heavy
5+
dependencies (openai SDK) at import time. However, the runtime factory
6+
registration must happen eagerly for CLI discovery.
7+
"""
28

39
from uipath.runtime import (
410
UiPathRuntimeContext,
511
UiPathRuntimeFactoryProtocol,
612
UiPathRuntimeFactoryRegistry,
713
)
814

9-
from uipath_openai_agents.runtime.factory import UiPathOpenAIAgentRuntimeFactory
10-
from uipath_openai_agents.runtime.runtime import UiPathOpenAIAgentRuntime
11-
from uipath_openai_agents.runtime.schema import (
12-
get_agent_schema,
13-
get_entrypoints_schema,
14-
)
15-
1615

1716
def register_runtime_factory() -> None:
1817
"""Register the OpenAI Agents factory. Called automatically via entry point."""
1918

2019
def create_factory(
2120
context: UiPathRuntimeContext | None = None,
2221
) -> UiPathRuntimeFactoryProtocol:
22+
# Import lazily when factory is actually created
23+
from uipath_openai_agents.runtime.factory import (
24+
UiPathOpenAIAgentRuntimeFactory,
25+
)
26+
2327
return UiPathOpenAIAgentRuntimeFactory(
2428
context=context if context else UiPathRuntimeContext(),
2529
)
@@ -29,8 +33,30 @@ def create_factory(
2933
)
3034

3135

36+
# Register factory eagerly (required for CLI discovery)
3237
register_runtime_factory()
3338

39+
40+
def __getattr__(name):
41+
if name == "get_entrypoints_schema":
42+
from .schema import get_entrypoints_schema
43+
44+
return get_entrypoints_schema
45+
if name == "get_agent_schema":
46+
from .schema import get_agent_schema
47+
48+
return get_agent_schema
49+
if name == "UiPathOpenAIAgentRuntimeFactory":
50+
from .factory import UiPathOpenAIAgentRuntimeFactory
51+
52+
return UiPathOpenAIAgentRuntimeFactory
53+
if name == "UiPathOpenAIAgentRuntime":
54+
from .runtime import UiPathOpenAIAgentRuntime
55+
56+
return UiPathOpenAIAgentRuntime
57+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
58+
59+
3460
__all__ = [
3561
"register_runtime_factory",
3662
"get_entrypoints_schema",

0 commit comments

Comments
 (0)