visproj commited on
Commit
a50a85b
·
verified ·
1 Parent(s): 539ff7f

Update app.py

Browse files

switch to nlm db interactions

Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -14,23 +14,24 @@ from typing import Optional, Dict, Any
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  @tool
16
  def drug_interaction_checker(drug_1: str, drug_2: str) -> str:
17
- """Checks for potential interactions between two medications using the FDA Drug Label API.
18
 
19
  Args:
20
  drug_1: The name of the first drug.
21
  drug_2: The name of the second drug.
22
  """
23
- base_url = "https://api.fda.gov/drug/label.json"
24
- query = f'search=openfda.brand_name:"{drug_1}"+openfda.brand_name:"{drug_2}"'
25
- response = requests.get(f"{base_url}?{query}")
26
 
27
  if response.status_code == 200:
28
  data = response.json()
29
- if "results" in data and len(data["results"]) > 0:
30
- interactions = data["results"][0].get("drug_interactions", ["No known interactions found."])
31
- return f"⚠️ Drug Interaction Warning: {interactions[0]}"
32
- else:
33
- return " No interaction data found for these drugs."
 
34
  else:
35
  return f"❌ Error fetching interaction data: {response.status_code}"
36
 
 
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  @tool
16
  def drug_interaction_checker(drug_1: str, drug_2: str) -> str:
17
+ """Checks for potential interactions between two medications using the NLM Interaction API.
18
 
19
  Args:
20
  drug_1: The name of the first drug.
21
  drug_2: The name of the second drug.
22
  """
23
+ base_url = "https://rxnav.nlm.nih.gov/REST/interaction/list.json"
24
+ query = f"?rxcuis={drug_1}+{drug_2}"
25
+ response = requests.get(f"{base_url}{query}")
26
 
27
  if response.status_code == 200:
28
  data = response.json()
29
+ if "fullInteractionTypeGroup" in data:
30
+ interactions = data["fullInteractionTypeGroup"][0]["fullInteractionType"]
31
+ if interactions:
32
+ description = interactions[0]["interactionPair"][0]["description"]
33
+ return f"⚠️ Drug Interaction Warning: {description}"
34
+ return "✅ No interaction data found for these drugs."
35
  else:
36
  return f"❌ Error fetching interaction data: {response.status_code}"
37