Spaces:
Configuration error
Configuration error
Download backend/tests/test_chat.py from Sivaneshakumar/sanjeevani-api: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/spaces/Sivaneshakumar/sanjeevani-api/resolve/main/backend/tests/test_chat.py
- Command line
-
hf download hf://spaces/Sivaneshakumar/sanjeevani-api/backend/tests/test_chat.py
-
curl -L -o test_chat.py https://huggingface.co/spaces/Sivaneshakumar/sanjeevani-api/resolve/main/backend/tests/test_chat.py
1.94 kB
| import pytest | |
| from httpx import AsyncClient | |
| async def test_ai_chat_consultation(client: AsyncClient, auth_headers: dict): | |
| payload = { | |
| "message": "What are typical lifestyle considerations for managing Type 2 Diabetes?" | |
| } | |
| response = await client.post("/api/v1/chat/message", headers=auth_headers, json=payload) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["success"] is True | |
| completion = data["data"] | |
| assert "conversation_id" in completion | |
| msg = completion["message"] | |
| assert msg["role"] == "assistant" | |
| assert msg["structured_data"] is not None | |
| assert len(msg["structured_data"]["possible_considerations"]) > 0 | |
| assert len(msg["structured_data"]["questions_for_doctor"]) > 0 | |
| assert msg["structured_data"]["is_emergency"] is False | |
| async def test_ai_chat_emergency_detection(client: AsyncClient, auth_headers: dict): | |
| payload = { | |
| "message": "I am having sudden severe chest pain and difficulty breathing!" | |
| } | |
| response = await client.post("/api/v1/chat/message", headers=auth_headers, json=payload) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| structured = data["data"]["message"]["structured_data"] | |
| assert structured["is_emergency"] is True | |
| assert "emergency" in structured["summary"].lower() or "emergency" in structured["safety_warning"].lower() | |
| async def test_chat_conversations_history(client: AsyncClient, auth_headers: dict): | |
| # Send a message to ensure conversation exists | |
| await client.post( | |
| "/api/v1/chat/message", | |
| headers=auth_headers, | |
| json={"message": "Can metformin cause vitamin B12 deficiency?"} | |
| ) | |
| response = await client.get("/api/v1/chat/conversations", headers=auth_headers) | |
| assert response.status_code == 200 | |
| convs = response.json()["data"] | |
| assert len(convs) >= 1 | |