{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Fetching data from: https://clinicaltrials.gov/api/v2/studies?query.titles=Stomach cancer SEARCH[Location](AREA[LocationCountry]Japan AND AREA[LocationStatus]Recruiting)&pageSize=100\n" ] } ], "source": [ "from langchain_community.agent_toolkits import create_sql_agent\n", "from langchain_openai import ChatOpenAI\n", "from langchain_groq import ChatGroq\n", "from langchain_core.prompts import ChatPromptTemplate\n", "from langchain_core.pydantic_v1 import BaseModel, Field\n", "import pandas as pd\n", "from pydantic import BaseModel, Field\n", "\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "from langchain_community.vectorstores import Chroma\n", "from langchain.embeddings import HuggingFaceEmbeddings\n", "from langchain_core.runnables import RunnablePassthrough\n", "from langchain_core.output_parsers import StrOutputParser\n", "\n", "\n", "gpt = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)\n", "#agent_gpt_executor = create_sql_agent(gpt, db=db, agent_type=\"tool-calling\", verbose=True)\n", "\n", "## make database\n", "from langchain_community.utilities import SQLDatabase\n", "from sqlalchemy import create_engine\n", "\n", "from langchain.prompts import ChatPromptTemplate\n", "from langchain.schema import SystemMessage\n", "from langchain_core.prompts import MessagesPlaceholder\n", "#agent_groq_executor = create_sql_agent(llm, db=db, agent_type=\"tool-calling\", verbose=True)\n", "\n", "from OpenAITools.FetchTools import fetch_clinical_trials, fetch_clinical_trials_jp\n", "from OpenAITools.CrinicalTrialTools import QuestionModifierEnglish, TumorNameExtractor, SimpleClinicalTrialAgent,GraderAgent,LLMTranslator,generate_ex_question_English\n", "\n", "groq = ChatGroq(model_name=\"llama3-70b-8192\", temperature=0)\n", "#agent_groq_executor = create_sql_agent(groq, db=db, agent_type=\"tool-calling\", verbose=True)\n", "\n", "age = \"65\"\n", "sex =\"男性\"\n", "tumor_type =\"胃癌\"\n", "#tumor_type = \"gastric cancer\"\n", "GeneMutation =\"HER2\"\n", "Meseable = \"有り\"\n", "Biopsiable = \"有り\"\n", "NCTID = 'NCT06441994'\n", "\n", "#Define extractor\n", "Translator = LLMTranslator(groq)\n", "TumorName = Translator.translate(tumor_type)\n", "\n", "#Make db\n", "df = fetch_clinical_trials(TumorName)\n", "# 新しい列を追加\n", "df['AgentJudgment'] = None\n", "df['AgentGrade'] = None\n", "#df = df.iloc[:5, :]\n", "NCTIDs = list(df['NCTID' ])\n", "\n", "#Define agents\n", "#modifier = QuestionModifierEnglish(groq)\n", "CriteriaCheckAgent = SimpleClinicalTrialAgent(groq)\n", "grader_agent = GraderAgent(groq)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "ex_question = generate_ex_question_English(age, sex, TumorName, GeneMutation, Meseable, Biopsiable)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The patient is not eligible for this clinical trial because the trial is for metastatic breast cancer (mBC) or metastatic gastric adenocarcinoma, gastroesophageal junction adenocarcinoma, or esophageal adenocarcinoma (mGEAC), and the patient has stomach cancer, which is not explicitly mentioned in the inclusion criteria.\n", "no\n", "The patient is eligible for this clinical trial based on the provided information, as they meet the inclusion criteria (age, measurable tumor, biopsiable tumor, and HER2 gene mutation) and do not have any of the exclusion criteria mentioned.\n", "yes\n", "The patient is eligible for this clinical trial based on the provided information, as he has a known HER2 gene mutation and a measurable and biopsiable tumor. However, I do not know if he meets the other inclusion criteria, such as adequate bone marrow, renal, and liver function, and performance status.\n", "unclear\n", "The 65-year-old male patient with Stomach cancer is eligible for this clinical trial based on the provided criteria, as he meets the inclusion criteria (age, disease characteristics, measurable tumor, and HER2-positive status) and does not have any of the listed exclusion criteria.\n", "yes\n", "The patient is eligible for this clinical trial based on the provided criteria, as the patient has a biopsy-confirmed diagnosis of stomach cancer (gastric adenocarcinoma), is 65 years old (meeting the age criterion), and has a biopsiable tumor.\n", "yes\n", "The patient is eligible for this clinical trial based on the provided criteria. The patient meets the inclusion criteria for gastric/GEJ cancer, has a measurable tumor, and has a biopsiable tumor. The patient's HER2 mutation is not a exclusion criterion. However, the patient's age (65) is not explicitly mentioned as an inclusion or exclusion criterion, but it is likely that the patient is considered an adult according to local regulation.\n", "yes\n", "I do not know if the patient is eligible for this clinical trial because the criteria do not mention age or cancer type as inclusion or exclusion criteria, and there is no information about the patient's H. pylori status.\n", "unclear\n", "The patient is not eligible for this clinical trial because the patient's tumor has a HER2 mutation, whereas the trial requires a KRAS wild type (wt) amplification or a KRAS G12V mutation.\n", "no\n", "The patient is not eligible for this clinical trial because the patient has stomach cancer, but the trial is specific to gastric cancer with malignant ascites or pancreatic cancer with malignant ascites, and there is no mention of malignant ascites in the patient's condition.\n", "no\n", "The patient is eligible for this clinical trial based on the provided criteria, as they meet the inclusion criteria (unresectable or recurrent gastric cancer, age over 20, and measurable tumor) and do not have any of the exclusion criteria mentioned.\n", "yes\n", "The patient is not eligible for this clinical trial because the patient has a known HER2 gene mutation, and the exclusion criteria specifically state that HER2 positive gastric or GEJ adenocarcinoma is an exclusion criterion.\n", "no\n", "The 65-year-old male patient with Stomach cancer is eligible for this clinical trial based on the provided information, as he meets the inclusion criteria (HER2-positive, measurable tumor, and biopsiable tumor) and does not have any obvious exclusion criteria mentioned.\n", "yes\n", "The patient is not eligible for this clinical trial because they have a known HER2 gene mutation, which is an exclusion criterion.\n", "no\n" ] } ], "source": [ "for nct_id in NCTIDs:\n", " TargetCriteria = df.loc[df['NCTID'] == nct_id, 'Eligibility Criteria'].values[0]\n", " AgentJudgment = CriteriaCheckAgent.evaluate_eligibility(TargetCriteria, ex_question)\n", " print(AgentJudgment)\n", "\n", " AgentGrade = grader_agent.evaluate_eligibility(AgentJudgment)\n", " print(AgentGrade)\n", " # NCTIDに一致する行を見つけて更新\n", " df.loc[df['NCTID'] == nct_id, 'AgentJudgment'] = AgentJudgment\n", " df.loc[df['NCTID'] == nct_id, 'AgentGrade'] = AgentGrade" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ " # 列を指定した順に並び替え\n", "columns_order = ['NCTID', 'AgentGrade', 'Title', 'AgentJudgment', 'Japanes Locations', \n", " 'Primary Completion Date', 'Cancer', 'Summary', 'Eligibility Criteria']\n", "df = df[columns_order] " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | NCTID | \n", "AgentGrade | \n", "Title | \n", "AgentJudgment | \n", "Japanes Locations | \n", "Primary Completion Date | \n", "Cancer | \n", "Summary | \n", "Eligibility Criteria | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "NCT06324357 | \n", "no | \n", "Beamion BCGC-1: A Study to Find a Suitable Dos... | \n", "The patient is not eligible for this clinical ... | \n", "ku, shi | \n", "2027-02-22 | \n", "Metastatic Breast Cancer, Metastatic Gastric A... | \n", "This study is open to adults aged 18 years and... | \n", "Inclusion Criteria:\\n\\n* Signed and dated writ... | \n", "
1 | \n", "NCT06490055 | \n", "yes | \n", "Predicting the Efficacy in Advanced Gastric Ca... | \n", "The patient is eligible for this clinical tria... | \n", "Kurashiki | \n", "2025-12-31 | \n", "Gastric Cancer, Chemotherapy Effect, Paclitaxe... | \n", "With advances in chemotherapy for gastric canc... | \n", "Inclusion Criteria:\\n\\n1. unresectable or recu... | \n", "
2 | \n", "NCT05002127 | \n", "unclear | \n", "A Study of Evorpacept (ALX148) in Patients wit... | \n", "The patient is eligible for this clinical tria... | \n", "Chiba, Fukuoka, Gifu, Kumamoto, Kyoto, Nagasak... | \n", "2026-07 | \n", "Gastric Cancer, Gastroesophageal Junction Aden... | \n", "A Phase 2/3 Study of Evorpacept (ALX148) in Co... | \n", "Inclusion Criteria:\\n\\n* HER2-overexpressing a... | \n", "
3 | \n", "NCT04379596 | \n", "yes | \n", "Ph1b/2 Study of the Safety and Efficacy of T-D... | \n", "The 65-year-old male patient with Stomach canc... | \n", "Kashiwa, gun, ku, shi | \n", "2026-07-30 | \n", "Gastric Cancer | \n", "DESTINY-Gastric03 will investigate the safety,... | \n", "Inclusion criteria:\\n\\n1. Male and female part... | \n", "
4 | \n", "NCT05205343 | \n", "yes | \n", "Trans-Pacific Multicenter Collaborative Study ... | \n", "The patient is eligible for this clinical tria... | \n", "Tokyo | \n", "2026-05-31 | \n", "Gastrostomy, Gastric, GastroEsophageal Cancer | \n", "To compare the symptoms of patients who have a... | \n", "Inclusion Criteria:\\n\\n1. Able to speak and re... | \n", "
5 | \n", "NCT05365581 | \n", "yes | \n", "A Study of ASP2138 Given by Itself or Given Wi... | \n", "The patient is eligible for this clinical tria... | \n", "Kashiwa, Nagoya, Osakasayama, Suita, Yokohama, ku | \n", "2026-10-31 | \n", "Gastric Adenocarcinoma, Gastroesophageal Junct... | \n", "Claudin 18.2 protein, or CLDN18.2 is a protein... | \n", "Inclusion Criteria:\\n\\n* Participant is consid... | \n", "
6 | \n", "NCT00197470 | \n", "unclear | \n", "Cytokine Gene Polymorphisms in Gastric Diseases | \n", "I do not know if the patient is eligible for t... | \n", "Hamamatsu | \n", "Unknown Date | \n", "Gastric Ulcer, Duodenal Ulcer, Gastric Cancer | \n", "Recently, cytokine polymorphisms are considere... | \n", "Inclusion Criteria:\\n\\n-\\n\\nExclusion Criteria... | \n", "
7 | \n", "NCT06056024 | \n", "no | \n", "A Study to Test How Well Different Doses of BI... | \n", "The patient is not eligible for this clinical ... | \n", "Kashiwa, ku | \n", "2027-05-26 | \n", "Solid Tumor, KRAS Mutation | \n", "This study is open to adults with advanced can... | \n", "Inclusion Criteria:\\n\\n1. Patients with pathol... | \n", "
8 | \n", "NCT05438459 | \n", "no | \n", "GAIA-102 Intraperitoneal Administration in Pat... | \n", "The patient is not eligible for this clinical ... | \n", "shi | \n", "2026-12-31 | \n", "Gastric Cancer, Pancreatic Cancer | \n", "Phase I Part :\\n\\nConfirm the safety of GAIA-1... | \n", "Inclusion Criteria:\\n\\n1. Unresectable, advanc... | \n", "
9 | \n", "NCT06490159 | \n", "yes | \n", "Predicting Peripheral Neuropathy of Paclitaxel... | \n", "The patient is eligible for this clinical tria... | \n", "Kurashiki | \n", "2025-12-31 | \n", "Gastric Cancer, Chemotherapy-induced Periphera... | \n", "Although advances in chemotherapy have improve... | \n", "Inclusion Criteria:\\n\\n1. unresectable or recu... | \n", "
10 | \n", "NCT06038578 | \n", "no | \n", "A Study of TRK-950 When Used in Combination Wi... | \n", "The patient is not eligible for this clinical ... | \n", "Chuo Ku, Kashiwa, Ku | \n", "2025-08-31 | \n", "Gastric Adenocarcinoma, Gastric Cancer, Gastro... | \n", "This study will assess the efficacy, safety, o... | \n", "Inclusion Criteria:\\n\\n* Histologically or cyt... | \n", "
11 | \n", "NCT05152147 | \n", "yes | \n", "A Study of Zanidatamab in Combination With Che... | \n", "The 65-year-old male patient with Stomach canc... | \n", "Cho, Chuo Ku, Hirakata, Ina, Ku, Matsuyama, Na... | \n", "2024-12-31 | \n", "Gastric Neoplasms, Gastroesophageal Adenocarci... | \n", "This study is being done to find out if zanida... | \n", "Inclusion Criteria:\\n\\n* Histologically confir... | \n", "
12 | \n", "NCT05322577 | \n", "no | \n", "A Study Evaluating Bemarituzumab in Combinatio... | \n", "The patient is not eligible for this clinical ... | \n", "Shi, gun, ku, shi | \n", "2026-03-17 | \n", "Gastric Cancer, Gastroesophageal Junction Cancer | \n", "The main objectives of this study are to evalu... | \n", "Inclusion Criteria:\\n\\n* Adults with unresecta... | \n", "