Spaces:
Sleeping
Sleeping
Download tests/test_inference.py from Neetu143/meta_hackathon: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/Neetu143/meta_hackathon/resolve/main/tests/test_inference.py
- Command line
-
hf download hf://spaces/Neetu143/meta_hackathon/tests/test_inference.py
-
curl -L -o test_inference.py https://huggingface.co/spaces/Neetu143/meta_hackathon/resolve/main/tests/test_inference.py
2.61 kB
| import importlib | |
| import sys | |
| from support_triage_env.environment import SupportTriageCoreEnvironment | |
| def _load_inference(monkeypatch): | |
| monkeypatch.delenv("OPENAI_API_KEY", raising=False) | |
| monkeypatch.setenv("HF_TOKEN", "test-token") | |
| monkeypatch.setenv("API_BASE_URL", "https://api.openai.com/v1") | |
| monkeypatch.setenv("MODEL_NAME", "test-model") | |
| sys.modules.pop("inference", None) | |
| return importlib.import_module("inference") | |
| def test_parse_action_accepts_wrapped_json(monkeypatch): | |
| inference = _load_inference(monkeypatch) | |
| action = inference._parse_action( | |
| "Use this action:\n```json\n{\"action_type\":\"submit\",\"value\":null}\n```" | |
| ) | |
| assert action.action_type == "submit" | |
| assert action.value is None | |
| def test_rule_based_fallback_solves_all_default_tasks(monkeypatch, capsys): | |
| inference = _load_inference(monkeypatch) | |
| def _raise_provider_error(prompt: str): | |
| del prompt | |
| raise RuntimeError("provider unavailable") | |
| monkeypatch.setattr(inference, "_request_action_with_tools", _raise_provider_error) | |
| monkeypatch.setattr(inference, "_request_action_with_json", _raise_provider_error) | |
| for task_id in ("billing_duplicate_charge", "shipping_damaged_replacement", "account_takeover_fraud"): | |
| success, rewards = inference._run_task(task_id) | |
| output = capsys.readouterr().out | |
| assert success is True | |
| assert rewards | |
| assert f"[START] task={task_id} env=support_triage_env model=test-model" in output | |
| assert "[END] success=true" in output | |
| assert "score=0.99" in output | |
| def test_strategy_handles_seeded_billing_variant(monkeypatch): | |
| inference = _load_inference(monkeypatch) | |
| env = SupportTriageCoreEnvironment() | |
| observation = env.reset(task_id="billing_duplicate_charge", seed=1) | |
| while not observation.done: | |
| action = inference._planned_action(observation) | |
| result = env.step(action) | |
| observation = result.observation | |
| state = env.state() | |
| assert state.submitted is True | |
| assert 0.98 < state.completion_score < 1.0 | |
| assert state.workspace.status == "resolved" | |
| assert "auth_hold" in state.workspace.tags | |
| def test_inference_accepts_openai_api_key(monkeypatch): | |
| monkeypatch.delenv("HF_TOKEN", raising=False) | |
| monkeypatch.setenv("OPENAI_API_KEY", "sk-test") | |
| monkeypatch.setenv("API_BASE_URL", "https://api.openai.com/v1") | |
| monkeypatch.setenv("MODEL_NAME", "test-model") | |
| sys.modules.pop("inference", None) | |
| inference = importlib.import_module("inference") | |
| assert inference.API_KEY == "sk-test" | |