EhrAgent icon indicating copy to clipboard operation
EhrAgent copied to clipboard

How to run generated sql code ?

Open SamhithKakarla opened this issue 1 year ago • 9 comments

Hello,

I downloaded and ran your code from the repo. The ouput i get locally doesnt match the intended output from your demo: https://wshi83.github.io/EHR-Agent-page/ . Here we see that the EHR agent is not only able to generate the code but also successfully execute the code to get an answer. When i run your code locally i only get the SQL output but not the actual answer. The code is never executed.

I was wondering how i can run the generated code? could i be missing some configurations ?

Furthermore, In the demo the EHR agent also able successfully re-write the code in the case of errors how would i ensure this also happens locally ?

Thanks

SamhithKakarla avatar Jun 12 '24 02:06 SamhithKakarla

Hi Samhith,

Thank you for your interest in our work. Our code is designed to automatically generate a code-based solution plan and modify the answers accordingly based on specific questions. To address your issue, we recommend the following checks:

  • Use the GPT-4 (0613) version: Reimplement the results using this version, as it explicitly supports function calling. Additionally, ensure you are using pyautogen version 0.2.0, as our code is developed on top of AutoGen, which is rapidly evolving.

  • Run the provided tools: Execute python tabtools.py in the EhrAgent/tools/ directory. This allows you to test the defined tools and identify any issues. Specifically, for the SQL issue, un-comment Line 215 of tabtools.py to see if it resolves the problem.

All the demos shown on the project page are from the running logs of this code. If the settings are correct, you should get the same logs in YOUR_LOG_PATH.

I hope these suggestions help resolve your issue.

Best regards, EHRAgent Authors

night-chen avatar Jun 12 '24 06:06 night-chen

Hey, i was following your advise, when i tried running python3 tabtools.py i immediately run into the following issue: Screenshot 2024-06-15 at 4 40 32 PM

what is table_toolkits() ? i did a search for that symbol in your code and it was never defined and i ensured i have all the same imports aswell.

SamhithKakarla avatar Jun 16 '24 00:06 SamhithKakarla

Hi SamhithKakarla,

Those lines are commands from the previous version. You can try the following: data = db_loader("microbiologyevents") filtered_data = data_filter(data, "HADM_ID=107655") filtered_data = data_filter(filtered_data, "SPEC_TYPE_DESC=peripheral blood lymphocytes") values = get_value(filtered_data, 'CHARTTIME') sql_results = sql_interpreter("select max(t1.c1) from ( select sum(cost.cost) as c1 from cost where cost.hadm_id in ( select diagnoses_icd.hadm_id from diagnoses_icd where diagnoses_icd.icd9_code = ( select d_icd_diagnoses.icd9_code from d_icd_diagnoses where d_icd_diagnoses.short_title = 'comp-oth vasc dev/graft' ) ) and datetime(cost.chargetime) >= datetime(current_time,'-1 year') group by cost.hadm_id ) as t1")

You can try to substitute these commands with the original commands in the tabtools.py. And the target is to test if each of the tools can be executed correctly. If your issue has not been resolved, can you also offer the error information when you execute the main code?

Thank you!

Best, EHRAgent authors

night-chen avatar Jun 25 '24 05:06 night-chen

When running the code with gpt4 i get 1 of 2 errors : Error: ModuleNotFoundError("No module named 'tools'"). Please make modifications accordingly and make sure the rest code works well with the modification. Potential Reasons: The error message indicates that there is a missing module named 'tools'. However, the provided code does not seem to import or use a module named 'tools'. The error might be coming from one of the functions used in the code, possibly these functions are defined in another script where 'tools' module is not imported correctly. TERMINATE

or sometimes it will output the following:

exitcode: 1 (execution failed) Code output: Traceback (most recent call last): File "", line 2, in <module> patient_db = LoadDB('admissions') NameError: name 'LoadDB' is not defined

SamhithKakarla avatar Jun 25 '24 06:06 SamhithKakarla

Even after running spesifically with gpt-4-0613 i am still getting the following error:

Screenshot 2024-06-26 at 7 22 51 PM

please advise how to move forward.

SamhithKakarla avatar Jun 27 '24 02:06 SamhithKakarla

Hello SamhithKakarla, Maybe you can try to move tools folder into ehragent folder.

Currently, it is:

.
|---ehragent
|---scripts
|---tools

Change it to:

.
|---ehragent
|     |---tools
|---scripts

zlzGithub-0801 avatar Jul 19 '24 03:07 zlzGithub-0801

Just tried that. I also tried moving tabtools.py out of tools and directly into ehragent. That also produced the same error: Screenshot 2024-07-18 at 9 39 00 PM

SamhithKakarla avatar Jul 19 '24 04:07 SamhithKakarla

Finally got it working. Moving tools into the ehragent folder as mentioned above and un-installing tools fixed the issue!! I also had to remember to update the dataset path in tabtools.py. Thanks for the help !!

SamhithKakarla avatar Jul 19 '24 05:07 SamhithKakarla

Hi Samhith,

Thank you for your interest in our work. Our code is designed to automatically generate a code-based solution plan and modify the answers accordingly based on specific questions. To address your issue, we recommend the following checks:

  • Use the GPT-4 (0613) version: Reimplement the results using this version, as it explicitly supports function calling. Additionally, ensure you are using pyautogen version 0.2.0, as our code is developed on top of AutoGen, which is rapidly evolving.
  • Run the provided tools: Execute python tabtools.py in the EhrAgent/tools/ directory. This allows you to test the defined tools and identify any issues. Specifically, for the SQL issue, un-comment Line 215 of tabtools.py to see if it resolves the problem.

All the demos shown on the project page are from the running logs of this code. If the settings are correct, you should get the same logs in YOUR_LOG_PATH.

I hope these suggestions help resolve your issue.

Best regards, EHRAgent Authors

Could you kindly provide the dataset that has been divided according to complexity levels from Level I (the simplest) to Level IV (the most difficult)? Thank you very much

xx36805 avatar May 18 '25 07:05 xx36805