Skip to content

Commit 2ad1473

Browse files
cosminachoclaude
andcommitted
Refactor: api_flavor as a field on OpenAI/Azure chat models
Follow the same pattern as UiPathChatAnthropic.vendor_type: add an api_flavor field to UiPathChatOpenAI, UiPathAzureChatOpenAI, and UiPathAzureAIChatCompletionsModel. The model_validator sets api_config.api_flavor from the field, and the request hook reads it. The factory now passes api_flavor= directly instead of constructing a full UiPathAPIConfig. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2c47265 commit 2ad1473

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

packages/uipath_langchain_client/src/uipath_langchain_client/clients/azure/chat_models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from uipath_langchain_client.base_client import UiPathBaseChatModel
77
from uipath_langchain_client.clients.openai.utils import fix_url_and_api_flavor_header
88
from uipath_langchain_client.settings import (
9+
ApiFlavor,
910
ApiType,
1011
RoutingMode,
1112
UiPathAPIConfig,
@@ -31,6 +32,7 @@ class UiPathAzureAIChatCompletionsModel(UiPathBaseChatModel, AzureAIOpenAIApiCha
3132
vendor_type=VendorType.AZURE,
3233
freeze_base_url=False,
3334
)
35+
api_flavor: ApiFlavor | str | None = None
3436

3537
# Override fields to avoid env var lookup / validation errors at instantiation
3638
endpoint: str | None = Field(default="PLACEHOLDER")
@@ -40,6 +42,8 @@ class UiPathAzureAIChatCompletionsModel(UiPathBaseChatModel, AzureAIOpenAIApiCha
4042

4143
@model_validator(mode="after")
4244
def setup_uipath_client(self) -> Self:
45+
if self.api_flavor is not None:
46+
self.api_config.api_flavor = self.api_flavor
4347
base_url = str(self.uipath_sync_client.base_url).rstrip("/")
4448
locked_flavor = str(self.api_config.api_flavor) if self.api_config.api_flavor else None
4549

packages/uipath_langchain_client/src/uipath_langchain_client/clients/openai/chat_models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from uipath_langchain_client.base_client import UiPathBaseChatModel
88
from uipath_langchain_client.clients.openai.utils import fix_url_and_api_flavor_header
99
from uipath_langchain_client.settings import (
10+
ApiFlavor,
1011
ApiType,
1112
RoutingMode,
1213
UiPathAPIConfig,
@@ -31,6 +32,7 @@ class UiPathChatOpenAI(UiPathBaseChatModel, ChatOpenAI): # type: ignore[overrid
3132
api_version="2025-03-01-preview",
3233
freeze_base_url=False,
3334
)
35+
api_flavor: ApiFlavor | str | None = None
3436

3537
# Override fields to avoid errors when instantiating the class
3638
openai_api_key: SecretStr | None | Callable[[], str] | Callable[[], Awaitable[str]] = Field(
@@ -39,6 +41,8 @@ class UiPathChatOpenAI(UiPathBaseChatModel, ChatOpenAI): # type: ignore[overrid
3941

4042
@model_validator(mode="after")
4143
def setup_uipath_client(self) -> Self:
44+
if self.api_flavor is not None:
45+
self.api_config.api_flavor = self.api_flavor
4246
base_url = str(self.uipath_sync_client.base_url).rstrip("/")
4347
locked_flavor = str(self.api_config.api_flavor) if self.api_config.api_flavor else None
4448

@@ -76,6 +80,7 @@ class UiPathAzureChatOpenAI(UiPathBaseChatModel, AzureChatOpenAI): # type: igno
7680
api_version="2025-03-01-preview",
7781
freeze_base_url=False,
7882
)
83+
api_flavor: ApiFlavor | str | None = None
7984

8085
# Override fields to avoid errors when instantiating the class
8186
azure_endpoint: str | None = Field(default="PLACEHOLDER")
@@ -84,6 +89,8 @@ class UiPathAzureChatOpenAI(UiPathBaseChatModel, AzureChatOpenAI): # type: igno
8489

8590
@model_validator(mode="after")
8691
def setup_uipath_client(self) -> Self:
92+
if self.api_flavor is not None:
93+
self.api_config.api_flavor = self.api_flavor
8794
base_url = str(self.uipath_sync_client.base_url).rstrip("/")
8895
locked_flavor = str(self.api_config.api_flavor) if self.api_config.api_flavor else None
8996

packages/uipath_langchain_client/src/uipath_langchain_client/factory.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
API_FLAVOR_TO_VENDOR_TYPE,
3131
BYOM_TO_ROUTING_FLAVOR,
3232
ApiFlavor,
33-
ApiType,
3433
RoutingMode,
35-
UiPathAPIConfig,
3634
UiPathBaseSettings,
3735
VendorType,
3836
get_default_client_settings,
@@ -176,18 +174,6 @@ def get_chat_model(
176174
if api_flavor == ApiFlavor.RESPONSES:
177175
model_kwargs["use_responses_api"] = True
178176

179-
# Lock the api_flavor into the api_config so the request hook
180-
# uses it instead of dynamically detecting from the URL path.
181-
if api_flavor is not None:
182-
model_kwargs["api_config"] = UiPathAPIConfig(
183-
api_type=ApiType.COMPLETIONS,
184-
routing_mode=RoutingMode.PASSTHROUGH,
185-
vendor_type=VendorType.OPENAI,
186-
api_version="2025-03-01-preview",
187-
api_flavor=str(api_flavor),
188-
freeze_base_url=False,
189-
)
190-
191177
if is_uipath_owned:
192178
from uipath_langchain_client.clients.openai.chat_models import (
193179
UiPathAzureChatOpenAI,
@@ -196,6 +182,7 @@ def get_chat_model(
196182
return UiPathAzureChatOpenAI(
197183
model=model_name,
198184
settings=client_settings,
185+
api_flavor=api_flavor,
199186
byo_connection_id=byo_connection_id,
200187
**model_kwargs,
201188
)
@@ -207,6 +194,7 @@ def get_chat_model(
207194
return UiPathChatOpenAI(
208195
model=model_name,
209196
settings=client_settings,
197+
api_flavor=api_flavor,
210198
byo_connection_id=byo_connection_id,
211199
**model_kwargs,
212200
)

0 commit comments

Comments
 (0)