hamnamughal commited on
Commit
da32aec
·
verified ·
1 Parent(s): e44e4d2

Update medication_agent.py

Browse files
Files changed (1) hide show
  1. medication_agent.py +11 -30
medication_agent.py CHANGED
@@ -1,30 +1,11 @@
1
- import datetime
2
- import openai
3
-
4
- openai.api_key = "your-openai-api-key"
5
-
6
- # Placeholder medication data
7
- medications = {}
8
-
9
- def set_medication_reminder(medicine: str, time: str):
10
- """Set a medication reminder."""
11
- reminder_id = str(datetime.datetime.now().timestamp())[:10]
12
- medications[reminder_id] = {"medicine": medicine, "time": time, "status": "Pending"}
13
- return f"Reminder set for {medicine} at {time}. Reminder ID: {reminder_id}"
14
-
15
- def mark_medication_taken(reminder_id: str):
16
- """Mark a medication as taken."""
17
- if reminder_id in medications:
18
- medications[reminder_id]["status"] = "Taken"
19
- return f"Medication {medications[reminder_id]['medicine']} marked as taken."
20
- return "Reminder not found."
21
-
22
- def suggest_medications(symptom: str):
23
- """Suggest medications based on symptoms."""
24
- # Query OpenAI GPT for suggestions based on symptom
25
- response = openai.Completion.create(
26
- model="gpt-3.5-turbo",
27
- prompt=f"Suggest medications for a patient with the symptom {symptom}.",
28
- max_tokens=150
29
- )
30
- return response.choices[0].text.strip().split("\n")
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
+
4
+ def get_medication_suggestions(symptom):
5
+ model_name = "m42-health/med42-70b"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+ prompt = f"Suggest medications for a patient with the symptom: {symptom}."
9
+ inputs = tokenizer(prompt, return_tensors="pt")
10
+ outputs = model.generate(**inputs, max_new_tokens=150)
11
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)