AI Tools Lab - Instructions
AI Tools Lab
Prerequisites
OpenAI API Key You need to signup for OpenAI API Platform for this exercise. We suggest purchasing a $5 credit on sign up.
Sign up for OpenAI API Platform
Create the account
Generate API Key
Purchase $5 Credit
Updated Code and Environment
Checked out Lab Repo from GitHub CS595 Lab RepoStep
Pull the code to get the latest updates for GitHub Repo
Python version 3.10 or later
A Python virtual environment to link and use for the project
Do Git Pull on lab repo to make sure you have the latest updates
Go to <Project Root>/labs/aitools
Install requirements
pip install -r requirements.txt
Setup and Verify LOF Services
Open <Project Root>
Activate the python virtual environment
Go to
lof
folderEdit
.env file
Update client_id and client_secret values with the credentials you have receivedclient_id= client_secret=
Install Requirements
pip install -r requirements.txt
Run
services.py
You should see the message :
LoF Services verified successfully
Possible Error Messages and resolution:
Missing or Incorrect client_id
Failed to get LoF auth token: 400 : {"error":"Invalid client ID"}
Resolution: Update correct client_id in .env file
Missing or Incorrect client_secret
Failed to get LoF auth token: 401 : {"error":"Unauthorized: Client authentication failed","status":401}
Resolution: Update correct client_secret in .env file
Instructions
We suggest to complete this lab using OpenAI gpt-4o-mini model. You can try other opensource models. We haven't tested the lab with other models and you may have to resolve the issue on your own.
Go to <Project Root>/labs/aitools
Update openai_api_key
Open constants.py file and update the openai_api_key
GuardRail
Under <Project Root>/labs/aitools : Go to tools/guardrail/ directory
Understand MedicalQueryOutput model in model.py
Understand agent implementation in guardrail_agent.py
Implement enhancer_agent
Functions
Under <Project Root>/labs/aitools : Go to tools/enhancer/functions/ directory
Open utils.py
Understand normalize_medication_with_imo and normalize_problem_with_imo functions
enhancer_agent
Under <Project Root>/labs/aitools : Go to tools/enhancer/ directory
Open enhancer_agent.py
Write enhancer_instructions PROMPT
Create enhancer Agent
Implement fhir_agent
Functions
Under <Project Root>/labs/aitools : Go to tools/fhir/functions/ directory
Open utils.py
Understand get_patient_conditions, get_patient_medications, get_patient_biography
FHIRClient
Understand fhir_client.py functions
Model
Under <Project Root>/labs/aitools : Go to tools/fhir/ directory
Implement
FHIRCondition
FHIRMedication
FHIRMedicationRequest
FHIRPatient
fhir_agent
Under <Project Root>/labs/aitools : Go to tools/fhir/ directory
Open fhir_agent.py
Write fhir_agent_instructions PROMPT
Create fhir_agent Agent
Implement Medication Matcher agent
Functions
Under <Project Root>/labs/aitools : Go to tools/medication/functions/ directory
Open utils.py
Understand get_medication_info_from_fdb
Model
Under <Project Root>/labs/aitools : Go to tools/medication/ directory
Implement MedicationMatcherInput
matcher_agent
Under <Project Root>/labs/aitools : Go to tools/medication/ directory
Write matcher_agent_instructions PROMPT
Create matcher Agent
Implement Search Tool
Functions
Under <Project Root>/labs/aitools : Go to tools/search/functions/ directory
Open utils.py
Implement search_duckduckgo function
Final Runner - medication_matcher.py
Go to <Project Root>/labs/aitools
Open medication_matcher.py
analyze_medication_condition_relationships function
Write matcher_input PROMPT
main function
Implement the agent orchestration code
Running the application
Go to /labs/aitools and run
streamlit run medication_matcher.py
Submission
Create a zip file with the below submission items and submit one zip file.
Short Report (1–2 pages PDF)
Document difficulties or errors you encountered, and how you resolved them.
Document your observations on writing the prompts, what didn't work and what worked.
aitools code folder
Full code implementation
Don't include the open_ai_key. Remove it before sharing
A document or folder with screen shots
Question asked
AI Response
Debugging
OpenAI (gpt-4o-mini)
Max turns (10) exceeded - Try ChatGPT for possible resolutions
Ollama - Llama 3.2 - Problems faced during testing
Most of the times no/dummy output
Some times Incomplete output
Some times functions are not recognized for tool calling
Last updated