10000 Nathan's branch by CodCodingCode · Pull Request #24 · CodCodingCode/AMIE-app · GitHub
[go: up one dir, main page]

Skip to content

Nathan's branch #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
39b65e7
Fixed diagnostic logic
CodCodingCode Jun 3, 2025
e87067f
added thinking and answer into json outputs
CodCodingCode Jun 7, 2025
3263a55
Update gen_convo.py
CodCodingCode Jun 7, 2025
24c54e5
testing prompt using specific vignette (there is a vignette issue wit…
CodCodingCode Jun 7, 2025
7acd9d2
fixed globalization issue
CodCodingCode Jun 7, 2025
7d12874
fixed defining function because of Extraction error
CodCodingCode Jun 7, 2025
da45f59
started new dataset generation
CodCodingCode Jun 7, 2025
b7d0088
generated new dataset
CodCodingCode Jun 8, 2025
7480df6
added deployment code to finally deploy model to website
CodCodingCode Jun 8, 2025
75e4726
Added print and break statements
CodCodingCode Jun 8, 2025
618a240
set up endpoint for the model - ALSMOT ABLE TO CONNECT TO FRONTEND
CodCodingCode Jun 8, 2025
71237bc
fixed major model thinking issue - tested model once again
CodCodingCode Jun 9, 2025
d1410fd
fixed prompting of the model. added openai caching
CodCodingCode Jun 9, 2025
1b3ada4
fixed prompting so that model would not hallucinate + changed summari…
CodCodingCode Jun 10, 2025
015032a
added new files
CodCodingCode Jun 10, 2025
9f58f7d
generated new interesting dataset
CodCodingCode Jun 11, 2025
9b07483
added reward for hallucination
CodCodingCode Jun 11, 2025
d8414af
Edited hallucination file - added patient training
CodCodingCode Jun 12, 2025
8ac87f5
fixed hallucination code fully.
CodCodingCode Jun 12, 2025
faebffa
created new endpoint to test full loop
CodCodingCode Jun 12, 2025
c2564aa
created code for trainin model to not hallucinate. Added multiple hal…
CodCodingCode Jun 12, 2025
222fa15
got rid of api keys lol
CodCodingCode Jun 12, 2025
2fca862
Changed prompting
CodCodingCode Jun 12, 2025
617ecfc
switched Diagnoer - changed patietn and summarizer logic
CodCodingCode Jun 12, 2025
dea890f
added further prompt enginerring to make model better
CodCodingCode Jun 12, 2025
3d89e46
added an evaluatoin meter than can easily evaluate the quality of the…
CodCodingCode Jun 12, 2025
a427988
debugging codebase for errors. added stirctness to evaluator. Made ev…
CodCodingCode Jun 13, 2025
0dea88b
Fixed file pathing for eval_data
CodCodingCode Jun 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
created code for trainin model to not hallucinate. Added multiple hal…
…lucinate scripts for all agents.
  • Loading branch information
CodCodingCode committed Jun 12, 2025
commit c2564aa3b8b11940ef7dc5e1e7a2beeea9477f45
3 changes: 1 addition & 2 deletions clinical_conversation_log.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"timestamp": "2025-06-12T12:06:31.688894",
"vignette": "A 58-year-old woman presents to the clinic with a 3-day history of progressively worsening lower left abdominal pain, described as sharp and constant. She reports associated low-grade fever, nausea, and decreased appetite but denies any vomiting. Her bowel habits have changed recently, alternating between constipation and occasional loose stools. She mentions a history of a low-fiber diet and chronic constipation over several years. On examination, tenderness localized to the left lower quadrant is noted without rebound or guarding. Laboratory evaluation reveals mild leukocytosis, and a CT scan of the abdomen confirms the presence of inflamed diverticula in the sigmoid colon consistent with acute diverticulitis. She denies any rectal bleeding or significant family history of colon disease. The patient is advised to start on a high-fiber diet once acute inflammation resolves and is prescribed antibiotics to manage the infection.",
"timestamp": "2025-06-12T13:15:22.176083",
"iterations": []
}
2 changes: 1 addition & 1 deletion new_data_gen/SFT /endpoint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# REPLACE THESE WITH YOUR ACTUAL VALUES
# ============================================================================
ENDPOINT_URL = "url" # Your endpoint URL from the screenshot
HF_TOKEN = "api" # Your HuggingFace token
HF_TOKEN = "token" # Your HuggingFace token


class HuggingFaceInference:
Expand Down
6 changes: 3 additions & 3 deletions new_data_gen/SFT /patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
def format_fn(example):
return {
"text": (
f"### Instruction:\nYou are a patient agent. Please act as if you are a real patient with the following vignette and conversation.\n\n"
f"### Input:\n{example['input']}\n\n"
f"### Output:\n{example['output']}"
f"instruction:\nYou are a patient agent. Please act as if you are a real patient with the following vignette and conversation.\n\n"
f"input:\n{example['input']}\n\n"
f"output:\n{example['output']}"
)
}

Expand Down
27 changes: 17 additions & 10 deletions new_data_gen/grpo_infra/Full_loop/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
# ============================================================================
# REPLACE THESE WITH YOUR ACTUAL VALUES
# ============================================================================
# Your JSON file with the vignettes
DOCTOR_ENDPOINT_URL = "https://pawaab86ddo00b8m.us-east-1.aws.endpoints.huggingface.cloud" # Your clinical/doctor model endpoint
PATIENT_ENDPOINT_URL = "https://b81l3ho0k7z27sip.us-east-1.aws.endpoints.huggingface.cloud" # Your patient agent model endpoint
HF_TOKEN = "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" # Your HuggingFace token
VIGNETTES_FILE = "new_data_gen/actual_data_gen/disease_vignettes_from_familydoctor.json" # Your JSON file with the vignettes


class HuggingFaceInference:
Expand Down Expand Up @@ -64,9 +67,9 @@ def generate(self, prompt, max_new_tokens=800):
def load_vignettes(filename):
"""Load vignettes from JSON file and select 2 per condition"""
try:
with open(filename, 'r') as f:
with open(filename, "r") as f:
data = json.load(f)

selected_vignettes = {}
for condition, vignettes in data.items():
cleaned_vignettes = []
Expand All @@ -78,8 +81,10 @@ def load_vignettes(filename):
cleaned_vignettes.append(str(vignette))
# Take only first 2 vignettes per condition
selected_vignettes[condition] = cleaned_vignettes[:2]
print(f"📋 Loaded {len(selected_vignettes[condition])} vignettes for {condition}")

print(
f"📋 Loaded {len(selected_vignettes[condition])} vignettes for {condition}"
)

return selected_vignettes
except FileNotFoundError:
print(f"❌ Vignettes file {filename} not found!")
Expand All @@ -88,23 +93,23 @@ def load_vignettes(filename):
print(f"❌ Invalid JSON in {filename}")
return {}


def get_random_vignette():
"""Get a random vignette from the loaded vignettes"""
vignettes_data = load_vignettes(VIGNETTES_FILE)
if not vignettes_data:
return "A patient presents with concerning symptoms.", "Unknown Condition"

# Get all vignettes from all conditions with their condition names
all_vignettes_with_conditions = []
for condition, vignettes in vignettes_data.items():
for vignette in vignettes:
all_vignettes_with_conditions.append((vignette, condition))

selected_vignette, condition = random.choice(all_vignettes_with_conditions)
return selected_vignette, condition



# JSON logging functionality
def save_to_json(data, filename="clinical_conversation_log.json"):
"""Save data to JSON file"""
Expand Down Expand Up @@ -187,7 +192,7 @@ def run_conversation():
convo = []
prev_questions = []
convo.append("Doctor: What brings you in today?")
patient_input = f"### Instruction:\nYou are a patient agent. Please act as if you are a real patient with the following vignette and conversation.\n\n### Input:\n{vignette}\n\n{question}\n\n### Output:" # MODIFIED THIS LINE
patient_input = f"Instruction:\nYou are a patient a 8000 gent. Please act as if you are a real patient with the following vignette and conversation.\n\n Input:\n{vignette}\n\n{question}\n\n Output: THINKING:" # MODIFIED THIS LINE
patient_response = patient_model.generate(
patient_input, max_new_tokens=700
) # Generate initial patient response
Expand Down Expand Up @@ -282,6 +287,7 @@ def run_conversation():
"thinking": thinking3,
"answer": answer3,
}
print(answer3)

doctor_output = answer3 if answer3 else raw_output
print("❓ Question Generation Output:")
Expand Down Expand Up @@ -313,7 +319,7 @@ def run_conversation():
save_conversation_state(conversation_log)
print(f"💾 Progress saved to clinical_conversation_log.json")

patient_input = f"### Instruction:\nYou are a patient agent. Please act as if you are a real patient with the following vignette and conversation.\n\n### Input:\n{vignette}\n\nCONVERSATION HISTORY:\n{chr(10).join(convo[-4:])}\n\nDOCTOR'S QUESTION: {doctor_output}\n\n### Output:" # MODIFIED THIS LINE
patient_input = f"instruction:\nYou are a patient agent. Please act as if you are a real patient with the following vignette and conversation.\n\n input:\n{vignette} {doctor_output} output: THINKING" # MODIFIED THIS LINE
patient_response = patient_model.generate(patient_input, max_new_tokens=700)
print("👤 Patient Response:", patient_response)
# Clean patient response
Expand All @@ -322,6 +328,7 @@ def run_conversation():
-1
].strip() # ADD THIS LINE
convo.append(f"Patient: {patient_response}")
print("Patient Response:", patient_response)
prev_vignette = output
question = doctor_output # Update question for next iteration

Expand Down
3 changes: 1 addition & 2 deletions new_data_gen/grpo_infra/Full_loop/tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

print("👤 Patient Response:", patient_response)
"
Loading
0