|
1 | 1 | from unittest.mock import MagicMock |
2 | 2 |
|
3 | 3 | import pytest |
| 4 | +from uipath_langchain_client.clients.bedrock.chat_models import ( |
| 5 | + UiPathChatBedrock, |
| 6 | + UiPathChatBedrockConverse, |
| 7 | +) |
4 | 8 | from uipath_langchain_client.clients.normalized.chat_models import UiPathChat |
5 | 9 | from uipath_langchain_client.clients.normalized.embeddings import UiPathEmbeddings |
6 | | -from uipath_langchain_client.factory import get_chat_model, get_embedding_model |
| 10 | +from uipath_langchain_client.factory import ( |
| 11 | + get_chat_model, |
| 12 | + get_embedding_model, |
| 13 | +) |
7 | 14 |
|
8 | 15 | from tests.langchain.conftest import COMPLETION_MODEL_NAMES, EMBEDDING_MODEL_NAMES |
9 | 16 | from uipath.llm_client.settings import ApiFlavor, UiPathBaseSettings, VendorType |
@@ -379,3 +386,94 @@ def test_anthropic_messages_routes_to_uipath_chat_anthropic( |
379 | 386 | ) |
380 | 387 | assert captured["vendor_type"] == VendorType.AWSBEDROCK |
381 | 388 | assert captured["api_flavor"] == ApiFlavor.ANTHROPIC_MESSAGES |
| 389 | + |
| 390 | + |
| 391 | +_BYO_BEDROCK_CONVERSE = { |
| 392 | + "modelName": "AWS - Bedrock", |
| 393 | + "vendor": "AwsBedrock", |
| 394 | + "modelFamily": None, |
| 395 | + "apiFlavor": None, |
| 396 | + "modelSubscriptionType": "BYOMAdded", |
| 397 | + "byomDetails": { |
| 398 | + "customerModel": "anthropic.claude-sonnet-4-5-20250929-v1:0", |
| 399 | + "integrationServiceConnectionId": "conn-x", |
| 400 | + }, |
| 401 | +} |
| 402 | +_BYO_BEDROCK_INVOKE = {**_BYO_BEDROCK_CONVERSE, "apiFlavor": "AwsBedrockInvoke"} |
| 403 | + |
| 404 | + |
| 405 | +class TestBedrockFactoryBaseModel: |
| 406 | + @pytest.fixture() |
| 407 | + def client_settings(self): |
| 408 | + import os |
| 409 | + from unittest.mock import patch |
| 410 | + |
| 411 | + from uipath.llm_client.settings.llmgateway import LLMGatewaySettings |
| 412 | + |
| 413 | + env = { |
| 414 | + "LLMGW_URL": "http://test-bedrock", |
| 415 | + "LLMGW_SEMANTIC_ORG_ID": "org", |
| 416 | + "LLMGW_SEMANTIC_TENANT_ID": "tenant", |
| 417 | + "LLMGW_REQUESTING_PRODUCT": "test", |
| 418 | + "LLMGW_REQUESTING_FEATURE": "test", |
| 419 | + "LLMGW_ACCESS_TOKEN": "dummy-token", |
| 420 | + } |
| 421 | + with patch.dict(os.environ, env, clear=True): |
| 422 | + return LLMGatewaySettings() |
| 423 | + |
| 424 | + @pytest.fixture(autouse=True) |
| 425 | + def _clear_discovery_cache(self): |
| 426 | + UiPathBaseSettings._discovery_cache.clear() |
| 427 | + yield |
| 428 | + UiPathBaseSettings._discovery_cache.clear() |
| 429 | + |
| 430 | + def _seed(self, client_settings, model_info): |
| 431 | + key = client_settings._discovery_cache_key() |
| 432 | + client_settings._discovery_cache[key] = [model_info] |
| 433 | + |
| 434 | + def test_converse_byo_alias_gets_backing_base_model(self, client_settings): |
| 435 | + self._seed(client_settings, _BYO_BEDROCK_CONVERSE) |
| 436 | + model = get_chat_model( |
| 437 | + "AWS - Bedrock", |
| 438 | + byo_connection_id="conn-x", |
| 439 | + client_settings=client_settings, |
| 440 | + ) |
| 441 | + assert isinstance(model, UiPathChatBedrockConverse) |
| 442 | + assert model.model_id == "AWS - Bedrock" |
| 443 | + assert model.base_model_id == "anthropic.claude-sonnet-4-5-20250929-v1:0" |
| 444 | + assert model.supports_tool_choice_values == ("auto", "any", "tool") |
| 445 | + |
| 446 | + from langchain_core.tools import tool |
| 447 | + |
| 448 | + @tool |
| 449 | + def ping() -> str: |
| 450 | + """ping.""" |
| 451 | + return "pong" |
| 452 | + |
| 453 | + model.bind_tools([ping], tool_choice="any") |
| 454 | + |
| 455 | + def test_converse_direct_construction_takes_explicit_backing_model(self, client_settings): |
| 456 | + self._seed(client_settings, _BYO_BEDROCK_CONVERSE) |
| 457 | + model = UiPathChatBedrockConverse( |
| 458 | + model="AWS - Bedrock", |
| 459 | + settings=client_settings, |
| 460 | + byo_connection_id="conn-x", |
| 461 | + base_model="anthropic.claude-sonnet-4-5-20250929-v1:0", |
| 462 | + provider="anthropic", |
| 463 | + ) |
| 464 | + assert model.base_model_id == "anthropic.claude-sonnet-4-5-20250929-v1:0" |
| 465 | + assert model.provider == "anthropic" |
| 466 | + assert model.supports_tool_choice_values == ("auto", "any", "tool") |
| 467 | + |
| 468 | + def test_invoke_byo_alias_gets_provider(self, client_settings): |
| 469 | + self._seed(client_settings, _BYO_BEDROCK_INVOKE) |
| 470 | + model = get_chat_model( |
| 471 | + "AWS - Bedrock", |
| 472 | + byo_connection_id="conn-x", |
| 473 | + client_settings=client_settings, |
| 474 | + ) |
| 475 | + assert isinstance(model, UiPathChatBedrock) |
| 476 | + assert model.model_id == "AWS - Bedrock" |
| 477 | + assert model.base_model_id == "anthropic.claude-sonnet-4-5-20250929-v1:0" |
| 478 | + assert model.provider == "anthropic" |
| 479 | + assert model._get_provider() == "anthropic" |
0 commit comments