AI Tools Lab - Instructions

AI Tools Lab

Prerequisites

  1. OpenAI API Key You need to signup for OpenAI API Platform for this exercise. We suggest purchasing a $5 credit on sign up.

    1. Create the account

    2. Generate API Key

    3. Purchase $5 Credit

  2. Updated Code and Environment

    1. Checked out Lab Repo from GitHub CS595 Lab RepoStep

    2. Pull the code to get the latest updates for GitHub Repo

    3. Python version 3.10 or later

    4. A Python virtual environment to link and use for the project

    5. Do Git Pull on lab repo to make sure you have the latest updates

    6. Go to <Project Root>/labs/aitools

      1. Install requirements pip install -r requirements.txt

  3. Setup and Verify LOF Services

    1. Open <Project Root>

    2. Activate the python virtual environment

    3. Go to lof folder

    4. Edit .env file Update client_id and client_secret values with the credentials you have received

      client_id=
      client_secret=
    5. Install Requirements pip install -r requirements.txt

    6. Run services.py

      1. You should see the message : LoF Services verified successfully

    7. Possible Error Messages and resolution:

      1. Missing or Incorrect client_id

        1. Failed to get LoF auth token: 400 : {"error":"Invalid client ID"}

        2. Resolution: Update correct client_id in .env file

      2. Missing or Incorrect client_secret

        1. Failed to get LoF auth token: 401 : {"error":"Unauthorized: Client authentication failed","status":401}

        2. 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.

  1. Go to <Project Root>/labs/aitools

  2. Update openai_api_key

    1. Open constants.py file and update the openai_api_key

  3. GuardRail

    1. Under <Project Root>/labs/aitools : Go to tools/guardrail/ directory

    2. Understand MedicalQueryOutput model in model.py

    3. Understand agent implementation in guardrail_agent.py

  4. Implement enhancer_agent

    1. Functions

      1. Under <Project Root>/labs/aitools : Go to tools/enhancer/functions/ directory

      2. Open utils.py

      3. Understand normalize_medication_with_imo and normalize_problem_with_imo functions

    2. enhancer_agent

      1. Under <Project Root>/labs/aitools : Go to tools/enhancer/ directory

      2. Open enhancer_agent.py

      3. Write enhancer_instructions PROMPT

      4. Create enhancer Agent

  5. Implement fhir_agent

    1. Functions

      1. Under <Project Root>/labs/aitools : Go to tools/fhir/functions/ directory

      2. Open utils.py

      3. Understand get_patient_conditions, get_patient_medications, get_patient_biography

    2. FHIRClient

      1. Understand fhir_client.py functions

    3. Model

      1. Under <Project Root>/labs/aitools : Go to tools/fhir/ directory

      2. Implement

        1. FHIRCondition

        2. FHIRMedication

        3. FHIRMedicationRequest

        4. FHIRPatient

    4. fhir_agent

      1. Under <Project Root>/labs/aitools : Go to tools/fhir/ directory

      2. Open fhir_agent.py

      3. Write fhir_agent_instructions PROMPT

      4. Create fhir_agent Agent

  6. Implement Medication Matcher agent

    1. Functions

      1. Under <Project Root>/labs/aitools : Go to tools/medication/functions/ directory

      2. Open utils.py

      3. Understand get_medication_info_from_fdb

    2. Model

      1. Under <Project Root>/labs/aitools : Go to tools/medication/ directory

      2. Implement MedicationMatcherInput

    3. matcher_agent

      1. Under <Project Root>/labs/aitools : Go to tools/medication/ directory

      2. Write matcher_agent_instructions PROMPT

      3. Create matcher Agent

  7. Implement Search Tool

    1. Functions

      1. Under <Project Root>/labs/aitools : Go to tools/search/functions/ directory

      2. Open utils.py

      3. Implement search_duckduckgo function

  8. Final Runner - medication_matcher.py

    1. Go to <Project Root>/labs/aitools

    2. Open medication_matcher.py

    3. analyze_medication_condition_relationships function

      1. Write matcher_input PROMPT

    4. main function

      1. Implement the agent orchestration code

  9. Running the application

    1. Go to /labs/aitools and run

    2. streamlit run medication_matcher.py

Submission

Create a zip file with the below submission items and submit one zip file.

  1. Short Report (1–2 pages PDF)

    1. Document difficulties or errors you encountered, and how you resolved them.

    2. Document your observations on writing the prompts, what didn't work and what worked.

  2. aitools code folder

    1. Full code implementation

    2. Don't include the open_ai_key. Remove it before sharing

  3. A document or folder with screen shots

    1. Question asked

    2. AI Response

Debugging

  1. OpenAI (gpt-4o-mini)

    1. Max turns (10) exceeded - Try ChatGPT for possible resolutions

  2. Ollama - Llama 3.2 - Problems faced during testing

    1. Most of the times no/dummy output

    2. Some times Incomplete output

    3. Some times functions are not recognized for tool calling

Last updated