File size: 2,516 Bytes
40d6b91
 
 
f2ef3e5
40d6b91
 
 
4f6fe3d
d33c542
 
40d6b91
 
 
 
 
 
 
 
 
 
 
 
 
 
d33c542
40d6b91
 
935527a
 
 
d33c542
40d6b91
e37e892
 
 
 
4f6fe3d
8d5e03b
 
 
 
 
 
40d6b91
 
 
8d5e03b
40d6b91
 
 
 
 
 
 
 
 
 
 
74631f7
40d6b91
74631f7
204da4c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from openai import OpenAI

# Initialiser le client OpenAI
client = OpenAI(
    base_url="https://integrate.api.nvidia.com/v1",
    api_key="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"
)

# Définir les prompts
DEFAULT_PROMPT2 = """You are Kittycara, a friendly AI assistant designed to help adolescent girls and their caretakers understand menstrual health. 
Your goal is to provide support, information, and potential diagnoses based on the symptoms provided. Remember to be sensitive, supportive, and 
encourage seeking professional medical advice when necessary. Always maintain a friendly and approachable tone, as if you were a caring pet cat.
Always explain medical terms in a way that is easy to understand. For example, if you mention "menstruation," explain it as 'the monthly bleeding women experience as part of their reproductive cycle.'
If asked about topics outside of menstrual health or medical information, politely state that you're not able to discuss those subjects 
and redirect the conversation to menstrual health concerns. Always encourage seeking professional medical advice for specific diagnoses or treatments."""

SYMPTOMS = [
    "Heavy bleeding", "Irregular periods", "Painful periods", "Missed periods",
    "Spotting between periods", "Mood swings", "Fatigue", "Abdominal pain",
    "Nausea", "Headaches", "Breast tenderness", "Acne"
]


# Initialiser l'application FastAPI
app = FastAPI()
class RequestData(BaseModel):
    message: str


# Fonction pour obtenir un message personnalisé basé sur les symptômes
@app.get("/")
async def home():
    return 'kitty'
@app.post("/analyze")
def predict(request: RequestData):
    # Construire la liste de messages
    prompt = [
        {"role": "system", "content": DEFAULT_PROMPT2},
        {"role": "user", "content": request.message}
    ]
    
    try:
        completion = client.chat.completions.create(
            model="meta/llama-3.1-8b-instruct",
            messages=prompt,  # Envoyer la liste de messages
            temperature=0.2,
            top_p=0.9,
            max_tokens=1024,
            stream=True
        )

        full_response = ""
        for chunk in completion:
            if chunk.choices[0].delta.content is not None:
                full_response += chunk.choices[0].delta.content

        return {"response": full_response}

    except Exception as e:
        return {"error": f"Erreur : {str(e)}"}