Skip to content

Commit 926227a

Browse files
cosminachoclaude
andauthored
Feat/update factory (#55)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a5115b0 commit 926227a

5 files changed

Lines changed: 56 additions & 1 deletion

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.7.1] - 2026-04-04
6+
7+
### Added
8+
- `custom_class` parameter in `get_chat_model()` and `get_embedding_model()` factory functions to allow instantiating a user-provided class instead of the auto-detected one
9+
510
## [1.7.0] - 2026-04-03
611

712
### Added
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.7.0"
3+
__version__ = "1.7.1"

packages/uipath_langchain_client/src/uipath_langchain_client/factory.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def get_chat_model(
8787
routing_mode: RoutingMode | str = RoutingMode.PASSTHROUGH,
8888
vendor_type: VendorType | str | None = None,
8989
api_flavor: ApiFlavor | str | None = None,
90+
custom_class: type[UiPathBaseChatModel] | None = None,
9091
**model_kwargs: Any,
9192
) -> UiPathBaseChatModel:
9293
"""Factory function to create the appropriate LangChain chat model for a given model name.
@@ -106,6 +107,9 @@ def get_chat_model(
106107
- Bedrock Claude: Default uses UiPathChatAnthropicBedrock.
107108
ApiFlavor.CONVERSE uses UiPathChatBedrockConverse,
108109
ApiFlavor.INVOKE uses UiPathChatBedrock.
110+
custom_class: A custom class to use for instantiating the chat model instead of the
111+
auto-detected one. Must be a subclass of UiPathBaseChatModel. When provided,
112+
the factory skips vendor detection and uses this class directly.
109113
**model_kwargs: Additional keyword arguments to pass to the model constructor.
110114
111115
Returns:
@@ -128,6 +132,14 @@ def get_chat_model(
128132
if not is_uipath_owned:
129133
client_settings.validate_byo_model(model_info)
130134

135+
if custom_class is not None:
136+
return custom_class(
137+
model=model_name,
138+
settings=client_settings,
139+
byo_connection_id=byo_connection_id,
140+
**model_kwargs,
141+
)
142+
131143
if routing_mode == RoutingMode.NORMALIZED:
132144
from uipath_langchain_client.clients.normalized.chat_models import (
133145
UiPathChat,
@@ -248,6 +260,7 @@ def get_embedding_model(
248260
client_settings: UiPathBaseSettings | None = None,
249261
routing_mode: RoutingMode | str = RoutingMode.PASSTHROUGH,
250262
vendor_type: VendorType | str | None = None,
263+
custom_class: type[UiPathBaseEmbeddings] | None = None,
251264
**model_kwargs: Any,
252265
) -> UiPathBaseEmbeddings:
253266
"""Factory function to create the appropriate LangChain embeddings model.
@@ -262,6 +275,9 @@ def get_embedding_model(
262275
RoutingMode.PASSTHROUGH for vendor-specific APIs.
263276
vendor_type: Filter models by vendor type (e.g., VendorType.OPENAI).
264277
If not provided, auto-detected from the model discovery endpoint.
278+
custom_class: A custom class to use for instantiating the embedding model instead of
279+
the auto-detected one. Must be a subclass of UiPathBaseEmbeddings. When provided,
280+
the factory skips vendor detection and uses this class directly.
265281
**model_kwargs: Additional arguments passed to the embeddings constructor.
266282
267283
Returns:
@@ -286,6 +302,14 @@ def get_embedding_model(
286302
if not is_uipath_owned:
287303
client_settings.validate_byo_model(model_info)
288304

305+
if custom_class is not None:
306+
return custom_class(
307+
model=model_name,
308+
settings=client_settings,
309+
byo_connection_id=byo_connection_id,
310+
**model_kwargs,
311+
)
312+
289313
if routing_mode == RoutingMode.NORMALIZED:
290314
from uipath_langchain_client.clients.normalized.embeddings import (
291315
UiPathEmbeddings,

tests/cassettes.db

208 KB
Binary file not shown.

tests/langchain/test_factory_function.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import pytest
2+
from uipath_langchain_client.clients.normalized.chat_models import UiPathChat
3+
from uipath_langchain_client.clients.normalized.embeddings import UiPathEmbeddings
24
from uipath_langchain_client.factory import get_chat_model, get_embedding_model
35

46
from tests.langchain.conftest import COMPLETION_MODEL_NAMES, EMBEDDING_MODEL_NAMES
@@ -18,3 +20,27 @@ def test_get_embedding_model(self, model_name: str, client_settings: UiPathBaseS
1820
model_name=model_name, client_settings=client_settings
1921
)
2022
assert embedding_model is not None
23+
24+
@pytest.mark.parametrize("model_name", COMPLETION_MODEL_NAMES)
25+
def test_get_chat_model_custom_class(
26+
self, model_name: str, client_settings: UiPathBaseSettings
27+
):
28+
chat_model = get_chat_model(
29+
model_name=model_name,
30+
client_settings=client_settings,
31+
custom_class=UiPathChat,
32+
)
33+
assert chat_model is not None
34+
assert isinstance(chat_model, UiPathChat)
35+
36+
@pytest.mark.parametrize("model_name", EMBEDDING_MODEL_NAMES)
37+
def test_get_embedding_model_custom_class(
38+
self, model_name: str, client_settings: UiPathBaseSettings
39+
):
40+
embedding_model = get_embedding_model(
41+
model_name=model_name,
42+
client_settings=client_settings,
43+
custom_class=UiPathEmbeddings,
44+
)
45+
assert embedding_model is not None
46+
assert isinstance(embedding_model, UiPathEmbeddings)

0 commit comments

Comments
 (0)