Download script/test_support_check.py from shahidul034/readctrl: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/shahidul034/readctrl/resolve/9f813643ecd2eecc1100086fab052d9c59ac09e5/script/test_support_check.py
- Command line
-
hf download hf://shahidul034/readctrl@9f813643ecd2eecc1100086fab052d9c59ac09e5/script/test_support_check.py
-
curl -L -o test_support_check.py https://huggingface.co/shahidul034/readctrl/resolve/9f813643ecd2eecc1100086fab052d9c59ac09e5/script/test_support_check.py
2 kB
| #!/usr/bin/env python3 | |
| import json | |
| import sys | |
| import urllib.request | |
| import urllib.error | |
| BASE_URL = "http://172.16.34.21:8086" | |
| MODEL = "support_check" | |
| QUESTIONS = [ | |
| "Is the claim 'Regular exercise improves cardiovascular health' supported by evidence?", | |
| "Does the statement 'Vitamin C cures the common cold' have strong scientific support?", | |
| "Is it true that 'The Earth is flat'?", | |
| "Can you verify the claim: 'Smoking increases the risk of lung cancer'?", | |
| "Is the claim 'Drinking 8 glasses of water daily is required for everyone' universally supported?", | |
| ] | |
| def post_chat_completion(prompt: str) -> dict: | |
| url = f"{BASE_URL}/v1/chat/completions" | |
| payload = { | |
| "model": MODEL, | |
| "temperature": 0.2, | |
| "max_tokens": 256, | |
| "messages": [ | |
| {"role": "system", "content": "Answer succinctly."}, | |
| {"role": "user", "content": prompt}, | |
| ], | |
| } | |
| data = json.dumps(payload).encode("utf-8") | |
| req = urllib.request.Request( | |
| url, | |
| data=data, | |
| headers={"Content-Type": "application/json"}, | |
| method="POST", | |
| ) | |
| try: | |
| with urllib.request.urlopen(req, timeout=120) as resp: | |
| body = resp.read().decode("utf-8") | |
| return json.loads(body) | |
| except urllib.error.HTTPError as exc: | |
| body = exc.read().decode("utf-8") if exc.fp else "" | |
| raise RuntimeError(f"HTTP {exc.code}: {body}") from exc | |
| except urllib.error.URLError as exc: | |
| raise RuntimeError(f"Request failed: {exc.reason}") from exc | |
| def main() -> int: | |
| for idx, question in enumerate(QUESTIONS, start=1): | |
| print(f"\nQ{idx}: {question}") | |
| result = post_chat_completion(question) | |
| try: | |
| answer = result["choices"][0]["message"]["content"] | |
| except (KeyError, IndexError, TypeError): | |
| answer = json.dumps(result, ensure_ascii=True) | |
| print(f"A{idx}: {answer}") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |