Spaces:
Configuration error
Configuration error
Download test_proxy_fix.py from Somraj-dev/AxioVital: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/Somraj-dev/AxioVital/resolve/main/test_proxy_fix.py
- Command line
-
hf download hf://spaces/Somraj-dev/AxioVital/test_proxy_fix.py
-
curl -L -o test_proxy_fix.py https://huggingface.co/spaces/Somraj-dev/AxioVital/resolve/main/test_proxy_fix.py
1.43 kB
| import os | |
| import asyncio | |
| import json | |
| from unittest.mock import MagicMock, patch | |
| # Mock the OpenAI client and httpx | |
| async def test_env_vars(): | |
| os.environ["API_BASE_URL"] = "https://mock-proxy.com/v1" | |
| os.environ["API_KEY"] = "sk-mock-key" | |
| os.environ["APP_URL"] = "http://localhost:7860" | |
| # Import inference after setting env vars | |
| import inference | |
| print(f"Inference API_BASE_URL: {inference.API_BASE_URL}") | |
| print(f"Inference API_KEY: {inference.API_KEY}") | |
| # Test run_inference mock call (intercept the OpenAI call) | |
| with patch("inference.OpenAI") as MockOpenAI: | |
| mock_client = MockOpenAI.return_value | |
| mock_completion = MagicMock() | |
| mock_completion.choices = [MagicMock()] | |
| mock_completion.choices[0].message.content = '{"risk_level": "HIGH", "risk_score": 0.85, "factors": [{"name": "BP", "severity": "high"}], "recommendations": ["See a doctor"]}' | |
| mock_client.chat.completions.create.return_value = mock_completion | |
| result = inference.run_inference({"hr": 100}) | |
| print(f"Inference Result: {result}") | |
| # Verify the client was initialized with the proxy URL | |
| MockOpenAI.assert_called_with(base_url="https://mock-proxy.com/v1", api_key="sk-mock-key") | |
| print("Verification Successful: OpenAI client initialized with proxy URL and key.") | |
| if __name__ == "__main__": | |
| asyncio.run(test_env_vars()) | |