|
|
|
|
|
from openai import OpenAI |
|
import re |
|
|
|
def initialize_openai_client(api_key, base_url): |
|
"""Initialize the OpenAI client.""" |
|
return OpenAI(api_key=api_key, base_url=base_url) |
|
|
|
def generate_system_message(current_organism, current_antibiotic, current_was_positive): |
|
"""Generate a dynamic system message for the AI Assistant.""" |
|
system_message = """ |
|
You are a clinical microbiology AI assistant. Analyze susceptibility results considering: |
|
1) Model predictions 2) CLSI/EUCAST guidelines 3) Local resistance patterns. |
|
Provide: Interpretation, therapy options, resistance mechanisms, and infection control measures. |
|
""" |
|
|
|
if all([current_organism, current_antibiotic, current_was_positive is not None]): |
|
system_message += f""" |
|
CONTEXTUAL NOTES: |
|
- Current organism: {current_organism} |
|
- Current antibiotic: {current_antibiotic} |
|
- Culture positivity: {'Positive' if current_was_positive else 'Negative'} |
|
""" |
|
|
|
return system_message |
|
|
|
|
|
|
|
def get_ai_response(client, prompt): |
|
"""Get a response from the AI Assistant.""" |
|
response = client.chat.completions.create( |
|
model="deepseek-chat", |
|
messages=[ |
|
{"role": "system", "content": "You are a clinical microbiology AI assistant."}, |
|
{"role": "user", "content": prompt} |
|
] |
|
).choices[0].message.content |
|
return response |