Skip to content

Commit 822806b

Browse files
committed
revert: restore UiPathChatAnthropic to original structure
- Restore VendorType.ANTHROPIC as default for both api_config.vendor_type and the vendor_type field - Restore all four vendor branches (ANTHROPIC, AZURE, VERTEXAI, AWSBEDROCK) in _anthropic_client and _async_anthropic_client - Restore original imports (Anthropic, AnthropicFoundry, AsyncAnthropic, AsyncAnthropicFoundry) that were removed in the earlier fix - Remove the long explanatory comment on api_config - Keep the original error messages verbatim
1 parent 8ad12aa commit 822806b

1 file changed

Lines changed: 43 additions & 17 deletions

File tree

  • packages/uipath_langchain_client/src/uipath_langchain_client/clients/anthropic

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

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515

1616
try:
1717
from anthropic import (
18+
Anthropic,
1819
AnthropicBedrock,
20+
AnthropicFoundry,
1921
AnthropicVertex,
22+
AsyncAnthropic,
2023
AsyncAnthropicBedrock,
24+
AsyncAnthropicFoundry,
2125
AsyncAnthropicVertex,
2226
)
2327
from langchain_anthropic.chat_models import ChatAnthropic
@@ -29,18 +33,13 @@
2933

3034

3135
class UiPathChatAnthropic(UiPathBaseChatModel, ChatAnthropic):
32-
# api_config.vendor_type is a placeholder here; the model_validator below
33-
# always overwrites it (and api_flavor / api_version) from self.vendor_type.
34-
# VendorType.VERTEXAI is used as the seed so UiPathAPIConfig's own validator
35-
# (which requires vendor_type when routing_mode=PASSTHROUGH) is satisfied.
3636
api_config: UiPathAPIConfig = UiPathAPIConfig(
3737
api_type=ApiType.COMPLETIONS,
3838
routing_mode=RoutingMode.PASSTHROUGH,
39-
vendor_type=VendorType.VERTEXAI,
39+
vendor_type=VendorType.ANTHROPIC,
4040
freeze_base_url=True,
4141
)
42-
# Required — caller must supply VendorType.VERTEXAI or VendorType.AWSBEDROCK.
43-
vendor_type: VendorType
42+
vendor_type: VendorType = VendorType.ANTHROPIC
4443

4544
@model_validator(mode="after")
4645
def setup_api_flavor_and_version(self) -> Self:
@@ -53,8 +52,7 @@ def setup_api_flavor_and_version(self) -> Self:
5352
self.api_config.api_flavor = ApiFlavor.INVOKE
5453
case _:
5554
raise ValueError(
56-
f"vendor_type '{self.vendor_type}' is not supported by UiPathChatAnthropic. "
57-
"Use VendorType.VERTEXAI or VendorType.AWSBEDROCK."
55+
"anthropic and azure vendors are currently not supported by UiPath"
5856
)
5957
return self
6058

@@ -66,8 +64,24 @@ def setup_api_flavor_and_version(self) -> Self:
6664
@cached_property
6765
def _anthropic_client(
6866
self,
69-
) -> AnthropicVertex | AnthropicBedrock:
67+
) -> Anthropic | AnthropicVertex | AnthropicBedrock | AnthropicFoundry:
7068
match self.vendor_type:
69+
case VendorType.ANTHROPIC:
70+
return Anthropic(
71+
api_key="PLACEHOLDER",
72+
base_url=str(self.uipath_sync_client.base_url),
73+
default_headers=dict(self.uipath_sync_client.headers),
74+
max_retries=0, # handled by the UiPathBaseChatModel
75+
http_client=self.uipath_sync_client,
76+
)
77+
case VendorType.AZURE:
78+
return AnthropicFoundry(
79+
api_key="PLACEHOLDER",
80+
base_url=str(self.uipath_sync_client.base_url),
81+
default_headers=dict(self.uipath_sync_client.headers),
82+
max_retries=0, # handled by the UiPathBaseChatModel
83+
http_client=self.uipath_sync_client,
84+
)
7185
case VendorType.VERTEXAI:
7286
return AnthropicVertex(
7387
region="PLACEHOLDER",
@@ -89,15 +103,29 @@ def _anthropic_client(
89103
http_client=self.uipath_sync_client,
90104
)
91105
case _:
92-
raise ValueError(
93-
f"vendor_type '{self.vendor_type}' is not supported by UiPathChatAnthropic."
94-
)
106+
raise ValueError("Anthropic models are currently not hosted on any other provider")
95107

96108
@cached_property
97109
def _async_anthropic_client(
98110
self,
99-
) -> AsyncAnthropicVertex | AsyncAnthropicBedrock:
111+
) -> AsyncAnthropic | AsyncAnthropicVertex | AsyncAnthropicBedrock | AsyncAnthropicFoundry:
100112
match self.vendor_type:
113+
case VendorType.ANTHROPIC:
114+
return AsyncAnthropic(
115+
api_key="PLACEHOLDER",
116+
base_url=str(self.uipath_async_client.base_url),
117+
default_headers=dict(self.uipath_async_client.headers),
118+
max_retries=0, # handled by the UiPathBaseChatModel
119+
http_client=self.uipath_async_client,
120+
)
121+
case VendorType.AZURE:
122+
return AsyncAnthropicFoundry(
123+
api_key="PLACEHOLDER",
124+
base_url=str(self.uipath_async_client.base_url),
125+
default_headers=dict(self.uipath_async_client.headers),
126+
max_retries=0, # handled by the UiPathBaseChatModel
127+
http_client=self.uipath_async_client,
128+
)
101129
case VendorType.VERTEXAI:
102130
return AsyncAnthropicVertex(
103131
region="PLACEHOLDER",
@@ -119,9 +147,7 @@ def _async_anthropic_client(
119147
http_client=self.uipath_async_client,
120148
)
121149
case _:
122-
raise ValueError(
123-
f"vendor_type '{self.vendor_type}' is not supported by UiPathChatAnthropic."
124-
)
150+
raise ValueError("Anthropic models are currently not hosted on any other provider")
125151

126152
@override
127153
def _create(self, payload: dict) -> Any:

0 commit comments

Comments
 (0)