Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2705 commits
Select commit Hold shift + click to select a range
a75486c
Update Implied-susceptibility.sql
fatemeh91 Oct 8, 2024
2fdb755
Update Implied-susceptibility.sql
fatemeh91 Oct 8, 2024
7c3b26f
add tutorial on running open-weight LLMs on remote GPUs
fcgrolleau Oct 11, 2024
217d492
Merge branch 'master' of https://github.com/HealthRex/CDSS
fcgrolleau Oct 11, 2024
83f5fed
add tutorial on running open-weight LLMs on remote GPUs
fcgrolleau Oct 11, 2024
801e786
Update webAppSetupNotes.txt
jonc101 Oct 15, 2024
461557b
Update web app setup notes to reflect current steps to revive recomme…
jonc101 Oct 16, 2024
711b783
Make recommender algorithm interface more robust to excessive exclusi…
jonc101 Oct 16, 2024
827b470
update tuto to prevent external IP from changing with VM restart
fcgrolleau Oct 17, 2024
30228fc
Merge branch 'master' of https://github.com/HealthRex/CDSS
fcgrolleau Oct 17, 2024
035a126
back to v1 tuto
fcgrolleau Oct 17, 2024
3e020dd
update tuto to prevent external IP from changing with VM restart
fcgrolleau Oct 17, 2024
ebb843c
tuto fix typos from last update
fcgrolleau Oct 17, 2024
70f33ab
edit gemma prompt formating + fix typos
fcgrolleau Oct 18, 2024
f44ef8a
edit gemma prompt formating + fix typos
fcgrolleau Oct 18, 2024
0fc349a
Updated web app notes to reflect evolving package and version numbers
jonc101 Oct 20, 2024
c6ac09e
Merge branch 'master' of https://github.com/HealthRex/CDSS
jonc101 Oct 20, 2024
21495b2
add link to llama 3.2 in keras tutorial
fcgrolleau Oct 21, 2024
5e5cfd4
add link to llama 3.2 in keras tutorial
fcgrolleau Oct 21, 2024
6120010
Update Antibiotic name microbiology_cultures_cohort_query.sql
fatemeh91 Oct 22, 2024
6a27e4c
Update microbiology_cultures_cohort_query.sql
fatemeh91 Oct 23, 2024
28c9074
Update medication_exposure.sql
fatemeh91 Oct 23, 2024
89bb2b5
Create Public_Data_Release_Guide.md
FatemeNateghi Oct 23, 2024
7c1fe22
Update Public_Data_Release_Guide.md
FatemeNateghi Oct 23, 2024
a63693d
Update Public_Data_Release_Guide.md
FatemeNateghi Oct 23, 2024
9548bf2
Update Public_Data_Release_Guide.md
FatemeNateghi Oct 23, 2024
d934ade
Merge branch 'master' of https://github.com/HealthRex/CDSS
fcgrolleau Oct 25, 2024
fff325b
add submodule discharge_sum_proj
fcgrolleau Oct 25, 2024
0dc997c
Removed submodule discharge_sum_proj
fcgrolleau Oct 25, 2024
f3e2e89
Note about Apache not seeing local user installed modules
jonc101 Oct 28, 2024
8602b37
Update webAppSetupNotes.txt
FatemeNateghi Oct 28, 2024
e064bd9
Create Google Form rubrics for discharge summaries, to be populated b…
fcgrolleau Oct 31, 2024
58d3b8e
Update comorbidities.sql
fatemeh91 Oct 31, 2024
1baa275
Create Labs.sql
fatemeh91 Nov 19, 2024
5b3067c
Update Labs.sql
fatemeh91 Nov 19, 2024
05b79c6
Update Labs.sql
fatemeh91 Nov 19, 2024
ad1122d
Update Labs.sql
fatemeh91 Nov 19, 2024
8427d48
Create Vitals.sql
fatemeh91 Nov 19, 2024
67f6aec
Update Vitals.sql
fatemeh91 Nov 21, 2024
308147b
Update Labs.sql
fatemeh91 Nov 21, 2024
2bed20e
Create Aim 1b
FatemeNateghi Nov 21, 2024
7966f7a
Delete scripts/antibiotic-susceptibility/Aim 1b
FatemeNateghi Nov 21, 2024
379d53e
Create README.md
FatemeNateghi Nov 21, 2024
ac4ebae
Update README.md
FatemeNateghi Nov 21, 2024
a817698
DCeval frontend v1: prefilling w llama3, google JS files, etc.
fcgrolleau Nov 25, 2024
a2926e0
Add files via upload
arinvansomphone Nov 26, 2024
3792923
Add tutorial on causal inference and estimation theory
fcgrolleau Dec 5, 2024
17e72f0
add tutorial link to colab
fcgrolleau Dec 5, 2024
bcc22d6
increase no. hidden units to 5 in the nuisance MLP
fcgrolleau Dec 5, 2024
f44c74c
Add files via upload
arinvansomphone Dec 10, 2024
afac9b9
update ssh gpu-VM tuto
fcgrolleau Dec 12, 2024
21d4100
fix the susceptibility
fatemeh91 Dec 13, 2024
6fd98e8
fix the susceptibility
fatemeh91 Dec 13, 2024
37a370a
susceptibility categories
FatemeNateghi Dec 17, 2024
263c4cf
Update Implied-susceptibility.sql
fatemeh91 Dec 19, 2024
2b5810d
Update Implied-susceptibility.sql
fatemeh91 Dec 19, 2024
6ac4b88
Update __init__.py
gracek012 Dec 27, 2024
48d8355
Update cosmos.py
gracek012 Dec 27, 2024
3be1762
Create deploy.py
gracek012 Dec 27, 2024
4097d36
Update orderInfo.py
gracek012 Dec 27, 2024
bfedd25
Update order_action.py
gracek012 Dec 27, 2024
c867971
Update and rename emailParser.py to train_model.py
gracek012 Dec 27, 2024
b2fb07e
Add files via upload
gracek012 Dec 27, 2024
33221b2
Update README.md
gracek012 Dec 27, 2024
cc4b198
Add files via upload
gracek012 Dec 27, 2024
7a8f7b5
Model version 2
arinvansomphone Jan 9, 2025
b200dff
Delete scripts/antibiotic-susceptibility/Aim1b/main.py
arinvansomphone Jan 9, 2025
b6220ac
Update microbiology_cultures_adi_scores.sql
FatemeNateghi Jan 10, 2025
28f6692
update causal inference tuto: proofs + coverage
fcgrolleau Jan 14, 2025
00c4402
add interpretation for coverage figure and fix parallel processing on…
fcgrolleau Jan 14, 2025
9995fc0
add html read only tuto
fcgrolleau Jan 14, 2025
eedf0c3
fix AIPW proof & update readme & html
fcgrolleau Jan 15, 2025
9d35c45
update readme html & tuto proofs
fcgrolleau Jan 16, 2025
3b1ecd8
Add files via upload
arinvansomphone Jan 19, 2025
1628919
Add files via upload
FatemeNateghi Jan 24, 2025
b527114
Delete scripts/OUDTreatmentRetentionVSAttrition/WebApp directory
FatemeNateghi Jan 24, 2025
4eede18
Create README.md
FatemeNateghi Jan 24, 2025
834ceeb
Added WebApp files to the OUDTreatmentRetentionVSAttrition/WebApp dir…
FatemeNateghi Jan 27, 2025
9464ccd
Update requirements.txt
FatemeNateghi Jan 27, 2025
27b9ad4
upload tuto on PHI-safe LLM APIs
fcgrolleau Jan 27, 2025
6c27aad
Update requirements.txt
FatemeNateghi Jan 27, 2025
0946d19
Update requirements.txt
FatemeNateghi Jan 27, 2025
8cdae65
Update requirements.txt
FatemeNateghi Jan 27, 2025
03e2c8e
Update requirements.txt
FatemeNateghi Jan 27, 2025
2559c33
Update requirements.txt
FatemeNateghi Jan 27, 2025
1fd663f
Update requirements.txt
FatemeNateghi Jan 27, 2025
479119d
Update requirements.txt
FatemeNateghi Jan 27, 2025
a0d055d
Update requirements.txt
FatemeNateghi Jan 27, 2025
b1c3595
Update app.py
FatemeNateghi Jan 27, 2025
3c42399
Update app.py
FatemeNateghi Jan 27, 2025
4864240
Update requirements.txt
FatemeNateghi Jan 27, 2025
d2d3d8f
Update requirements.txt
FatemeNateghi Jan 27, 2025
a569252
Update requirements.txt
FatemeNateghi Jan 27, 2025
8c66db4
Update requirements.txt
FatemeNateghi Jan 27, 2025
f53c196
update PHI-safe LLM API tuto prerequisites
fcgrolleau Jan 27, 2025
32cebf3
Merge branch 'master' of https://github.com/HealthRex/CDSS
fcgrolleau Jan 27, 2025
2500ff1
Update requirements.txt
FatemeNateghi Jan 27, 2025
56dc14a
Update requirements.txt
FatemeNateghi Jan 27, 2025
bc9c964
Update requirements.txt
FatemeNateghi Jan 27, 2025
4c2c6b6
Update requirements.txt
FatemeNateghi Jan 27, 2025
89ba0f0
Added WebApp folder contents to OUDTreatmentRetentionVSAttrition
FatemeNateghi Jan 27, 2025
9802dfe
Delete scripts/OUDTreatmentRetentionVSAttrition/WebApp/Users/fateme/L…
FatemeNateghi Jan 27, 2025
f217a4c
Added WebApp folder contents to OUDTreatmentRetentionVSAttrition
FatemeNateghi Jan 27, 2025
5ef3f7b
Delete scripts/OUDTreatmentRetentionVSAttrition/WebApp/Users/fateme/L…
FatemeNateghi Jan 27, 2025
5b1f83a
Add files via upload
FatemeNateghi Jan 27, 2025
74e903b
Update requirements.txt
FatemeNateghi Jan 27, 2025
2b4451c
Update requirements.txt
FatemeNateghi Jan 27, 2025
7a36bdf
Update requirements.txt
FatemeNateghi Jan 27, 2025
a6b6cb4
Update requirements.txt
FatemeNateghi Jan 27, 2025
e4284c8
Update requirements.txt
FatemeNateghi Jan 27, 2025
996b14a
Update requirements.txt
FatemeNateghi Jan 27, 2025
9b14b18
update PHI-safe LLM API for o1-mini
fcgrolleau Jan 28, 2025
c83978e
Create README.md
FatemeNateghi Jan 29, 2025
b26c8c3
Update app.py
FatemeNateghi Jan 30, 2025
7fa9c49
Update requirements.txt
FatemeNateghi Jan 30, 2025
0ef6c8a
Create models.py
FatemeNateghi Jan 30, 2025
db4e65e
Update app.py
FatemeNateghi Jan 30, 2025
4a4240a
Delete scripts/OUDTreatmentRetentionVSAttrition/WebApp/models.py
FatemeNateghi Jan 30, 2025
6e4ba30
Update app.py
FatemeNateghi Jan 30, 2025
d5d20c0
Create models.py
FatemeNateghi Jan 30, 2025
cf50831
Making host/port configurable to be able to run it on Render
ynodir Jan 31, 2025
262f23f
Adding logging of predict endpoint response
ynodir Jan 31, 2025
5fbcbe3
Added logging of parsed graphData object
ynodir Jan 31, 2025
97a3538
Create README
fatemeh91 Feb 6, 2025
c5b7b8d
Add files via upload
fatemeh91 Feb 6, 2025
2fbf3cc
Update DataPrepration_Inpatient_5ABX.ipynb
fatemeh91 Feb 6, 2025
ee6adbc
Delete scripts/antibiotic-susceptibility/Aim1b/Inpatient directory
fatemeh91 Feb 6, 2025
c07bc3f
Create README
fatemeh91 Feb 6, 2025
f00fcf9
Add files via upload
fatemeh91 Feb 6, 2025
802e906
Add files via upload
aaryanxshah Feb 12, 2025
586a251
Adding back plotting logic.
ynodir Feb 18, 2025
d70e29c
med orders extraction
aaryanxshah Feb 19, 2025
084df40
labs/proc scripts
aaryanxshah Feb 19, 2025
61caa48
Added eConsult Embedding System to scripts/eConsult
FatemeNateghi Feb 19, 2025
8d11b1c
Removed unwanted files and folders, kept only eConsult-embeddings
FatemeNateghi Feb 19, 2025
58584b2
Added eConsult-embeddings to scripts/eConsult
FatemeNateghi Feb 19, 2025
d129e95
Re-added eConsult-embeddings as a regular folder
FatemeNateghi Feb 20, 2025
969ac2d
Re-added eConsult-embeddings as a regular folder
FatemeNateghi Feb 20, 2025
66a7ec1
Re-added eConsult-embeddings as a regular folder
FatemeNateghi Feb 20, 2025
ef8aff0
Create g.py
FatemeNateghi Feb 20, 2025
79deefb
Added all files to eConsult-embeddings directory
FatemeNateghi Feb 20, 2025
fa6b6dc
Update g.py
FatemeNateghi Feb 20, 2025
76286e3
Delete scripts/eConsult/eConsult-embeddings/g.py
FatemeNateghi Feb 20, 2025
a04616e
Add Deepseek R1 & Phi 3.5-mini to PHI-safe LLM API doc
fcgrolleau Feb 20, 2025
2985753
Update embedding_generator.py
FatemeNateghi Feb 20, 2025
d9d88ab
Delete scripts/Implied_Susceptibility directory
FatemeNateghi Feb 21, 2025
73b098c
Add files via upload
fatemeh91 Mar 4, 2025
0773215
Create main.py
FatemeNateghi Mar 4, 2025
94d680b
Update embedding_generator.py
FatemeNateghi Mar 4, 2025
c38b412
Update requirements.txt
FatemeNateghi Mar 4, 2025
ead8848
Create Q&A_no_derm.sql
FatemeNateghi Mar 5, 2025
064dd5c
Add Claude 3.7 Sonnet to PHI-safe LLM API doc
fcgrolleau Mar 6, 2025
3333073
Update embedding_generator.py
FatemeNateghi Mar 10, 2025
986ba88
Fixing error handling - 404 error was being thrown with 500 error sta…
ynodir Mar 11, 2025
4a8d5b2
Update main.py
FatemeNateghi Mar 11, 2025
e930867
Merge remote-tracking branch 'origin/master' into feature/save-mappin…
ynodir Mar 18, 2025
560a2da
Handling closing of binary files after opening.
ynodir Mar 18, 2025
d6ffd83
Merge pull request #412 from HealthRex/feature/save-mapping-and-fix-e…
FatemeNateghi Mar 18, 2025
fa1b524
Update embedding_generator.py
FatemeNateghi Mar 18, 2025
97048be
Added given aspect
WenyuanChen1326 Mar 24, 2025
a42454c
Convert AIM4 from submodule to regular folder
WenyuanChen1326 Mar 24, 2025
0f2f3c3
Properly add AIM4 directory
WenyuanChen1326 Mar 24, 2025
895e49c
Merged master into main, keeping local AIM4 version
WenyuanChen1326 Mar 24, 2025
20d5761
Merge pull request #413 from HealthRex/main
WenyuanChen1326 Mar 24, 2025
c9dc86b
delete duplicated files
WenyuanChen1326 Mar 24, 2025
308a67b
Change to BlueSky instead of Twitter/X feed
jonc101 Mar 25, 2025
1dea591
finish analysis for adults & peds ed cohort
WenyuanChen1326 Mar 25, 2025
b24e15a
Update index.html
FatemeNateghi Apr 1, 2025
fa0d760
Update index.html
FatemeNateghi Apr 2, 2025
9e3c689
Remove tracked files from csv_folder, ignore with .gitignore, delete …
WenyuanChen1326 Apr 2, 2025
d91f961
Update prior_procedures.sql
fatemeh91 Apr 3, 2025
88f80cc
Update prior_procedures.sql
fatemeh91 Apr 3, 2025
2af332c
Update medication_exposure.sql
fatemeh91 Apr 3, 2025
6bf5e9a
Update previous_infecting_organisms.sql
fatemeh91 Apr 3, 2025
ca1bb80
Update antibiotic_subtype_exposure.sql
fatemeh91 Apr 3, 2025
0444429
Update antibiotic_class_exposure.sql
fatemeh91 Apr 3, 2025
9ed5370
Create README.md
fatemeh91 Apr 3, 2025
53b587d
Add files via upload
fatemeh91 Apr 3, 2025
aa29ccc
Add files via upload
fatemeh91 Apr 3, 2025
f99133d
Add files via upload
fatemeh91 Apr 3, 2025
9f29bdd
Making root endpoint async as shown in Render Fastapi example: https:…
ynodir Apr 7, 2025
13606d4
Adding stacktrace to "Failed to load model or curves" exception.
ynodir Apr 7, 2025
941e0e7
Trying to add `accelerate` into requirements.txt to fix init_empty_we…
ynodir Apr 7, 2025
4ae99cd
Trying to add hf_xet package to fix "Xet Storage is enabled for this …
ynodir Apr 10, 2025
5a1332e
Setting logging level to debug to see sentence transformer logs to tr…
ynodir Apr 14, 2025
062dfef
Moving referral template documents embedding out of the request handl…
ynodir Apr 14, 2025
df3049a
Update ml_models.py
FatemeNateghi Apr 15, 2025
d80a8e8
Create survival_pipeline.py
FatemeNateghi Apr 15, 2025
7693c5f
Rename survival_pipline.py to survival_pipeline.py
FatemeNateghi Apr 15, 2025
a62006d
Add Gemini 2.0 Flash
jyx-su Apr 22, 2025
76ac4ef
Update PHI-safe LLM API guide with new models and helper function ref…
fcgrolleau Apr 24, 2025
c84b0aa
Fix typo on PHI-safe LLM API update
fcgrolleau Apr 24, 2025
9e986a6
added updates for AIM4 and Recommender API project
WenyuanChen1326 Apr 25, 2025
5376f97
updated Recommender_API with FastAPI
WenyuanChen1326 Apr 25, 2025
89991e7
Create cosmos-onboarding.md
FatemeNateghi Apr 27, 2025
6311018
Update cosmos-onboarding.md
FatemeNateghi Apr 28, 2025
559478f
Add Gemini 2.0 Flash
jyx-su Apr 28, 2025
ed5cbe0
Update phi-llm-api-python.md
jyx-su Apr 28, 2025
f9c9de4
add model-switching and text generation utility examples to LLM API g…
fcgrolleau Apr 29, 2025
3c3db52
updated recommender API
WenyuanChen1326 May 6, 2025
d7f18b4
fixed the gitignore
WenyuanChen1326 May 6, 2025
db877cf
fixed the api
WenyuanChen1326 May 7, 2025
4732306
Create Readme.md
FatemeNateghi May 8, 2025
77c2d51
Update Readme.md
FatemeNateghi May 9, 2025
26be254
Add phase 1 files: bigquery API, notebook, and requirements to the ri…
WenyuanChen1326 May 14, 2025
3cb2d70
Merge pull request #414 from HealthRex/main
WenyuanChen1326 May 14, 2025
90ce314
Add example of using Params temporary table for common table expressi…
jonc101 May 19, 2025
1af4d4e
Add working query for SmartAlert pilot study
jonc101 May 19, 2025
9f28336
Merge branch 'master' of https://github.com/HealthRex/CDSS
jonc101 May 19, 2025
eb360ba
PArameterize SQL query, so can more easily tweak numbers
jonc101 May 19, 2025
6ad581a
Add lab names as query parameters
jonc101 May 19, 2025
a7cfb18
added all relevant files
WenyuanChen1326 May 20, 2025
39fb798
Adding separate referral templates in JSON format.
ynodir May 21, 2025
cc91eb9
Adding JSON referral templates for Psychiatry and Pain Medicine.
ynodir May 21, 2025
29e4d9b
Dockerfile for Embeddings API:
ynodir Jun 3, 2025
cc0e80c
Fixing dockerfile issues:
ynodir Jun 5, 2025
3ca5eb1
Add API usage docs to eConsult embeddings API
vishnuravi Jun 5, 2025
fa73dea
Update markdown formatting
vishnuravi Jun 5, 2025
cbff06f
Fix indentation
vishnuravi Jun 5, 2025
df63953
Reorganize for clarity
vishnuravi Jun 5, 2025
a7d3a9f
Adds additional instruction
vishnuravi Jun 5, 2025
9378396
Merge pull request #415 from HealthRex/vr-embeddings-docs
vishnuravi Jun 5, 2025
9238a05
Resolve merge conflicts in phase_1_updated.ipynb, keeping local version
WenyuanChen1326 Jun 6, 2025
b5f828f
moved to vm
WenyuanChen1326 Jun 6, 2025
639a6ca
JSONifying templates:
ynodir Jun 10, 2025
42bb5bb
JSONifying templates - added orthopedics and oncology trial templates.
ynodir Jun 11, 2025
9e970b4
JSONifying templates - added neurology templates.
ynodir Jun 11, 2025
a3d48e8
JSONifying templates - added nephrology templates.
ynodir Jun 11, 2025
d13426e
JSONifying templates:
ynodir Jun 11, 2025
4c32d8a
Create bigquery.sql
manojmaddali Jun 11, 2025
c22f225
JSONifying templates:
ynodir Jun 12, 2025
822ddfa
JSONifying templates - last batch:
ynodir Jun 12, 2025
2abecb1
Merge remote-tracking branch 'origin/master' into feature/jsonify-tem…
ynodir Jun 13, 2025
ed29ef5
JSONifying templates - last batch:
ynodir Jun 16, 2025
efd7293
Converging JSON templates to format fillable by LLM.
ynodir Jun 16, 2025
9749287
add support to Gemini 2.5 Pro SHC API & model agnostic shortcut
fcgrolleau Jun 17, 2025
4a4cea7
Merge pull request #416 from HealthRex/feature/jsonify-templates
ynodir Jun 18, 2025
aad086a
added code for sample_100 experiment
WenyuanChen1326 Jun 22, 2025
f18d10a
Remove Recommender_API directory and update other files
WenyuanChen1326 Jun 22, 2025
7581603
Merge branch 'master' of https://github.com/HealthRex/CDSS
WenyuanChen1326 Jun 22, 2025
fd36be5
Update error handling for shc llm api calls
fcgrolleau Jun 22, 2025
19a6fcf
Restore GPT-4o support using SHC LLM API
fcgrolleau Jun 22, 2025
9a9a849
added procedure tables and experimented with real data
WenyuanChen1326 Jun 23, 2025
41c6d51
Merge branch 'master' of https://github.com/HealthRex/CDSS
WenyuanChen1326 Jun 23, 2025
05eaea8
remoced all logs
WenyuanChen1326 Jun 23, 2025
1b19017
removed any pat info
WenyuanChen1326 Jun 23, 2025
ca78189
ready for VM migration
WenyuanChen1326 Jun 23, 2025
6e6327c
added demo
WenyuanChen1326 Jun 24, 2025
cba6a5c
update README
WenyuanChen1326 Jun 24, 2025
541f3d4
Modified code to parse response only if it was successful.
ynodir Jul 2, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
*.pyc
LocalEnv.py
.DS_Store
Expand Down
122 changes: 93 additions & 29 deletions scripts/DevWorkshop/llm-api/agnostic_evaluator_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from functools import partial
import requests
import json
import time
import os

class API_text_to_text:
Expand All @@ -12,6 +13,11 @@ def __init__(self, model_init, model_call):
def gen_txt_to_txt(self, input_txt):
return self.model_call(input_txt, **self.model_init_dict)

def error_handling(model_name, i, max_calls, sleep_time, e):
print(f"Failed with {model_name} (SHC) call {i}/{max_calls}, waited {i*sleep_time} seconds. Error: {e}.")
time.sleep(sleep_time)
return f"Failed to get a response from {model_name} (SHC) after {i*sleep_time} seconds. Error: {e}."

# Gemini via Vertex AI
def gemini_init(model_name, credentials_path):
# For HIPAA compliance, everything remains in our Google Cloud Project
Expand All @@ -20,36 +26,61 @@ def gemini_init(model_name, credentials_path):
from vertexai.preview.generative_models import GenerativeModel
return {"ready_model": GenerativeModel(model_name), "model_name": model_name}

def gemini_call(input_txt, **kwargs):
import time
def gemini_call(input_txt, max_calls = 10, sleep_time = 5, **kwargs):
ready_model = kwargs["ready_model"]
model_name = kwargs["model_name"]

max_calls = 10; sleep_time = 5
for i in range (max_calls):
try:
response = ready_model.generate_content([input_txt])
full_response = response.candidates[0].content.parts[0].text
break
except Exception as e:
print(f"Failed with {model_name} call {i}/{max_calls}, waited {i*sleep_time} seconds. Error: {e}.")
time.sleep(sleep_time)
full_response = f"Failed to get a response from {model_name} after {i*sleep_time} seconds."
full_response = error_handling(model_name, i, max_calls, sleep_time, e)
return full_response

# Gemini 2.5 Pro via SHC
def gemini_shc_init(model_name, my_key):
headers = {'Ocp-Apim-Subscription-Key': my_key, 'Content-Type': 'application/json'}
url = 'https://apim.stanfordhealthcare.org/gemini-25-pro/gemini-25-pro'
return {"model_name": model_name, "url": url, "headers": headers}

def gemini_shc_call(input_txt, max_calls=10, sleep_time=5, **kwargs):
model_name = kwargs["model_name"]
url = kwargs["url"]
headers = kwargs["headers"]
payload = json.dumps({"contents": [{"role": "user", "parts": [{ "text": input_txt }]}]})

for i in range(max_calls):
try:
response = requests.request("POST", url, headers=headers, data=payload)
full_response = ''.join([i['candidates'][0]['content']['parts'][0]['text'] for i in json.loads(response.text)])
break
except Exception as e:
full_response = error_handling(model_name, i, max_calls, sleep_time, e)
return full_response

# Open AI models via SHC
def openai_init(model_name, my_key):
headers = {'Ocp-Apim-Subscription-Key': my_key, 'Content-Type': 'application/json'}
url = f"https://apim.stanfordhealthcare.org/openai-eastus2/deployments/{model_name}/chat/completions?api-version=2025-01-01-preview"
url = f"https://apim.stanfordhealthcare.org/openai-eastus2/deployments/{model_name}/chat/completions?api-version=2025-01-01-preview"
if model_name == "gpt-4o":
url = "https://apim.stanfordhealthcare.org/openai20/deployments/gpt-4o/chat/completions?api-version=2023-05-15"
return {"model_name": model_name, "url": url, "headers": headers}

def openai_call(input_txt, **kwargs):
def openai_call(input_txt, max_calls = 10, sleep_time = 5, **kwargs):
model_name = kwargs["model_name"]
url = kwargs["url"]
headers = kwargs["headers"]
payload = json.dumps({"model": model_name, "messages": [{"role": "user", "content": input_txt}]})
response = requests.request("POST", url, headers=headers, data=payload)
return json.loads(response.text)['choices'][0]['message']['content']
for i in range(max_calls):
try:
response = requests.request("POST", url, headers=headers, data=payload)
full_response = json.loads(response.text)['choices'][0]['message']['content']
break
except Exception as e:
full_response = error_handling(model_name, i, max_calls, sleep_time, e)
return full_response

# Deepseek-R1 via SHC
def deepseek_init(model_name, my_key, view_thinking=False):
Expand All @@ -58,18 +89,24 @@ def deepseek_init(model_name, my_key, view_thinking=False):
url = "https://apim.stanfordhealthcare.org/deepseekr1/v1/chat/completions"
return {"url": url, "headers": headers, "view_thinking": view_thinking}

def deepseek_call(input_txt, **kwargs):
def deepseek_call(input_txt, max_calls = 10, sleep_time = 5, **kwargs):
url = kwargs["url"]
headers = kwargs["headers"]
payload = json.dumps({"model": "deepseek-chat", "messages": [{"role": "user", "content": input_txt}], "temperature": 0.8, "max_tokens": 4096, "top_p": 1, "stream": False})
response = requests.request("POST", url, headers=headers, data=payload)
full_response = json.loads(response.text)['choices'][0]['message']['content']
if kwargs["view_thinking"]:
return full_response
def _extract_after_think(text):
parts = text.split("</think>")
return parts[1].strip() if len(parts) > 1 else text
return _extract_after_think(full_response)
for i in range(max_calls):
try:
response = requests.request("POST", url, headers=headers, data=payload)
full_response = json.loads(response.text)['choices'][0]['message']['content']
if kwargs["view_thinking"]:
break
def _extract_after_think(text):
parts = text.split("</think>")
return parts[1].strip() if len(parts) > 1 else text
full_response = _extract_after_think(full_response)
break
except Exception as e:
full_response = error_handling("deepseek-r1", i, max_calls, sleep_time, e)
return full_response

# Microsoft model via SHC
def microsoft_init(model_name, my_key):
Expand All @@ -78,12 +115,18 @@ def microsoft_init(model_name, my_key):
url = "https://apim.stanfordhealthcare.org/phi35mi/v1/chat/completions"
return {"url": url, "headers": headers}

def microsoft_call(input_txt, **kwargs):
def microsoft_call(input_txt, max_calls = 10, sleep_time = 5, **kwargs):
url = kwargs["url"]
headers = kwargs["headers"]
payload = json.dumps({"messages": [{"role": "user", "content": input_txt}], "max_tokens": 2048, "temperature": 0.8, "top_p": 0.1, "presence_penalty": 0, "frequency_penalty": 0, "model": "Phi-3.5-mini-instruct"})
response = requests.request("POST", url, headers=headers, data=payload)
return json.loads(response.text)["choices"][0]["message"]["content"]
for i in range(max_calls):
try:
response = requests.request("POST", url, headers=headers, data=payload)
full_response = json.loads(response.text)["choices"][0]["message"]["content"]
break
except Exception as e:
full_response = error_handling("phi-3.5-mini-instruct", i, max_calls, sleep_time, e)
return full_response

# Anthropic model via SHC
def anthropic_init(model_name, my_key):
Expand All @@ -96,13 +139,19 @@ def anthropic_init(model_name, my_key):
headers = {'Ocp-Apim-Subscription-Key': my_key, 'Content-Type': 'application/json'}
return {"model_id": model_id, "url": url, "headers": headers}

def anthropic_call(input_txt, **kwargs):
def anthropic_call(input_txt, max_calls = 10, sleep_time = 5, **kwargs):
model_id = kwargs["model_id"]
url = kwargs["url"]
headers = kwargs["headers"]
payload = json.dumps({"model_id": model_id, "prompt_text": input_txt})
response = requests.request("POST", url, headers=headers, data=payload)
return json.loads(response.text)['content'][0]['text']
for i in range(max_calls):
try:
response = requests.request("POST", url, headers=headers, data=payload)
full_response = json.loads(response.text)['content'][0]['text']
break
except Exception as e:
full_response = error_handling(model_id, i, max_calls, sleep_time, e)
return full_response

# Meta model via SHC
def meta_init(model_name, my_key):
Expand All @@ -114,20 +163,35 @@ def meta_init(model_name, my_key):
url = f"https://apim.stanfordhealthcare.org/{model_name}/v1/chat/completions"
return {"full_model_name": full_model_name, "url": url, "headers": headers}

def meta_call(input_txt, **kwargs):
def meta_call(input_txt, max_calls = 10, sleep_time = 5, **kwargs):
full_model_name = kwargs["full_model_name"]
url = kwargs["url"]
headers = kwargs["headers"]
payload = json.dumps({"model": full_model_name, "messages": [{"role": "user", "content": input_txt}]})
response = requests.request("POST", url, headers=headers, data=payload)
return json.loads(response.text)['choices'][0]['message']['content']
for i in range(max_calls):
try:
response = requests.request("POST", url, headers=headers, data=payload)
full_response = json.loads(response.text)['choices'][0]['message']['content']
break
except Exception as e:
full_response = error_handling(full_model_name, i, max_calls, sleep_time, e)
return full_response

if __name__ == "main":
from dotenv import load_dotenv
load_dotenv("../../../.env")

my_question = """First, state what LLM you are based on. Please answer with the precise version of the model.
Next, answer the following hard physics question.
What is the difference between the cosmological constant and the vacuum energy?"""

lab_key = "enter the lab key here"
lab_key = os.getenv("LAB_KEY") # enter the lab key here

# Using Gemini 2.5 pro via SHC
gemini_shc_init_partial = partial(gemini_shc_init, "gemini-2.5-pro-preview-05-06", lab_key)
gemini_shc_instance = API_text_to_text(gemini_shc_init_partial, gemini_shc_call)
res = gemini_shc_instance.gen_txt_to_txt(my_question)
print(res)

# Using Meta via SHC
llama_init = partial(meta_init, "llama4-maverick", lab_key)
Expand Down
29 changes: 16 additions & 13 deletions scripts/DevWorkshop/llm-api/phi-llm-api-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This guide demonstrates how to use Python to interact with various Large Languag

*Created by François Grolleau on 02/19/2025
Contributors: Yixing Jiang
Last update April 29, 2025.*
Last update June 16, 2025.*

## Table of Contents
- [Prerequisites](#prerequisites)
Expand All @@ -18,8 +18,8 @@ Last update April 29, 2025.*
- [Claude 3.7 Sonnet](#claude-37-sonnet-api-call)
- [Claude 3.5 Sonnet v2](#claude-35-sonnet-v2-api-call)
- [Google Models](#google-models)
- [Gemini 2.5 Pro](#gemini-25-pro-api-call)
- [Gemini 2.0 Flash](#gemini-20-flash-api-call)
- [Gemini 1.5 Pro](#gemini-15-pro-api-call)
- [Meta Models](#meta-models)
- [Llama 3.3 70B](#llama-33-70b-instruct-api-call)
- [Llama 4 Maverick](#llama-4-maverick-api-call)
Expand Down Expand Up @@ -141,25 +141,22 @@ print(response.text)
---

## Google Models
### Gemini 2.0 Flash API Call
### Gemini 2.5 Pro API Call
```python
url = "https://apim.stanfordhealthcare.org/gcp-gem20flash-fa/apim-gcp-gem20flash-fa"
url = "https://apim.stanfordhealthcare.org/gemini-25-pro/gemini-25-pro"
payload = json.dumps({
"contents": {"role": "user", "parts": {"text": my_question}},
"safety_settings": {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
"generation_config": {"temperature": 0.2, "topP": 0.8, "topK": 40}
"contents": [{"role": "user", "parts": [{"text": my_question}]}]
})
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
```


### Gemini 1.5 Pro API Call
### Gemini 2.0 Flash API Call
```python
url = "https://apim.stanfordhealthcare.org/gcpgemini/apim-gcp-oauth-fa"
url = "https://apim.stanfordhealthcare.org/gcp-gem20flash-fa/apim-gcp-gem20flash-fa"
payload = json.dumps({
"contents": {"role": "user", "parts": {"text": my_question}},
"safety_settings": {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_LOW_AND_ABOVE"},
"safety_settings": {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
"generation_config": {"temperature": 0.2, "topP": 0.8, "topK": 40}
})
response = requests.request("POST", url, headers=headers, data=payload)
Expand Down Expand Up @@ -296,7 +293,7 @@ def gen_txt_to_txt(input_txt):
Use the `API_text_to_text` class from `agnostic_evaluator_models.py` to seamlessly switch between different LLM providers:

```python
from agnostic_evaluator_models import API_text_to_text, meta_init, meta_call, gemini_init, gemini_call
from agnostic_evaluator_models import API_text_to_text, meta_init, meta_call, gemini_init, gemini_call, gemini_shc_init, gemini_shc_call
from functools import partial

lab_key = "enter the lab's key here!"
Expand All @@ -309,6 +306,12 @@ llama_instance = API_text_to_text(llama_init, meta_call)
res = llama_instance.gen_txt_to_txt(my_question)
print(res)

# Using Gemini 2.5 Pro via SHC
gemini_shc_init_partial = partial(gemini_shc_init, "gemini-2.5-pro-preview-05-06", lab_key)
gemini_shc_instance = API_text_to_text(gemini_shc_init_partial, gemini_shc_call)
res = gemini_shc_instance.gen_txt_to_txt(my_question)
print(res)

# Using Gemini 2.5 Pro Preview via Vertex AI
credentials_path = "path/to/your/google_application_default_credentials.json"

Expand All @@ -323,4 +326,4 @@ More examples are provided in the `agnostic_evaluator_models.py` under `if __nam

> **Note:** If you haven't already set up Google Cloud authentication, you'll need to create an `application_default_credentials.json` file. You can follow the step-by-step instructions in our [Google Cloud setup guide](https://github.com/HealthRex/CDSS/blob/master/scripts/DevWorkshop/ReadMe.GoogleCloud-BigQuery-VPC.txt) to generate and configure these credentials.

*Final fun note: As of April 2025, no model seems to get the physics question right. According to cosmologist Sean Carroll "The vacuum energy and the cosmological constant are two different labels for exactly the same thing; don't let anyone tell you differently" (Quanta and Fields, Dutton, 2024. Chapter 6 p. 146). Looks like latest models continue bullshitting very confidently when facts are rarely in their training data.* 😄
*Final fun note: As of June 2025, no model seems to get the physics question right. According to cosmologist Sean Carroll "The vacuum energy and the cosmological constant are two different labels for exactly the same thing; don't let anyone tell you differently" (Quanta and Fields, Dutton, 2024. Chapter 6 p. 146). Looks like latest models continue bullshitting very confidently when facts are rarely in their training data.* 😄
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
csv_folder/*
csv_folder/*
Embedding_Pilot_Exp/data/*
Embedding_Pilot_Exp/error_checking/*
Embedding_Pilot_Exp/strictest/*
Embedding_Pilot_Exp/.env
Loading