Spaces:
Running
Running
File size: 3,866 Bytes
9f2df60 31c360c 9f2df60 a7bed5e 9f2df60 | 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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | import os
import sys
import uuid
import pytest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from src.config import config
from src.rag.agent_chain import ExecutiveAgentChain
pytestmark = [pytest.mark.network, pytest.mark.integration]
def _has_real_agent_prerequisites() -> tuple[bool, str]:
llm_api_key = config.llm.get_api_key()
if not llm_api_key:
return False, "No LLM API key configured for the real agent positioning test."
missing = []
if not config.weaviate.CLUSTER_URL:
missing.append("WEAVIATE_CLUSTER_URL")
if not config.weaviate.WEAVIATE_API_KEY:
missing.append("WEAVIATE_API_KEY")
if not config.processing.EMBEDDING_API_KEY:
missing.append("OPEN_ROUTER_API_KEY")
if missing:
return False, f"Missing Weaviate configuration for real agent positioning test: {', '.join(missing)}"
return True, ""
def _normalize(text: str) -> str:
return " ".join(text.lower().split())
def _count_keyword_hits(text: str, keywords: list[str]) -> int:
normalized = _normalize(text)
return sum(1 for keyword in keywords if keyword.lower() in normalized)
_READY, _SKIP_REASON = _has_real_agent_prerequisites()
@pytest.fixture
def real_agent_positioning():
yield ExecutiveAgentChain(
language="en",
session_id=f"programme-positioning-{uuid.uuid4()}",
)
@pytest.mark.skipif(not _READY, reason=_SKIP_REASON)
def test_generic_programme_comparison_stays_balanced(real_agent_positioning):
response = real_agent_positioning.query(
"What is the difference between EMBA HSG and IEMBA HSG?"
)
response_text = _normalize(response.response)
assert "emba hsg" in response_text
assert "iemba" in response_text
assert response.appointment_requested is False
assert response.show_booking_widget is False
assert "best" not in response_text
assert "perfect" not in response_text
assert "guaranteed" not in response_text
assert "world-class" not in response_text
@pytest.mark.skipif(not _READY, reason=_SKIP_REASON)
def test_emba_interest_triggers_positive_value_framing(real_agent_positioning):
real_agent_positioning.query("I am particularly interested in the EMBA HSG.")
response = real_agent_positioning.query(
"Why might this programme be attractive for a German-speaking leader in the DACH region?"
)
emba_keywords = [
"dach",
"german-speaking",
"general management",
"leadership",
"peer network",
"regional",
]
response_text = response.response
assert "EMBA HSG" in response_text or "EMBA" in response_text
assert _count_keyword_hits(response_text, emba_keywords) >= 2, response_text
assert "best" not in _normalize(response_text)
assert "perfect" not in _normalize(response_text)
assert response.appointment_requested is False
assert response.show_booking_widget is False
@pytest.mark.skipif(not _READY, reason=_SKIP_REASON)
def test_iemba_interest_triggers_positive_value_framing(real_agent_positioning):
real_agent_positioning.query("I am particularly interested in the IEMBA HSG.")
response = real_agent_positioning.query(
"Why might this programme be attractive for an executive with international ambitions?"
)
iemba_keywords = [
"international",
"global",
"cohort",
"cross-cultural",
"different business environments",
"exposure",
]
response_text = response.response
assert "IEMBA" in response_text
assert _count_keyword_hits(response_text, iemba_keywords) >= 2, response_text
assert "best" not in _normalize(response_text)
assert "perfect" not in _normalize(response_text)
assert response.appointment_requested is False
assert response.show_booking_widget is False
|