File size: 1,443 Bytes
78960a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# ai_assistant.py

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

# In ai_assistant.py

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