|
| 1 | +"""Golden-master snapshots for the trickiest vendor transformations. |
| 2 | +
|
| 3 | +These freeze to_config() output BEFORE the collapse refactor and must stay green |
| 4 | +throughout it. The broader tests/custom/test_*_vendors.py suite guards the rote |
| 5 | +classes; this file targets the classes with custom __init__, sample_rate logic, |
| 6 | +cross-vendor inheritance, or aliases. |
| 7 | +""" |
| 8 | +from agora_agent import ( |
| 9 | + DeepgramSTT, |
| 10 | + ElevenLabsTTS, |
| 11 | + GoogleTTS, |
| 12 | + OpenAITTS, |
| 13 | + OpenAI, |
| 14 | + Groq, |
| 15 | + CustomLLM, |
| 16 | + VertexAILLM, |
| 17 | +) |
| 18 | +from agora_agent.agentkit.vendors.cn import AliyunLLM, FengmingSTT, SenseTimeAvatar |
| 19 | +from agora_agent.agentkit.vendors.avatar import HeyGenAvatar |
| 20 | + |
| 21 | + |
| 22 | +def test_deepgram_stt_golden() -> None: |
| 23 | + cfg = DeepgramSTT(model="nova-3", language="en-US", smart_format=True).to_config() |
| 24 | + assert cfg == { |
| 25 | + "vendor": "deepgram", |
| 26 | + "params": {"model": "nova-3", "language": "en-US", "smart_format": True}, |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | +def test_elevenlabs_sample_rate_field_golden() -> None: |
| 31 | + tts = ElevenLabsTTS( |
| 32 | + key="k", model_id="eleven_flash_v2_5", voice_id="v", |
| 33 | + base_url="wss://api.elevenlabs.io/v1", sample_rate=24000, |
| 34 | + ) |
| 35 | + assert tts.sample_rate == 24000 |
| 36 | + assert tts.to_config()["params"]["sample_rate"] == 24000 |
| 37 | + |
| 38 | + |
| 39 | +def test_google_tts_sample_rate_hertz_golden() -> None: |
| 40 | + # GoogleTTS uses `key` for the credentials JSON string (not project_id/location/adc_credentials_string). |
| 41 | + tts = GoogleTTS( |
| 42 | + key="{}", voice_name="en-US-Neural2-A", language_code="en-US", sample_rate_hertz=16000, |
| 43 | + ) |
| 44 | + assert tts.sample_rate == 16000 |
| 45 | + assert tts.to_config()["params"]["AudioConfig"]["sample_rate_hertz"] == 16000 |
| 46 | + |
| 47 | + |
| 48 | +def test_openai_tts_fixed_sample_rate_golden() -> None: |
| 49 | + assert OpenAITTS(voice="alloy").sample_rate == 24000 |
| 50 | + |
| 51 | + |
| 52 | +def test_openai_llm_golden() -> None: |
| 53 | + cfg = OpenAI(model="gpt-4o-mini").to_config() |
| 54 | + assert cfg["style"] == "openai" |
| 55 | + assert cfg["params"]["model"] == "gpt-4o-mini" |
| 56 | + assert cfg["url"] == "https://api.openai.com/v1/chat/completions" |
| 57 | + |
| 58 | + |
| 59 | +def test_groq_golden() -> None: |
| 60 | + cfg = Groq(api_key="k", model="llama-3.3-70b-versatile", |
| 61 | + base_url="https://api.groq.com/openai/v1/chat/completions").to_config() |
| 62 | + assert cfg["url"] == "https://api.groq.com/openai/v1/chat/completions" |
| 63 | + assert cfg["style"] == "openai" |
| 64 | + assert cfg["params"]["model"] == "llama-3.3-70b-versatile" |
| 65 | + |
| 66 | + |
| 67 | +def test_custom_llm_golden() -> None: |
| 68 | + cfg = CustomLLM(api_key="k", model="m", base_url="https://x/chat").to_config() |
| 69 | + assert cfg["vendor"] == "custom" |
| 70 | + assert cfg["url"] == "https://x/chat" |
| 71 | + |
| 72 | + |
| 73 | +def test_vertexai_llm_golden() -> None: |
| 74 | + cfg = VertexAILLM(api_key="tok", project_id="proj", location="us-central1", |
| 75 | + model="gemini-1.5-pro").to_config() |
| 76 | + assert cfg["api_key"] == "tok" |
| 77 | + assert "us-central1-aiplatform.googleapis.com" in cfg["url"] |
| 78 | + |
| 79 | + |
| 80 | +def test_aliyun_llm_pins_vendor_golden() -> None: |
| 81 | + cfg = AliyunLLM(api_key="k", model="qwen-max", |
| 82 | + base_url="https://dashscope.example/chat").to_config() |
| 83 | + assert cfg["vendor"] == "aliyun" |
| 84 | + assert cfg["api_key"] == "k" |
| 85 | + |
| 86 | + |
| 87 | +def test_sensetime_avatar_camelcase_golden() -> None: |
| 88 | + # SenseTimeAvatarOptions uses alias "appId" for the app_id field; |
| 89 | + # pydantic v2 requires the alias keyword in the constructor. |
| 90 | + cfg = SenseTimeAvatar(agora_uid="2", appId="app", app_key="key").to_config() |
| 91 | + assert cfg["vendor"] == "sensetime" |
| 92 | + assert cfg["params"]["appId"] == "app" |
| 93 | + |
| 94 | + |
| 95 | +def test_heygen_avatar_golden() -> None: |
| 96 | + import warnings |
| 97 | + with warnings.catch_warnings(): |
| 98 | + warnings.simplefilter("ignore") |
| 99 | + cfg = HeyGenAvatar(api_key="k", quality="high", agora_uid="2").to_config() |
| 100 | + assert cfg["vendor"] == "heygen" |
| 101 | + |
| 102 | + |
| 103 | +def test_fengming_rejects_kwargs() -> None: |
| 104 | + import pytest |
| 105 | + with pytest.raises(TypeError): |
| 106 | + FengmingSTT(unexpected="x") |
| 107 | + assert FengmingSTT().to_config() == {"vendor": "fengming"} |
0 commit comments