first-aid-rag-assistant / notebooks / 03-clinical-data-gen.ipynb
03-clinical-data-gen.ipynb
Raw
import path_setup  # noqa: F401 — adds project root to sys.path

from ingest import load_faq_data

documents = load_faq_data()
from pydantic import BaseModel

class Questions(BaseModel):
    questions: list[str]
data_gen_instructions = """
    You are an expert medical software tester creating evaluation datasets.
    You are given one Questions and Answers Knowledge Base (QA KB).

    Generate 2 different realistic search queries a panicked, non-medical user might type into a search bar if they were experiencing this emergency right now.

    Rules:
    1. Do NOT use the exact medical titles or phrasing from the official question (e.g., avoid using the words 'pit viper' or 'coral snake' if possible).
    2. Use descriptive, frantic symptoms, slang, or layperson descriptions instead (e.g., 'a snake with red and yellow bands bit me' or 'got bit by a rattlesnake lookalike').
    3. Return your response strictly as a valid JSON list of strings.
    """
from dotenv import load_dotenv
from config import make_llm_client, MODEL_NAME

load_dotenv()

# 1. Initialize your client object with a model list
litellm_client = make_llm_client()


from concurrent.futures import ThreadPoolExecutor
from evaluation.evaluation_utils import map_progress
from evaluation.evaluation import generate_ground_truth


with ThreadPoolExecutor(max_workers=6) as pool:
    results = map_progress(
        pool,
        documents,
        generate_ground_truth,
        litellm_client,
        data_gen_instructions,
        Questions
    )

clinical_eval_set = []
for res in results:
    clinical_eval_set.extend(res)

len(clinical_eval_set)
clinical_eval_set[0:5]
import pandas as pd

df_ground_truth = pd.DataFrame(clinical_eval_set)

df_ground_truth.to_csv("data/clinical_eval_set.csv", index=False)