Skip to content

Instantly share code, notes, and snippets.

@yoniLavi
Created March 8, 2023 22:50
Show Gist options
  • Select an option

  • Save yoniLavi/178a0f7f87dad51e73c909b14a01c6e9 to your computer and use it in GitHub Desktop.

Select an option

Save yoniLavi/178a0f7f87dad51e73c909b14a01c6e9 to your computer and use it in GitHub Desktop.
ChatGPT Physician's Assistant
"""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