-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathtest_agenthub_config_default.py
More file actions
75 lines (63 loc) · 2.67 KB
/
test_agenthub_config_default.py
File metadata and controls
75 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Tests that direct construction of UiPathChat / UiPathChatOpenAI /
UiPathAzureChatOpenAI / UiPathChatBedrock / UiPathChatBedrockConverse /
UiPathChatAnthropicBedrock / UiPathChatGoogleGenerativeAI / UiPathChatVertex
defaults ``client_settings.agenthub_config`` to None and omits the
``x-uipath-agenthub-config`` header on the outgoing httpx client unless
``UIPATH_AGENTHUB_CONFIG`` is set."""
import pytest
from uipath_langchain.chat import (
UiPathAzureChatOpenAI,
UiPathChat,
UiPathChatAnthropicBedrock,
UiPathChatBedrock,
UiPathChatBedrockConverse,
UiPathChatGoogleGenerativeAI,
UiPathChatOpenAI,
UiPathChatVertex,
)
_FAKE_JWT = (
"eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9."
"eyJzdWIiOiAidGVzdCIsICJpc3MiOiAidGVzdCJ9."
"signature"
)
@pytest.fixture(autouse=True)
def _platform_env(monkeypatch):
monkeypatch.setenv("UIPATH_ACCESS_TOKEN", _FAKE_JWT)
monkeypatch.setenv("UIPATH_URL", "https://example.com/org/tenant/orchestrator_/")
monkeypatch.setenv("UIPATH_TENANT_ID", "tenant")
monkeypatch.setenv("UIPATH_ORGANIZATION_ID", "org")
monkeypatch.delenv("UIPATH_AGENTHUB_CONFIG", raising=False)
monkeypatch.delenv("UIPATH_MODEL_NAME", raising=False)
_DIRECT_CTOR_CASES = [
UiPathChat,
UiPathAzureChatOpenAI,
UiPathChatOpenAI,
UiPathChatBedrock,
UiPathChatBedrockConverse,
UiPathChatAnthropicBedrock,
UiPathChatGoogleGenerativeAI,
UiPathChatVertex,
]
@pytest.mark.parametrize("cls", _DIRECT_CTOR_CASES)
class TestDirectConstructorAgentHubConfig:
def test_default_is_none(self, cls):
llm = cls()
assert llm.client_settings.agenthub_config is None
def test_env_var_is_honored(self, cls, monkeypatch):
monkeypatch.setenv("UIPATH_AGENTHUB_CONFIG", "agentsplayground")
llm = cls()
assert llm.client_settings.agenthub_config == "agentsplayground"
def test_no_agenthub_header_on_inner_http_client(self, cls):
llm = cls()
client = getattr(llm, "uipath_sync_client", None)
if client is None:
pytest.skip(f"{cls.__name__} has no uipath_sync_client to inspect")
assert "x-uipath-agenthub-config" not in {key.lower() for key in client.headers}
def test_env_var_is_honored_on_inner_http_client(self, cls, monkeypatch):
monkeypatch.setenv("UIPATH_AGENTHUB_CONFIG", "agentsplayground")
llm = cls()
client = getattr(llm, "uipath_sync_client", None)
if client is None:
pytest.skip(f"{cls.__name__} has no uipath_sync_client to inspect")
normalized = {key.lower(): value for key, value in client.headers.items()}
assert normalized.get("x-uipath-agenthub-config") == "agentsplayground"