Skip to content

Commit 15fd4e4

Browse files
authored
Refactor langchain factory function (#11)
1 parent a3e7e63 commit 15fd4e4

4 files changed

Lines changed: 120 additions & 36 deletions

File tree

packages/uipath_langchain_client/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_langchain_client` will be documented in this file.
44

5+
## [1.0.7] - 2026-02-04
6+
7+
### Refactor
8+
- Refactor factory function to include byom models
9+
510
## [1.0.6] - 2026-02-03
611

712
### 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.0.5",
9+
"uipath-llm-client>=1.0.6",
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.0.6"
3+
__version__ = "1.0.7"

packages/uipath_langchain_client/src/uipath_langchain_client/factory.py

Lines changed: 113 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ def _get_model_info(
4747
]
4848

4949
if not byo_connection_id and len(matching_models) > 1:
50-
matching_models = [m for m in matching_models if m.get("byomDetails") is None]
50+
matching_models = [
51+
m
52+
for m in matching_models
53+
if (
54+
(m.get("modelSubscriptionType", "") == "UiPathOwned")
55+
or (m.get("byomDetails") is None)
56+
)
57+
]
5158

5259
if not matching_models:
5360
raise ValueError(
@@ -87,12 +94,18 @@ def get_chat_model(
8794
UiPathNormalizedChatModel,
8895
)
8996

90-
return UiPathNormalizedChatModel(model=model_name, **model_kwargs)
97+
return UiPathNormalizedChatModel(
98+
model=model_name,
99+
settings=client_settings,
100+
byo_connection_id=byo_connection_id,
101+
**model_kwargs,
102+
)
91103

92104
vendor_type = model_info["vendor"].lower()
105+
is_uipath_owned = model_info.get("modelSubscriptionType") == "UiPathOwned"
93106
match vendor_type:
94107
case "openai":
95-
if "gpt" in model_name:
108+
if is_uipath_owned:
96109
from uipath_langchain_client.clients.openai.chat_models import (
97110
UiPathAzureChatOpenAI,
98111
)
@@ -103,47 +116,89 @@ def get_chat_model(
103116
**model_kwargs,
104117
)
105118
else:
106-
raise ValueError(f"Invalid model name: {model_name} for vendor: {vendor_type}")
107-
case "vertexai":
108-
if "gemini" in model_name:
109-
from uipath_langchain_client.clients.google.chat_models import (
110-
UiPathChatGoogleGenerativeAI,
119+
from uipath_langchain_client.clients.openai.chat_models import (
120+
UiPathChatOpenAI,
111121
)
112122

113-
return UiPathChatGoogleGenerativeAI(
123+
return UiPathChatOpenAI(
114124
model=model_name,
115125
settings=client_settings,
126+
byo_connection_id=byo_connection_id,
116127
**model_kwargs,
117128
)
118-
elif "claude" in model_name:
119-
from uipath_langchain_client.clients.anthropic.chat_models import (
120-
UiPathChatAnthropic,
129+
case "vertexai":
130+
if is_uipath_owned:
131+
if "claude" in model_name:
132+
from uipath_langchain_client.clients.vertexai.chat_models import (
133+
UiPathChatAnthropicVertex,
134+
)
135+
136+
return UiPathChatAnthropicVertex(
137+
model=model_name,
138+
settings=client_settings,
139+
**model_kwargs,
140+
)
141+
elif "gemini" in model_name:
142+
from uipath_langchain_client.clients.google.chat_models import (
143+
UiPathChatGoogleGenerativeAI,
144+
)
145+
146+
return UiPathChatGoogleGenerativeAI(
147+
model=model_name,
148+
settings=client_settings,
149+
**model_kwargs,
150+
)
151+
else:
152+
raise ValueError(
153+
f"We don't have a client that currently supports this model: {model_name} on vendor: {vendor_type}"
154+
)
155+
else:
156+
from uipath_langchain_client.clients.google.chat_models import (
157+
UiPathChatGoogleGenerativeAI,
121158
)
122159

123-
return UiPathChatAnthropic(
160+
return UiPathChatGoogleGenerativeAI(
124161
model=model_name,
125162
settings=client_settings,
126-
vendor_type="vertexai",
163+
byo_connection_id=byo_connection_id,
127164
**model_kwargs,
128165
)
129-
else:
130-
raise ValueError(f"Invalid model name: {model_name} for vendor: {vendor_type}")
131166
case "awsbedrock":
132-
if "claude" in model_name:
133-
from uipath_langchain_client.clients.anthropic.chat_models import (
134-
UiPathChatAnthropic,
167+
if is_uipath_owned:
168+
if "claude" in model_name:
169+
from uipath_langchain_client.clients.anthropic.chat_models import (
170+
UiPathChatAnthropic,
171+
)
172+
173+
return UiPathChatAnthropic(
174+
model=model_name,
175+
settings=client_settings,
176+
**model_kwargs,
177+
)
178+
else:
179+
from uipath_langchain_client.clients.bedrock.chat_models import (
180+
UiPathChatBedrock,
181+
)
182+
183+
return UiPathChatBedrock(
184+
model=model_name,
185+
settings=client_settings,
186+
**model_kwargs,
187+
)
188+
else:
189+
from uipath_langchain_client.clients.bedrock.chat_models import (
190+
UiPathChatBedrockConverse,
135191
)
136192

137-
return UiPathChatAnthropic(
193+
return UiPathChatBedrockConverse(
138194
model=model_name,
139195
settings=client_settings,
140-
vendor_type="awsbedrock",
141196
**model_kwargs,
142197
)
143-
else:
144-
raise ValueError(f"Invalid model name: {model_name} for vendor: {vendor_type}")
145198
case _:
146-
raise ValueError(f"Invalid UiPath vendor type: {vendor_type}")
199+
raise ValueError(
200+
f"Invalid vendor type: {vendor_type}, we don't currently have clients that support that api type"
201+
)
147202

148203

149204
def get_embedding_model(
@@ -184,34 +239,58 @@ def get_embedding_model(
184239
)
185240

186241
return UiPathNormalizedEmbeddings(
187-
model=model_name, settings=client_settings, **model_kwargs
242+
model=model_name,
243+
settings=client_settings,
244+
byo_connection_id=byo_connection_id,
245+
**model_kwargs,
188246
)
189247

190248
vendor_type = model_info["vendor"].lower()
249+
is_uipath_owned = model_info.get("modelSubscriptionType") == "UiPathOwned"
191250
match vendor_type:
192251
case "openai":
193-
from uipath_langchain_client.clients.openai.embeddings import (
194-
UiPathAzureOpenAIEmbeddings,
195-
)
252+
if is_uipath_owned:
253+
from uipath_langchain_client.clients.openai.embeddings import (
254+
UiPathAzureOpenAIEmbeddings,
255+
)
196256

197-
return UiPathAzureOpenAIEmbeddings(
198-
model=model_name, settings=client_settings, **model_kwargs
199-
)
257+
return UiPathAzureOpenAIEmbeddings(
258+
model=model_name, settings=client_settings, **model_kwargs
259+
)
260+
else:
261+
from uipath_langchain_client.clients.openai.embeddings import (
262+
UiPathOpenAIEmbeddings,
263+
)
264+
265+
return UiPathOpenAIEmbeddings(
266+
model=model_name,
267+
settings=client_settings,
268+
byo_connection_id=byo_connection_id,
269+
**model_kwargs,
270+
)
200271
case "vertexai":
201272
from uipath_langchain_client.clients.google.embeddings import (
202273
UiPathGoogleGenerativeAIEmbeddings,
203274
)
204275

205276
return UiPathGoogleGenerativeAIEmbeddings(
206-
model=model_name, settings=client_settings, **model_kwargs
277+
model=model_name,
278+
settings=client_settings,
279+
byo_connection_id=byo_connection_id,
280+
**model_kwargs,
207281
)
208282
case "awsbedrock":
209283
from uipath_langchain_client.clients.bedrock.embeddings import (
210284
UiPathBedrockEmbeddings,
211285
)
212286

213287
return UiPathBedrockEmbeddings(
214-
model=model_name, settings=client_settings, **model_kwargs
288+
model=model_name,
289+
settings=client_settings,
290+
byo_connection_id=byo_connection_id,
291+
**model_kwargs,
215292
)
216293
case _:
217-
raise ValueError(f"Invalid UiPath Embeddings provider: {vendor_type}")
294+
raise ValueError(
295+
f"We don't currently have clients that support this provider: {vendor_type}"
296+
)

0 commit comments

Comments
 (0)