| | |
| | 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()) |
| |
|