Created
March 8, 2023 22:50
-
-
Save yoniLavi/178a0f7f87dad51e73c909b14a01c6e9 to your computer and use it in GitHub Desktop.
ChatGPT Physician's Assistant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """A first try at a ChatGPT diagnosing bot; it's definitely not production ready, but I'm amazed that this works""" | |
| import json | |
| import openai | |
| openai.api_key = "?" | |
| completion = openai.ChatCompletion.create( | |
| model='gpt-3.5-turbo', | |
| messages=[ | |
| {'role': 'user', 'content': ( | |
| 'Please behave as an automated physician"s assistant. I will give you a description of medical symptoms, and you will provide me with potential diagnoses matching those symptoms.' | |
| 'Our interaction will be in valid JSON format. Let\'s start.' | |
| )}, | |
| {'role': 'assistant', 'content': '\n\nSure, please begin providing json input.'}, | |
| {'role': 'user', 'content': ( | |
| '{"sex": "Male", "age": 40", "symptoms": ["38.5 degree centigrade fever", "Headache", "Chest pain", "Fatigue"]}' | |
| )}, | |
| {'role': 'assistant', 'content': ( | |
| '{"possible-diagnoses-in-order-of-decreasing-likelihood": ["Influenza", "Common cold", "Mononucleosis", "Strep throat", "Pneumonia", "Lyme disease"], "recommended-actions": ["Blood test", "Imaging", "Functional tests"]}' | |
| )}, | |
| {'role': 'user', 'content': ( | |
| '{"sex": "Female", "age": 32", "symptoms": ["Vomiting", "Abdominal pain", "Fatigue"]}' | |
| )}, | |
| ] | |
| ) | |
| response = json.loads(completion["choices"][0]["message"]["content"]) | |
| print("The patient likely suffers from one of the following:") | |
| for i, diagnosis in enumerate(response["possible-diagnoses-in-order-of-decreasing-likelihood"], 1): | |
| print(f" {i}: {diagnosis}") | |
| print("\n\nWe recommend the following actions:") | |
| for i, recommendation in enumerate(response["recommended-actions"], 1): | |
| print(f" {i}: {recommendation}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment