Spaces:
Runtime error
Runtime error
Download tests/test_agents.py from rudhratej09/Eco-LLM-Carbon-Aware-LLM-Inference-Routing: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/rudhratej09/Eco-LLM-Carbon-Aware-LLM-Inference-Routing/resolve/main/tests/test_agents.py
- Command line
-
hf download hf://spaces/rudhratej09/Eco-LLM-Carbon-Aware-LLM-Inference-Routing/tests/test_agents.py
-
curl -L -o test_agents.py https://huggingface.co/spaces/rudhratej09/Eco-LLM-Carbon-Aware-LLM-Inference-Routing/resolve/main/tests/test_agents.py
1.51 kB
| """Unit tests for baseline agents.""" | |
| import pytest | |
| pytest.importorskip("openenv") | |
| from baseline import HeuristicRoutingAgent, RandomRoutingAgent | |
| from server.env import EcoLLMInferenceRoutingEnvironment | |
| from server.models import Strategy | |
| def test_random_agent_creates_valid_actions() -> None: | |
| """Random agent produces valid RLAction values.""" | |
| agent = RandomRoutingAgent() | |
| env = EcoLLMInferenceRoutingEnvironment() | |
| obs = env.reset(task_id="task_1") | |
| action = agent.get_action(obs) | |
| assert action.strategy is not None | |
| assert action.model_choice is not None | |
| assert isinstance(action.exit_flag, bool) | |
| def test_heuristic_agent_prefers_cache() -> None: | |
| """Heuristic agent should prioritize cache hits.""" | |
| agent = HeuristicRoutingAgent() | |
| env = EcoLLMInferenceRoutingEnvironment() | |
| obs = env.reset(task_id="task_1") | |
| obs.cache_contents.append(obs.query) | |
| action = agent.get_action(obs) | |
| assert action.strategy == Strategy.USE_CACHE | |
| def test_random_agent_deterministic_with_seed() -> None: | |
| """Random agent should be deterministic with the same seed.""" | |
| agent1 = RandomRoutingAgent(seed=42) | |
| agent2 = RandomRoutingAgent(seed=42) | |
| env = EcoLLMInferenceRoutingEnvironment() | |
| obs = env.reset(task_id="task_1") | |
| action1 = agent1.get_action(obs) | |
| action2 = agent2.get_action(obs) | |
| assert action1.strategy == action2.strategy | |
| assert action1.model_choice == action2.model_choice | |
| assert action1.exit_flag == action2.exit_flag | |