Skip to content

Instantly share code, notes, and snippets.

@potatoqualitee
Last active August 22, 2024 10:15
Show Gist options
  • Save potatoqualitee/e7a44c19bbc80f46dc2ef525bc97c98e to your computer and use it in GitHub Desktop.
Save potatoqualitee/e7a44c19bbc80f46dc2ef525bc97c98e to your computer and use it in GitHub Desktop.

Revisions

  1. potatoqualitee revised this gist Aug 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion so.ps1
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ $jsonSchema = '{
    },
    "owner_name": {
    "type": "string",
    "description": "What is the name of the pet's owner?"
    "description": "What is the name of the owner of the pet?"
    },
    "pet_breed": {
    "type": "string",
  2. potatoqualitee revised this gist Aug 21, 2024. 1 changed file with 58 additions and 68 deletions.
    126 changes: 58 additions & 68 deletions so.ps1
    Original file line number Diff line number Diff line change
    @@ -41,79 +41,69 @@ Phone: 123-1234567 - Email: [email protected]

    ############# Provide the JSON schema #############
    $jsonSchema = '{
    "name": "pet",
    "strict": true,
    "schema": {
    "type": "object",
    "properties": {
    "pet_name": {
    "type": "string",
    "description": "What is the name of the pet?"
    "name": "pet",
    "strict": true,
    "schema": {
    "type": "object",
    "properties": {
    "pet_name": {
    "type": "string",
    "description": "What is the name of the pet?"
    },
    "owner_name": {
    "type": "string",
    "description": "What is the name of the pet's owner?"
    },
    "pet_breed": {
    "type": "string",
    "description": "What is the breed of the pet?"
    },
    "vaccinations": {
    "type": "array",
    "items": {
    "type": "object",
    "properties": {
    "vaccine_name": {
    "type": "string",
    "description": "What is the name of the vaccine administered?"
    },
    "owner_name": {
    "type": "string",
    "description": "What is the name of its owner?"
    "date_administered_1": {
    "type": "string",
    "description": "When was the first dose of the vaccine administered?"
    },
    "pet_breed": {
    "type": "string",
    "description": "What is the breed of the pet?"
    "date_administered_2": {
    "type": "string",
    "description": "When was the second dose of the vaccine administered?"
    },
    "vaccinations": {
    "type": "array",
    "items": {
    "type": "object",
    "properties": {
    "vaccine_name": {
    "type": "string",
    "description": "What is the name of the vaccine administered?"
    },
    "date_administered_1": {
    "type": "string",
    "description": "When was the first dose of the vaccine administered?"
    },
    "veterinarian_1": {
    "type": "string",
    "description": "Who is the veterinarian that administered the first dose?"
    },
    "date_administered_2": {
    "type": "string",
    "description": "When was the second dose of the vaccine administered?"
    },
    "veterinarian_2": {
    "type": "string",
    "description": "Who is the veterinarian that administered the second dose?"
    },
    "date_administered_3": {
    "type": "string",
    "description": "When was the third dose of the vaccine administered?"
    },
    "veterinarian_3": {
    "type": "string",
    "description": "Who is the veterinarian that administered the third dose?"
    }
    },
    "required": [
    "vaccine_name",
    "date_administered_1",
    "veterinarian_1",
    "date_administered_2",
    "veterinarian_2",
    "date_administered_3",
    "veterinarian_3"
    ],
    "additionalProperties": false
    },
    "description": "What vaccinations were given to the pet, including the vaccine names, administration dates, and veterinarian names?"
    "date_administered_3": {
    "type": "string",
    "description": "When was the third dose of the vaccine administered?"
    },
    "veterinarian": {
    "type": "string",
    "description": "Who is the veterinarian that administered the first dose?"
    }
    },
    "required": [
    "vaccine_name",
    "date_administered_1",
    "date_administered_2",
    "date_administered_3",
    "veterinarian"
    ],
    "additionalProperties": false
    },
    "required": [
    "pet_name",
    "owner_name",
    "pet_breed",
    "vaccinations"
    ],
    "additionalProperties": false
    }
    "description": "What vaccinations were given to the pet, including the vaccine names, administration dates, and veterinarian names?"
    }
    },
    "required": [
    "pet_name",
    "owner_name",
    "pet_breed",
    "vaccinations"
    ],
    "additionalProperties": false
    }
    }'
    ############# call dat #############
  3. potatoqualitee created this gist Aug 20, 2024.
    129 changes: 129 additions & 0 deletions so.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,129 @@
    ############# Install PSOpenAI and set your API key #############
    Install-Module PSOpenAI
    Import-Module PSOpenAI # only when it's first installed
    $env:OPENAI_API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx'

    ############# Here's some markdown that'd be extracted from a PDF, however you want #############
    $markdown = "# Dog Shot Record
    2309 Kelley Road, Gulfport, MS, 39501
    **CLINIC NAME**
    Phone: 123-1234567 - Email: [email protected]
    ## Dog's Information
    - **Name:** Chewy
    - **Age:** 5
    - **Date of Birth:** February 25, 2014
    - **Gender:** Male
    - **Breed:** Labrador
    - **Color:** Brown
    ## Owner's Information
    - **Name:** Jane Doe
    - **Address:** 1375 McDowell Street, Mount Pleasant, TN, 38474
    ## Immunization Dates
    | Vaccine | Immunization Date 1 | Immunization Date 2 | Immunization Date 3 | Veterinarian Name |
    |----------------|---------------------|---------------------|---------------------|-------------------|
    | Distemper | 02/01/2019 | | | John Smith |
    | Measles | 02/01/2019 | | | John Smith |
    | Parainfluenza | 02/01/2019 | | | John Smith |
    | DHPP | 02/01/2019 | 09/01/2017 | 09/01/2018 | John Smith |
    | Bordatella | 02/01/2019 | 09/01/2017 | 09/01/2018 | John Smith |
    | Coronavirus | 02/01/2019 | 10/01/2017 | 09/01/2018 | John Smith |
    | Leptospirosis | 02/01/2019 | 09/01/2017 | 09/01/2018 | John Smith |
    | Lyme disease | 02/01/2019 | 10/01/2017 | 09/01/2018 | John Smith |
    **Veterinarian Name:** John Smith
    **Veterinarian Signature:**
    **Date of Signature:** February 25, 2019"

    ############# Provide the JSON schema #############
    $jsonSchema = '{
    "name": "pet",
    "strict": true,
    "schema": {
    "type": "object",
    "properties": {
    "pet_name": {
    "type": "string",
    "description": "What is the name of the pet?"
    },
    "owner_name": {
    "type": "string",
    "description": "What is the name of its owner?"
    },
    "pet_breed": {
    "type": "string",
    "description": "What is the breed of the pet?"
    },
    "vaccinations": {
    "type": "array",
    "items": {
    "type": "object",
    "properties": {
    "vaccine_name": {
    "type": "string",
    "description": "What is the name of the vaccine administered?"
    },
    "date_administered_1": {
    "type": "string",
    "description": "When was the first dose of the vaccine administered?"
    },
    "veterinarian_1": {
    "type": "string",
    "description": "Who is the veterinarian that administered the first dose?"
    },
    "date_administered_2": {
    "type": "string",
    "description": "When was the second dose of the vaccine administered?"
    },
    "veterinarian_2": {
    "type": "string",
    "description": "Who is the veterinarian that administered the second dose?"
    },
    "date_administered_3": {
    "type": "string",
    "description": "When was the third dose of the vaccine administered?"
    },
    "veterinarian_3": {
    "type": "string",
    "description": "Who is the veterinarian that administered the third dose?"
    }
    },
    "required": [
    "vaccine_name",
    "date_administered_1",
    "veterinarian_1",
    "date_administered_2",
    "veterinarian_2",
    "date_administered_3",
    "veterinarian_3"
    ],
    "additionalProperties": false
    },
    "description": "What vaccinations were given to the pet, including the vaccine names, administration dates, and veterinarian names?"
    }
    },
    "required": [
    "pet_name",
    "owner_name",
    "pet_breed",
    "vaccinations"
    ],
    "additionalProperties": false
    }
    }'

    ############# call dat #############
    $params = @{
    Model = "gpt-4o-2024-08-06"
    SystemMessage = "You are an assistant that extracts information from pet vaccination records."
    Message = $markdown
    Format = "json_schema"
    JsonSchema = $jsonSchema
    }
    $result = Request-ChatCompletion @params

    $result.Answers | ConvertFrom-Json