{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NCTIDAgentGradeTitleAgentJudgmentJapanes LocationsPrimary Completion DateCancerSummaryEligibility Criteria
0NCT06324357noBeamion BCGC-1: A Study to Find a Suitable Dos...The patient is not eligible for this clinical ...ku, shi2027-02-22Metastatic Breast Cancer, Metastatic Gastric A...This study is open to adults aged 18 years and...Inclusion Criteria:\\n\\n* Signed and dated writ...
1NCT06490055yesPredicting the Efficacy in Advanced Gastric Ca...The patient is eligible for this clinical tria...Kurashiki2025-12-31Gastric Cancer, Chemotherapy Effect, Paclitaxe...With advances in chemotherapy for gastric canc...Inclusion Criteria:\\n\\n1. unresectable or recu...
2NCT05002127unclearA Study of Evorpacept (ALX148) in Patients wit...The patient is eligible for this clinical tria...Chiba, Fukuoka, Gifu, Kumamoto, Kyoto, Nagasak...2026-07Gastric Cancer, Gastroesophageal Junction Aden...A Phase 2/3 Study of Evorpacept (ALX148) in Co...Inclusion Criteria:\\n\\n* HER2-overexpressing a...
3NCT04379596yesPh1b/2 Study of the Safety and Efficacy of T-D...The 65-year-old male patient with Stomach canc...Kashiwa, gun, ku, shi2026-07-30Gastric CancerDESTINY-Gastric03 will investigate the safety,...Inclusion criteria:\\n\\n1. Male and female part...
4NCT05205343yesTrans-Pacific Multicenter Collaborative Study ...The patient is eligible for this clinical tria...Tokyo2026-05-31Gastrostomy, Gastric, GastroEsophageal CancerTo compare the symptoms of patients who have a...Inclusion Criteria:\\n\\n1. Able to speak and re...
5NCT05365581yesA Study of ASP2138 Given by Itself or Given Wi...The patient is eligible for this clinical tria...Kashiwa, Nagoya, Osakasayama, Suita, Yokohama, ku2026-10-31Gastric Adenocarcinoma, Gastroesophageal Junct...Claudin 18.2 protein, or CLDN18.2 is a protein...Inclusion Criteria:\\n\\n* Participant is consid...
6NCT00197470unclearCytokine Gene Polymorphisms in Gastric DiseasesI do not know if the patient is eligible for t...HamamatsuUnknown DateGastric Ulcer, Duodenal Ulcer, Gastric CancerRecently, cytokine polymorphisms are considere...Inclusion Criteria:\\n\\n-\\n\\nExclusion Criteria...
7NCT06056024noA Study to Test How Well Different Doses of BI...The patient is not eligible for this clinical ...Kashiwa, ku2027-05-26Solid Tumor, KRAS MutationThis study is open to adults with advanced can...Inclusion Criteria:\\n\\n1. Patients with pathol...
8NCT05438459noGAIA-102 Intraperitoneal Administration in Pat...The patient is not eligible for this clinical ...shi2026-12-31Gastric Cancer, Pancreatic CancerPhase I Part :\\n\\nConfirm the safety of GAIA-1...Inclusion Criteria:\\n\\n1. Unresectable, advanc...
9NCT06490159yesPredicting Peripheral Neuropathy of Paclitaxel...The patient is eligible for this clinical tria...Kurashiki2025-12-31Gastric Cancer, Chemotherapy-induced Periphera...Although advances in chemotherapy have improve...Inclusion Criteria:\\n\\n1. unresectable or recu...
10NCT06038578noA Study of TRK-950 When Used in Combination Wi...The patient is not eligible for this clinical ...Chuo Ku, Kashiwa, Ku2025-08-31Gastric Adenocarcinoma, Gastric Cancer, Gastro...This study will assess the efficacy, safety, o...Inclusion Criteria:\\n\\n* Histologically or cyt...
11NCT05152147yesA Study of Zanidatamab in Combination With Che...The 65-year-old male patient with Stomach canc...Cho, Chuo Ku, Hirakata, Ina, Ku, Matsuyama, Na...2024-12-31Gastric Neoplasms, Gastroesophageal Adenocarci...This study is being done to find out if zanida...Inclusion Criteria:\\n\\n* Histologically confir...
12NCT05322577noA Study Evaluating Bemarituzumab in Combinatio...The patient is not eligible for this clinical ...Shi, gun, ku, shi2026-03-17Gastric Cancer, Gastroesophageal Junction CancerThe main objectives of this study are to evalu...Inclusion Criteria:\\n\\n* Adults with unresecta...
\n", "
" ], "text/plain": [ " NCTID AgentGrade Title \\\n", "0 NCT06324357 no Beamion BCGC-1: A Study to Find a Suitable Dos... \n", "1 NCT06490055 yes Predicting the Efficacy in Advanced Gastric Ca... \n", "2 NCT05002127 unclear A Study of Evorpacept (ALX148) in Patients wit... \n", "3 NCT04379596 yes Ph1b/2 Study of the Safety and Efficacy of T-D... \n", "4 NCT05205343 yes Trans-Pacific Multicenter Collaborative Study ... \n", "5 NCT05365581 yes A Study of ASP2138 Given by Itself or Given Wi... \n", "6 NCT00197470 unclear Cytokine Gene Polymorphisms in Gastric Diseases \n", "7 NCT06056024 no A Study to Test How Well Different Doses of BI... \n", "8 NCT05438459 no GAIA-102 Intraperitoneal Administration in Pat... \n", "9 NCT06490159 yes Predicting Peripheral Neuropathy of Paclitaxel... \n", "10 NCT06038578 no A Study of TRK-950 When Used in Combination Wi... \n", "11 NCT05152147 yes A Study of Zanidatamab in Combination With Che... \n", "12 NCT05322577 no A Study Evaluating Bemarituzumab in Combinatio... \n", "\n", " AgentJudgment \\\n", "0 The patient is not eligible for this clinical ... \n", "1 The patient is eligible for this clinical tria... \n", "2 The patient is eligible for this clinical tria... \n", "3 The 65-year-old male patient with Stomach canc... \n", "4 The patient is eligible for this clinical tria... \n", "5 The patient is eligible for this clinical tria... \n", "6 I do not know if the patient is eligible for t... \n", "7 The patient is not eligible for this clinical ... \n", "8 The patient is not eligible for this clinical ... \n", "9 The patient is eligible for this clinical tria... \n", "10 The patient is not eligible for this clinical ... \n", "11 The 65-year-old male patient with Stomach canc... \n", "12 The patient is not eligible for this clinical ... \n", "\n", " Japanes Locations Primary Completion Date \\\n", "0 ku, shi 2027-02-22 \n", "1 Kurashiki 2025-12-31 \n", "2 Chiba, Fukuoka, Gifu, Kumamoto, Kyoto, Nagasak... 2026-07 \n", "3 Kashiwa, gun, ku, shi 2026-07-30 \n", "4 Tokyo 2026-05-31 \n", "5 Kashiwa, Nagoya, Osakasayama, Suita, Yokohama, ku 2026-10-31 \n", "6 Hamamatsu Unknown Date \n", "7 Kashiwa, ku 2027-05-26 \n", "8 shi 2026-12-31 \n", "9 Kurashiki 2025-12-31 \n", "10 Chuo Ku, Kashiwa, Ku 2025-08-31 \n", "11 Cho, Chuo Ku, Hirakata, Ina, Ku, Matsuyama, Na... 2024-12-31 \n", "12 Shi, gun, ku, shi 2026-03-17 \n", "\n", " Cancer \\\n", "0 Metastatic Breast Cancer, Metastatic Gastric A... \n", "1 Gastric Cancer, Chemotherapy Effect, Paclitaxe... \n", "2 Gastric Cancer, Gastroesophageal Junction Aden... \n", "3 Gastric Cancer \n", "4 Gastrostomy, Gastric, GastroEsophageal Cancer \n", "5 Gastric Adenocarcinoma, Gastroesophageal Junct... \n", "6 Gastric Ulcer, Duodenal Ulcer, Gastric Cancer \n", "7 Solid Tumor, KRAS Mutation \n", "8 Gastric Cancer, Pancreatic Cancer \n", "9 Gastric Cancer, Chemotherapy-induced Periphera... \n", "10 Gastric Adenocarcinoma, Gastric Cancer, Gastro... \n", "11 Gastric Neoplasms, Gastroesophageal Adenocarci... \n", "12 Gastric Cancer, Gastroesophageal Junction Cancer \n", "\n", " Summary \\\n", "0 This study is open to adults aged 18 years and... \n", "1 With advances in chemotherapy for gastric canc... \n", "2 A Phase 2/3 Study of Evorpacept (ALX148) in Co... \n", "3 DESTINY-Gastric03 will investigate the safety,... \n", "4 To compare the symptoms of patients who have a... \n", "5 Claudin 18.2 protein, or CLDN18.2 is a protein... \n", "6 Recently, cytokine polymorphisms are considere... \n", "7 This study is open to adults with advanced can... \n", "8 Phase I Part :\\n\\nConfirm the safety of GAIA-1... \n", "9 Although advances in chemotherapy have improve... \n", "10 This study will assess the efficacy, safety, o... \n", "11 This study is being done to find out if zanida... \n", "12 The main objectives of this study are to evalu... \n", "\n", " Eligibility Criteria \n", "0 Inclusion Criteria:\\n\\n* Signed and dated writ... \n", "1 Inclusion Criteria:\\n\\n1. unresectable or recu... \n", "2 Inclusion Criteria:\\n\\n* HER2-overexpressing a... \n", "3 Inclusion criteria:\\n\\n1. Male and female part... \n", "4 Inclusion Criteria:\\n\\n1. Able to speak and re... \n", "5 Inclusion Criteria:\\n\\n* Participant is consid... \n", "6 Inclusion Criteria:\\n\\n-\\n\\nExclusion Criteria... \n", "7 Inclusion Criteria:\\n\\n1. Patients with pathol... \n", "8 Inclusion Criteria:\\n\\n1. Unresectable, advanc... \n", "9 Inclusion Criteria:\\n\\n1. unresectable or recu... \n", "10 Inclusion Criteria:\\n\\n* Histologically or cyt... \n", "11 Inclusion Criteria:\\n\\n* Histologically confir... \n", "12 Inclusion Criteria:\\n\\n* Adults with unresecta... " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "gradio", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }