Skip to content

Commit 24e19d8

Browse files
committed
2 parents 2d232a7 + b53d957 commit 24e19d8

File tree

9 files changed

+585
-1
lines changed

9 files changed

+585
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
**/*.pyc
22
.venv/
3+
.env
34
.azure
45
__pycache__/
56
.coverage
7+
sample_data/

api.http

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
GET http://localhost:8000/generate_name
22

33
###
4-
GET http://localhost:8000/generate_name?starts_with=p
4+
GET http://localhost:8000/generate_name?starts_with=p
5+
6+
###
7+
POST http://localhost:8000/generate_plan
8+
Content-Type: application/json
9+
10+
{
11+
"drug": "ozempic",
12+
"rules": [
13+
{
14+
"name": "1.1",
15+
"value": "For patients requiring ongoing drug treatment for type 2 diabetes mellitus, submission of medical records (e.g., chart notes) confirming diagnosis of type 2 diabetes mellitus"
16+
},
17+
{
18+
"name": "1.2",
19+
"value": "A1C greater than or equal to 6.5% OR Fasting plasma glucose (FPG) greater than or equal to 126 mg/dL"
20+
}
21+
]
22+
}
23+
24+
###
25+
GET http://localhost:8000/get_plan?drug=ozempic

notebooks/rewoo.ipynb

Lines changed: 496 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/tools.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from langchain_core.tools import tool
2+
3+
@tool
4+
def get_patient_notes(patient_id: str):
5+
"""Get patient notes by patient ID."""
6+
return {
7+
"id": patient_id,
8+
"notes": "Patient was diagnosed with Type 2 diabetes on 2023-01-09. Patient has an A1C level of 9.5%."
9+
}
10+
11+
@tool
12+
def get_patient_data(patient_id: str):
13+
"""Get patient data by patient ID."""
14+
return {
15+
"id": patient_id,
16+
"name": "John Doe",
17+
"birthdate": "2010-01-05"
18+
}

src/api/agents/planner.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
prompt = """For the following rule, make plans that can validate a patient meets the criteria defined by the rule. For each plan, indicate \
2+
which external tool together with tool input to retrieve evidence. You can store the evidence into a \
3+
variable #E that can be called by later tools. (Plan, #E1, Plan, #E2, Plan, ...)
4+
5+
Tools can be one of the following:
6+
(1) ChartNotes[input]: Worker that searches for patient visit notes. Useful when you need to confirm a diagnosis or treatment.
7+
(2) PatientData[input]: Worker that searches for specific patient data. Useful when looking up patient data.
8+
(2) LLM[input]: A pretrained LLM like yourself. Useful when you need to act with general
9+
world knowledge and common sense. Prioritize it when you are confident in solving the problem
10+
yourself. Input can be any instruction.
11+
12+
For example,
13+
Rule: The outside air temperature must be below 32 degrees Fahrenheit in order for it to be snowing.
14+
Plan: Look up the outside air temperature. #E1 = WeatherData[lookup outside air temperature]
15+
16+
Begin!
17+
Describe your plans with rich details. Each Plan should be followed by only one #E.
18+
19+
Rule: {rule}"""
20+

src/api/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import random
22

3+
from pydantic import BaseModel
4+
from langchain_core.tools import tool
5+
from langgraph.checkpoint.memory import MemorySaver
6+
from langgraph.graph import END, START, StateGraph, MessagesState
7+
from langgraph.prebuilt import ToolNode
8+
39
import fastapi
410

511
from .data import names
612

713
app = fastapi.FastAPI()
814

15+
class plan_request(BaseModel):
16+
drug: str
17+
rules: list
918

1019
@app.get("/generate_name")
1120
async def generate_name(starts_with: str = None):
@@ -14,3 +23,11 @@ async def generate_name(starts_with: str = None):
1423
name_choices = [name for name in name_choices if name.lower().startswith(starts_with.lower())]
1524
random_name = random.choice(name_choices)
1625
return {"name": random_name}
26+
27+
@app.post("/generate_plan")
28+
async def generate_plan(request: plan_request):
29+
return {"plan": f"Take 1 of {request.drug} pill every 4 hours", "rules": request.rules}
30+
31+
@app.get("/get_plan")
32+
async def get_plan(drug: str):
33+
return {"plan": f"Take 1 pill of {drug} every 4 hours"}

src/api/tools/__init__.py

Whitespace-only changes.

src/api/tools/drug_rules.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# write a function to return a list of drug qualification rules
2+
def fetch_drug_rules(drug: str):
3+
return [
4+
{"rule": "Patient must be 18 years or older", "logical": "AND"},
5+
{"rule": "Patient must have a confirmed diagnosis of Type 2 diabetes", "logical": "AND"},
6+
{"rule": "Patient must have an A1C level of 7.0% or higher", "logical": "AND"}
7+
]
8+

src/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
fastapi==0.111.0
22
uvicorn[standard]==0.29.0
33
gunicorn==22.0.0
4+
langgraph
5+

0 commit comments

Comments
 (0)