Skip to content

Commit 676f836

Browse files
authored
Fix/OpenAI api flavor at invocation time (#22)
1 parent 743a480 commit 676f836

12 files changed

Lines changed: 97 additions & 51 deletions

File tree

.github/workflows/cd-langchain.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ jobs:
4747
steps:
4848
- uses: actions/checkout@v6
4949

50+
- name: Wait for package indexing
51+
if: github.event_name == 'workflow_run'
52+
run: sleep 60
53+
5054
- name: Setup uv
5155
uses: astral-sh/setup-uv@v7
5256
with:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to `uipath_llm_client` (core package) will be documented in this file.
44

5+
## [1.1.1] - 2026-02-12
6+
7+
### Fix
8+
- Small fixes on openai client
9+
510
## [1.1.0] - 2026-02-11
611

712
### Stable release

packages/uipath_langchain_client/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to `uipath_langchain_client` will be documented in this file.
44

5+
## [1.1.3] - 2026-02-12
6+
7+
### Fixes
8+
- Fixes on openai langchain client on resposes_api
9+
- Allow the flavor to be set up at requst time, not just when instantiating the llm
10+
- Some fixes for the anthropic client
11+
512
## [1.1.2] - 2026-02-12
613

714
### Refactor

packages/uipath_langchain_client/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
requires-python = ">=3.11"
77
dependencies = [
88
"langchain>=1.2.7",
9-
"uipath-llm-client>=1.1.0",
9+
"uipath-llm-client>=1.1.1",
1010
]
1111

1212
[project.optional-dependencies]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__title__ = "UiPath LangChain Client"
22
__description__ = "A Python client for interacting with UiPath's LLM services via LangChain."
3-
__version__ = "1.1.2"
3+
__version__ = "1.1.3"

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@ class UiPathChatAnthropic(UiPathBaseLLMClient, ChatAnthropic):
3333
vendor_type="anthropic",
3434
freeze_base_url=True,
3535
)
36-
vendor_type: Literal["anthropic", "azure", "vertexai", "awsbedrock"] = "awsbedrock"
36+
vendor_type: Literal["anthropic", "azure", "vertexai", "awsbedrock"] = "anthropic"
3737

3838
@model_validator(mode="after")
3939
def setup_api_flavor_and_version(self) -> Self:
40+
self.api_config.vendor_type = self.vendor_type
4041
match self.vendor_type:
4142
case "vertexai":
4243
self.api_config.api_flavor = "anthropic-claude"
4344
self.api_config.api_version = "v1beta1"
4445
case "awsbedrock":
4546
self.api_config.api_flavor = "invoke"
4647
case _:
47-
raise ValueError("Those vendors are currently not supported")
48-
self.api_config.vendor_type = self.vendor_type
48+
raise ValueError(
49+
"anthropic and azure vendors are currently not supported by UiPath"
50+
)
4951
return self
5052

5153
# Override fields to avoid typing issues and fix stuff

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

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Awaitable, Callable
22
from typing import Self
33

4+
from httpx import URL, Request
45
from pydantic import Field, SecretStr, model_validator
56
from uipath_langchain_client.base_client import UiPathBaseLLMClient
67
from uipath_langchain_client.settings import UiPathAPIConfig
@@ -21,25 +22,38 @@ class UiPathChatOpenAI(UiPathBaseLLMClient, ChatOpenAI): # type: ignore[overrid
2122
api_type="completions",
2223
client_type="passthrough",
2324
vendor_type="openai",
24-
freeze_base_url=True,
25+
api_version="2025-03-01-preview",
26+
freeze_base_url=False,
2527
)
2628

2729
# Override fields to avoid errors when instantiating the class
2830
openai_api_key: SecretStr | None | Callable[[], str] | Callable[[], Awaitable[str]] = Field(
2931
alias="api_key", default=SecretStr("PLACEHOLDER")
3032
)
3133

32-
@model_validator(mode="after")
33-
def setup_uipath_api_flavor_and_version(self) -> Self:
34-
self.api_config.api_version = "2025-03-01-preview"
35-
if self._use_responses_api({}):
36-
self.api_config.api_flavor = "responses"
37-
else:
38-
self.api_config.api_flavor = "chat-completions"
39-
return self
40-
4134
@model_validator(mode="after")
4235
def setup_uipath_client(self) -> Self:
36+
base_url = str(self.uipath_sync_client.base_url).rstrip("/")
37+
38+
def fix_url_and_api_flavor_header(request: Request):
39+
url_suffix = str(request.url).split(base_url)[-1]
40+
if "responses" in url_suffix:
41+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "responses"
42+
else:
43+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "chat-completions"
44+
request.url = URL(base_url)
45+
46+
async def fix_url_and_api_flavor_header_async(request: Request):
47+
url_suffix = str(request.url).split(base_url)[-1]
48+
if "responses" in url_suffix:
49+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "responses"
50+
else:
51+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "chat-completions"
52+
request.url = URL(base_url)
53+
54+
self.uipath_sync_client.event_hooks["request"].append(fix_url_and_api_flavor_header)
55+
self.uipath_async_client.event_hooks["request"].append(fix_url_and_api_flavor_header_async)
56+
4357
self.root_client = OpenAI(
4458
api_key="PLACEHOLDER",
4559
timeout=None, # handled by the UiPath client
@@ -62,25 +76,37 @@ class UiPathAzureChatOpenAI(UiPathBaseLLMClient, AzureChatOpenAI): # type: igno
6276
api_type="completions",
6377
client_type="passthrough",
6478
vendor_type="openai",
65-
freeze_base_url=True,
79+
api_version="2025-03-01-preview",
80+
freeze_base_url=False,
6681
)
6782

6883
# Override fields to avoid errors when instantiating the class
6984
azure_endpoint: str | None = Field(default="PLACEHOLDER")
7085
openai_api_version: str | None = Field(default="PLACEHOLDER", alias="api_version")
7186
openai_api_key: SecretStr | None = Field(default=SecretStr("PLACEHOLDER"), alias="api_key")
7287

73-
@model_validator(mode="after")
74-
def setup_uipath_api_flavor_and_version(self) -> Self:
75-
self.api_config.api_version = "2025-03-01-preview"
76-
if self._use_responses_api({}):
77-
self.api_config.api_flavor = "responses"
78-
else:
79-
self.api_config.api_flavor = "chat-completions"
80-
return self
81-
8288
@model_validator(mode="after")
8389
def setup_uipath_client(self) -> Self:
90+
base_url = str(self.uipath_sync_client.base_url).rstrip("/")
91+
92+
def fix_url_and_api_flavor_header(request: Request):
93+
url_suffix = str(request.url).split(base_url)[-1]
94+
if "responses" in url_suffix:
95+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "responses"
96+
else:
97+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "chat-completions"
98+
request.url = URL(base_url)
99+
100+
async def fix_url_and_api_flavor_header_async(request: Request):
101+
url_suffix = str(request.url).split(base_url)[-1]
102+
if "responses" in url_suffix:
103+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "responses"
104+
else:
105+
request.headers["X-UiPath-LlmGateway-ApiFlavor"] = "chat-completions"
106+
request.url = URL(base_url)
107+
108+
self.uipath_sync_client.event_hooks["request"].append(fix_url_and_api_flavor_header)
109+
self.uipath_async_client.event_hooks["request"].append(fix_url_and_api_flavor_header_async)
84110
self.root_client = AzureOpenAI(
85111
azure_endpoint="PLACEHOLDER",
86112
api_version="PLACEHOLDER",

packages/uipath_langchain_client/src/uipath_langchain_client/factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def get_chat_model(
177177
return UiPathChatAnthropic(
178178
model=model_name,
179179
settings=client_settings,
180+
vendor_type=vendor_type,
180181
**model_kwargs,
181182
)
182183
else:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__titile__ = "UiPath LLM Client"
22
__description__ = "A Python client for interacting with UiPath's LLM services."
3-
__version__ = "1.1.0"
3+
__version__ = "1.1.1"

src/uipath_llm_client/httpx_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class UiPathHttpxAsyncClient(AsyncClient):
219219

220220
_streaming_header: str = "X-UiPath-Streaming-Enabled"
221221
_default_headers: Mapping[str, str] = {
222-
"X-UiPath-LLMGateway-TimeoutSeconds": "30", # server side timeout, default is 10, maximum is 300
222+
"X-UiPath-LLMGateway-TimeoutSeconds": "295", # server side timeout, default is 10, maximum is 300
223223
"X-UiPath-LLMGateway-AllowFull4xxResponse": "true", # allow full 4xx responses (default is false)
224224
}
225225

0 commit comments

Comments
 (0)