|
| 1 | +import pytest |
| 2 | +from pydantic import ValidationError |
| 3 | +from uipath_langchain_client.clients.bedrock.chat_models import ( |
| 4 | + UiPathChatBedrockConverse as _UpstreamBedrockConverse, |
| 5 | +) |
| 6 | +from uipath_langchain_client.clients.normalized.chat_models import ( |
| 7 | + UiPathChat as _UpstreamUiPathChat, |
| 8 | +) |
| 9 | + |
| 10 | +from uipath_langchain.chat import ( |
| 11 | + UiPathAzureChatOpenAI, |
| 12 | + UiPathChat, |
| 13 | + UiPathChatAnthropic, |
| 14 | + UiPathChatAnthropicBedrock, |
| 15 | + UiPathChatAnthropicVertex, |
| 16 | + UiPathChatBedrock, |
| 17 | + UiPathChatBedrockConverse, |
| 18 | + UiPathChatFireworks, |
| 19 | + UiPathChatGoogleGenerativeAI, |
| 20 | + UiPathChatOpenAI, |
| 21 | + UiPathChatVertex, |
| 22 | +) |
| 23 | + |
| 24 | +_DEFAULT_OPENAI = "gpt-4.1-mini-2025-04-14" |
| 25 | +_DEFAULT_BEDROCK = "anthropic.claude-haiku-4-5-20251001-v1:0" |
| 26 | +_DEFAULT_VERTEX = "gemini-2.5-flash" |
| 27 | + |
| 28 | +_FAKE_JWT = ( |
| 29 | + "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9." |
| 30 | + "eyJzdWIiOiAidGVzdCIsICJpc3MiOiAidGVzdCJ9." |
| 31 | + "signature" |
| 32 | +) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.fixture(autouse=True) |
| 36 | +def _platform_env(monkeypatch): |
| 37 | + monkeypatch.setenv("UIPATH_ACCESS_TOKEN", _FAKE_JWT) |
| 38 | + monkeypatch.setenv("UIPATH_URL", "https://example.com/org/tenant/orchestrator_/") |
| 39 | + monkeypatch.setenv("UIPATH_TENANT_ID", "tenant") |
| 40 | + monkeypatch.setenv("UIPATH_ORGANIZATION_ID", "org") |
| 41 | + monkeypatch.delenv("UIPATH_MODEL_NAME", raising=False) |
| 42 | + |
| 43 | + |
| 44 | +_CASES = [ |
| 45 | + (UiPathChat, _DEFAULT_OPENAI), |
| 46 | + (UiPathAzureChatOpenAI, _DEFAULT_OPENAI), |
| 47 | + (UiPathChatOpenAI, _DEFAULT_OPENAI), |
| 48 | + (UiPathChatGoogleGenerativeAI, _DEFAULT_VERTEX), |
| 49 | + (UiPathChatVertex, _DEFAULT_VERTEX), |
| 50 | + (UiPathChatBedrock, _DEFAULT_BEDROCK), |
| 51 | + (UiPathChatBedrockConverse, _DEFAULT_BEDROCK), |
| 52 | + (UiPathChatAnthropicBedrock, _DEFAULT_BEDROCK), |
| 53 | +] |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.parametrize("cls, expected", _CASES) |
| 57 | +class TestInstantiationWithoutModelKwarg: |
| 58 | + def test_no_args_uses_default(self, cls, expected): |
| 59 | + llm = cls() |
| 60 | + assert llm.model_name == expected |
| 61 | + |
| 62 | + def test_explicit_model_kwarg_overrides_default(self, cls, expected): |
| 63 | + llm = cls(model="custom-model-id") |
| 64 | + assert llm.model_name == "custom-model-id" |
| 65 | + |
| 66 | + |
| 67 | +def test_uipath_chat_no_args(): |
| 68 | + llm = UiPathChat() |
| 69 | + assert llm.model_name == _DEFAULT_OPENAI |
| 70 | + |
| 71 | + |
| 72 | +def test_uipath_chat_bedrock_no_args(): |
| 73 | + llm = UiPathChatBedrock() |
| 74 | + assert llm.model_name == _DEFAULT_BEDROCK |
| 75 | + |
| 76 | + |
| 77 | +def test_uipath_chat_bedrock_converse_no_args(): |
| 78 | + llm = UiPathChatBedrockConverse() |
| 79 | + assert llm.model_name == _DEFAULT_BEDROCK |
| 80 | + |
| 81 | + |
| 82 | +def test_uipath_chat_vertex_no_args(): |
| 83 | + llm = UiPathChatVertex() |
| 84 | + assert llm.model_name == _DEFAULT_VERTEX |
| 85 | + |
| 86 | + |
| 87 | +class TestUipathModelNameEnvVarOverride: |
| 88 | + def test_env_var_overrides_openai_default(self, monkeypatch): |
| 89 | + monkeypatch.setenv("UIPATH_MODEL_NAME", "custom-override") |
| 90 | + llm = UiPathChat() |
| 91 | + assert llm.model_name == "custom-override" |
| 92 | + |
| 93 | + def test_env_var_overrides_bedrock_default(self, monkeypatch): |
| 94 | + monkeypatch.setenv("UIPATH_MODEL_NAME", "custom-override") |
| 95 | + llm = UiPathChatBedrock() |
| 96 | + assert llm.model_name == "custom-override" |
| 97 | + |
| 98 | + def test_env_var_overrides_bedrock_converse_default(self, monkeypatch): |
| 99 | + monkeypatch.setenv("UIPATH_MODEL_NAME", "custom-override") |
| 100 | + llm = UiPathChatBedrockConverse() |
| 101 | + assert llm.model_name == "custom-override" |
| 102 | + |
| 103 | + def test_env_var_overrides_vertex_default(self, monkeypatch): |
| 104 | + monkeypatch.setenv("UIPATH_MODEL_NAME", "custom-override") |
| 105 | + llm = UiPathChatGoogleGenerativeAI() |
| 106 | + assert llm.model_name == "custom-override" |
| 107 | + |
| 108 | + |
| 109 | +class TestExportsWithoutDefaults: |
| 110 | + def test_anthropic_raises_without_model(self): |
| 111 | + with pytest.raises(ValidationError, match="model"): |
| 112 | + UiPathChatAnthropic() |
| 113 | + |
| 114 | + def test_anthropic_vertex_raises_without_model(self): |
| 115 | + with pytest.raises(ValidationError, match="model"): |
| 116 | + UiPathChatAnthropicVertex() |
| 117 | + |
| 118 | + def test_fireworks_raises_without_model(self): |
| 119 | + with pytest.raises(ValidationError, match="model"): |
| 120 | + UiPathChatFireworks() |
| 121 | + |
| 122 | + |
| 123 | +class TestReExportedClassIdentity: |
| 124 | + def test_uipath_chat_is_upstream_class(self): |
| 125 | + assert UiPathChat is _UpstreamUiPathChat |
| 126 | + |
| 127 | + def test_uipath_chat_vertex_alias_matches_google(self): |
| 128 | + assert UiPathChatVertex is UiPathChatGoogleGenerativeAI |
| 129 | + |
| 130 | + def test_bedrock_converse_is_subclass_of_upstream(self): |
| 131 | + assert issubclass(UiPathChatBedrockConverse, _UpstreamBedrockConverse) |
0 commit comments