diff --git a/src/Client/App.fs b/src/Client/App.fs index bf0a54e..6145f6f 100644 --- a/src/Client/App.fs +++ b/src/Client/App.fs @@ -800,7 +800,7 @@ open Shared [] let private themeDef = """ -responsiveFontSizes(createTheme()) +responsiveFontSizes(createTheme(), { factor : 2 }) """ @@ -809,6 +809,7 @@ responsiveFontSizes(createTheme()) let private theme : obj = jsNative + // Entry point must be in a separate file // for Vite Hot Reload to work diff --git a/src/Informedica.GenForm.Lib/Scripts/RenalRule.fsx b/src/Informedica.GenForm.Lib/Scripts/RenalRule.fsx index 8445f3a..fa1131f 100644 --- a/src/Informedica.GenForm.Lib/Scripts/RenalRule.fsx +++ b/src/Informedica.GenForm.Lib/Scripts/RenalRule.fsx @@ -42,6 +42,9 @@ open Informedica.GenUnits.Lib RenalRule.get () +Web.getDataFromSheet dataUrlId "RenalRules" + +Web.GoogleSheets.createUrl "RenalRules" (Web.getDataUrlIdGenPres ()) open RenalRule diff --git a/src/Informedica.OpenAI.Lib/Notebooks/ExtractFrequencies.ipynb b/src/Informedica.OpenAI.Lib/Notebooks/ExtractFrequencies.ipynb index a7b3a75..92f46f6 100644 --- a/src/Informedica.OpenAI.Lib/Notebooks/ExtractFrequencies.ipynb +++ b/src/Informedica.OpenAI.Lib/Notebooks/ExtractFrequencies.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 82, + "execution_count": 1, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 5, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -73,7 +73,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "- Testing: mistral: \n", + "- Testing: gemma2: \n", "## System:\n", "You are an expert on medication prescribing, preparation and administration. You will give\n", "exact answers. If there is no possible answer return an empty string.\n", @@ -161,7 +161,7 @@ "\n", "\n", "## Answer:\n", - "{\"frequencies\":[3],\"timeUnit\":\"dag\"}\n", + "{\"frequencies\":[1,3],\"timeUnit\":\"dag\"}\n", "\n", "\n", "## Question:\n", @@ -203,25 +203,788 @@ "\n", "\n", "## Answer:\n", - "{\"quantities\":[{\"maxQty\":0.05,\"minQty\":0.125,\"unit\":\"mg\"},{\"maxQty\":3.0,\"minQty\":1.0,\"unit\":\"mg/dag\"}]}\n", + "{\"quantities\":[{\"maxQty\":3.0,\"minQty\":0.125,\"unit\":\"mg\"},{\"maxQty\":3.0,\"minQty\":0.05,\"unit\":\"mg/kg\"}]}\n", "\n", - "## Failed test: { doseQuantities = [|{ maxQty = 0.05\n", + "## Failed test: { doseQuantities = [|{ maxQty = 3.0\n", " minQty = 0.125\n", " unit = \"mg\" }; { maxQty = 3.0\n", - " minQty = 1.0\n", - " unit = \"mg/dag\" }|]\n", + " minQty = 0.05\n", + " unit = \"mg/kg\" }|]\n", " doseUnits = { adjustUnit = \"kg\"\n", " substanceUnit = \"mg\"\n", " timeUnit = \"dag\" }\n", - " freqs = { frequencies = [3]\n", + " freqs = { frequencies = [1; 3]\n", " timeUnit = \"dag\" } } is not { doseQuantities = [|{ maxQty = 0.25\n", " minQty = 0.125\n", " unit = \"mg\" }|]\n", - " doseUnits = { adjustUnit = \"kg\"\n", + " doseUnits = { adjustUnit = \"kg\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [3]\n", + " timeUnit = \"dag\" } }\n", + "\n", + "## System:\n", + "You are an expert on medication prescribing, preparation and administration. You will give\n", + "exact answers. If there is no possible answer return an empty string.\n", + "You will be asked to extract structured information from the following text between ''':\n", + "\n", + "'''\n", + "acetylsalicylzuur\n", + "1 maand tot 18 jaar Startdosering:Acetylsalicylzuur: 30 - 50 mg/kg/dag in 3 - 4 doses. Max: 3.000 mg/dag.\n", + "'''\n", + "\n", + "ONLY respond if the response is actually present in the text. If the response cannot be extracted\n", + "respond with an empty string for a textfield or zero for a number field.\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement for the medication substance (substance unit)\n", + "from the medication dosage information contained in the text.\n", + "\n", + "Use schema: { substanceUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + " - For \"mg/kg/dag\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + " - For \"g/m2/dag\", return: \"{ \"substanceUnit\": \"g\" }\"\n", + " - For \"IE/m2\", return: \"{ \"substanceUnit\": \"IE\" }\"\n", + " - For \"mg/2 dagen\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + "\n", + "\n", + "## Answer:\n", + "{\"substanceUnit\":\"mg\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement by which a medication dose is adjusted,\n", + "such as patient weight or body surface area, from the medication dosage information contained in the text.\n", + "\n", + "Use schema : { adjustUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/kg\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/m2/dag\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "- For \"mg/m2\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"adjustUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"adjustUnit\":\"kg\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the time unit from the medication dosage information contained in the text.\n", + "The timeunit is the unit by which the frequency of administration is measured.\n", + "\n", + "Use schema : { timeUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"timeUnit\": \"dag\" }\"\n", + "- For \"mg/kg\", return: \"{ \"timeUnit\": \"\" }\"\n", + "- For \"mg/m2/week\", return: \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"mg/2 dagen\", return: \"{ \"timeUnit\": \"2 dagen\" }\"\n", + "- For \"per week\", return \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"per dag\", return \"{ \"timeUnit\": \"week\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"timeUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the frequencies by which the drug can be administered.\n", + "The frequencies field in the schema should be an array of integers.\n", + "\n", + "Use schema : { frequencies: []; timeUnit: string }\n", + "\n", + "Note that the frequencies should be possible times of administrations per dag\n", + "If extraction is not possible return: \"{\"frequencies\":[],\"timeUnit\":\"dag\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"frequencies\":[3,4],\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract all mentioned dose quantities.\n", + "A quantity should match the regular expresion between the ticks '(\\d+(\\.\\d+)?\\s?(mg)(\\/(kg|dag|keer|dosis))?(\\s?\\/\\s?(kg|dag|keer|dosis))?\\s)'\n", + "\n", + "Return dose quantities as a list of JSON\n", + "Use schema :\n", + "{\n", + " \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"quantities\": {\n", + " \"type\": \"array\",\n", + " \"items\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"minQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"maxQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"unit\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"mg\", \"mg/kg\"]\n", + " }\n", + " },\n", + " \"required\": [\"minQty\", \"maxQty\", \"unit\"]\n", + " }\n", + " }\n", + " },\n", + " \"required\": [\"quantities\"]\n", + "}\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"quantities\":[{\"maxQty\":50.0,\"minQty\":30.0,\"unit\":\"mg/kg\"},{\"maxQty\":3000.0,\"minQty\":0.0,\"unit\":\"mg\"}]}\n", + "\n", + "## Failed test: { doseQuantities = [|{ maxQty = 50.0\n", + " minQty = 30.0\n", + " unit = \"mg/kg\" }; { maxQty = 3000.0\n", + " minQty = 0.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"kg\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [3; 4]\n", + " timeUnit = \"dag\" } } is not { doseQuantities = [|{ maxQty = 0.0\n", + " minQty = 0.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"kg\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [3; 4]\n", + " timeUnit = \"dag\" } }\n", + "\n", + "## System:\n", + "You are an expert on medication prescribing, preparation and administration. You will give\n", + "exact answers. If there is no possible answer return an empty string.\n", + "You will be asked to extract structured information from the following text between ''':\n", + "\n", + "'''\n", + "paracetamol\n", + "Oraal: Bij milde tot matige pijn en/of koorts: volgens het Kinderformularium van het NKFK bij een leeftijd van 1 maand–18 jaar: 10–15 mg/kg lichaamsgewicht per keer, zo nodig 4×/dag, max. 60 mg/kg/dag en max. 4 g/dag.\n", + "'''\n", + "\n", + "ONLY respond if the response is actually present in the text. If the response cannot be extracted\n", + "respond with an empty string for a textfield or zero for a number field.\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement for the medication substance (substance unit)\n", + "from the medication dosage information contained in the text.\n", + "\n", + "Use schema: { substanceUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + " - For \"mg/kg/dag\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + " - For \"g/m2/dag\", return: \"{ \"substanceUnit\": \"g\" }\"\n", + " - For \"IE/m2\", return: \"{ \"substanceUnit\": \"IE\" }\"\n", + " - For \"mg/2 dagen\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + "\n", + "\n", + "## Answer:\n", + "{\"substanceUnit\":\"mg\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement by which a medication dose is adjusted,\n", + "such as patient weight or body surface area, from the medication dosage information contained in the text.\n", + "\n", + "Use schema : { adjustUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/kg\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/m2/dag\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "- For \"mg/m2\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"adjustUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"adjustUnit\":\"kg\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the time unit from the medication dosage information contained in the text.\n", + "The timeunit is the unit by which the frequency of administration is measured.\n", + "\n", + "Use schema : { timeUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"timeUnit\": \"dag\" }\"\n", + "- For \"mg/kg\", return: \"{ \"timeUnit\": \"\" }\"\n", + "- For \"mg/m2/week\", return: \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"mg/2 dagen\", return: \"{ \"timeUnit\": \"2 dagen\" }\"\n", + "- For \"per week\", return \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"per dag\", return \"{ \"timeUnit\": \"week\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"timeUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the frequencies by which the drug can be administered.\n", + "The frequencies field in the schema should be an array of integers.\n", + "\n", + "Use schema : { frequencies: []; timeUnit: string }\n", + "\n", + "Note that the frequencies should be possible times of administrations per dag\n", + "If extraction is not possible return: \"{\"frequencies\":[],\"timeUnit\":\"dag\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"frequencies\":[4],\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract all mentioned dose quantities.\n", + "A quantity should match the regular expresion between the ticks '(\\d+(\\.\\d+)?\\s?(mg)(\\/(kg|dag|keer|dosis))?(\\s?\\/\\s?(kg|dag|keer|dosis))?\\s)'\n", + "\n", + "Return dose quantities as a list of JSON\n", + "Use schema :\n", + "{\n", + " \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"quantities\": {\n", + " \"type\": \"array\",\n", + " \"items\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"minQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"maxQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"unit\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"mg\", \"mg/kg\"]\n", + " }\n", + " },\n", + " \"required\": [\"minQty\", \"maxQty\", \"unit\"]\n", + " }\n", + " }\n", + " },\n", + " \"required\": [\"quantities\"]\n", + "}\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"quantities\":[{\"maxQty\":15.0,\"minQty\":10.0,\"unit\":\"mg/kg\"},{\"maxQty\":4000.0,\"minQty\":60.0,\"unit\":\"mg\"}]}\n", + "\n", + "## Failed test: { doseQuantities = [|{ maxQty = 15.0\n", + " minQty = 10.0\n", + " unit = \"mg/kg\" }; { maxQty = 4000.0\n", + " minQty = 60.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"kg\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [4]\n", + " timeUnit = \"dag\" } } is not { doseQuantities = [|{ maxQty = 0.0\n", + " minQty = 0.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"kg\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [4]\n", + " timeUnit = \"dag\" } }\n", + "\n", + "## System:\n", + "You are an expert on medication prescribing, preparation and administration. You will give\n", + "exact answers. If there is no possible answer return an empty string.\n", + "You will be asked to extract structured information from the following text between ''':\n", + "\n", + "'''\n", + "amitriptyline\n", + "6 jaar tot 18 jaar Startdosering: voor de nacht: 10 mg/dag in 1 dosisOnderhoudsdosering: langzaam ophogen met 10 mg/dag per 4-6 weken naar 10 - 30 mg/dag in 1 dosis. Max: 30 mg/dag. Behandeling met amitriptyline mag niet plotseling worden gestaakt vanwege het optreden van ontwenningsverschijnselen; de dosering moet geleidelijk worden verminderd.Uit de studie van Powers (2017) blijkt dat de werkzaamheid van amitriptyline bij migraine profylaxe niet effectiever is t.o.v. placebo. Desondanks menen experts dat in individuele gevallen behandeling met amitriptyline overwogen kan worden.\n", + "'''\n", + "\n", + "ONLY respond if the response is actually present in the text. If the response cannot be extracted\n", + "respond with an empty string for a textfield or zero for a number field.\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement for the medication substance (substance unit)\n", + "from the medication dosage information contained in the text.\n", + "\n", + "Use schema: { substanceUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + " - For \"mg/kg/dag\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + " - For \"g/m2/dag\", return: \"{ \"substanceUnit\": \"g\" }\"\n", + " - For \"IE/m2\", return: \"{ \"substanceUnit\": \"IE\" }\"\n", + " - For \"mg/2 dagen\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + "\n", + "\n", + "## Answer:\n", + "{\"substanceUnit\":\"mg\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement by which a medication dose is adjusted,\n", + "such as patient weight or body surface area, from the medication dosage information contained in the text.\n", + "\n", + "Use schema : { adjustUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/kg\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/m2/dag\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "- For \"mg/m2\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"adjustUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"adjustUnit\":\"\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the time unit from the medication dosage information contained in the text.\n", + "The timeunit is the unit by which the frequency of administration is measured.\n", + "\n", + "Use schema : { timeUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"timeUnit\": \"dag\" }\"\n", + "- For \"mg/kg\", return: \"{ \"timeUnit\": \"\" }\"\n", + "- For \"mg/m2/week\", return: \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"mg/2 dagen\", return: \"{ \"timeUnit\": \"2 dagen\" }\"\n", + "- For \"per week\", return \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"per dag\", return \"{ \"timeUnit\": \"week\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"timeUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the frequencies by which the drug can be administered.\n", + "The frequencies field in the schema should be an array of integers.\n", + "\n", + "Use schema : { frequencies: []; timeUnit: string }\n", + "\n", + "Note that the frequencies should be possible times of administrations per dag\n", + "If extraction is not possible return: \"{\"frequencies\":[],\"timeUnit\":\"dag\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"frequencies\":[1],\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract all mentioned dose quantities.\n", + "A quantity should match the regular expresion between the ticks '(\\d+(\\.\\d+)?\\s?(mg)(\\/(dag|keer|dosis))?(\\s?\\/\\s?(dag))?\\s)'\n", + "\n", + "Return dose quantities as a list of JSON\n", + "Use schema :\n", + "{\n", + " \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"quantities\": {\n", + " \"type\": \"array\",\n", + " \"items\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"minQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"maxQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"unit\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"mg\", \"mg/kg\"]\n", + " }\n", + " },\n", + " \"required\": [\"minQty\", \"maxQty\", \"unit\"]\n", + " }\n", + " }\n", + " },\n", + " \"required\": [\"quantities\"]\n", + "}\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"quantities\":[{\"maxQty\":30.0,\"minQty\":10.0,\"unit\":\"mg\"},{\"maxQty\":30.0,\"minQty\":10.0,\"unit\":\"mg\"}]}\n", + "\n", + "## Failed test: { doseQuantities = [|{ maxQty = 30.0\n", + " minQty = 10.0\n", + " unit = \"mg\" }; { maxQty = 30.0\n", + " minQty = 10.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [1]\n", + " timeUnit = \"dag\" } } is not { doseQuantities = [|{ maxQty = 0.0\n", + " minQty = 0.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [1]\n", + " timeUnit = \"dag\" } }\n", + "\n", + "## System:\n", + "You are an expert on medication prescribing, preparation and administration. You will give\n", + "exact answers. If there is no possible answer return an empty string.\n", + "You will be asked to extract structured information from the following text between ''':\n", + "\n", + "'''\n", + "aciclovir\n", + "3 maanden tot 18 jaar 1.500 mg/m2/dag in 3 doses.Behandelduur: Herpes encefalitis: 14-21 dagen Varicella zoster: 7 dagen\n", + "'''\n", + "\n", + "ONLY respond if the response is actually present in the text. If the response cannot be extracted\n", + "respond with an empty string for a textfield or zero for a number field.\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement for the medication substance (substance unit)\n", + "from the medication dosage information contained in the text.\n", + "\n", + "Use schema: { substanceUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + " - For \"mg/kg/dag\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + " - For \"g/m2/dag\", return: \"{ \"substanceUnit\": \"g\" }\"\n", + " - For \"IE/m2\", return: \"{ \"substanceUnit\": \"IE\" }\"\n", + " - For \"mg/2 dagen\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + "\n", + "\n", + "## Answer:\n", + "{\"substanceUnit\":\"mg/m2/dag\"}\n", + "\n", + "\n", + "## Question:\n", + "The answer: |{\"substanceUnit\":\"mg/m2/dag\"}| was not correct because of mg/m2/dag is not a valid unit, this is not one unit but 3 units, just one unit should be extracted, so, the extracted unit should not contain '/'. Please try again answering:\n", + "\n", + "\n", + "Use the provided schema to extract the unit of measurement for the medication substance (substance unit)\n", + "from the medication dosage information contained in the text.\n", + "\n", + "Use schema: { substanceUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + " - For \"mg/kg/dag\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + " - For \"g/m2/dag\", return: \"{ \"substanceUnit\": \"g\" }\"\n", + " - For \"IE/m2\", return: \"{ \"substanceUnit\": \"IE\" }\"\n", + " - For \"mg/2 dagen\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + "\n", + "\n", + "## Answer:\n", + "{\"substanceUnit\":\"mg\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement by which a medication dose is adjusted,\n", + "such as patient weight or body surface area, from the medication dosage information contained in the text.\n", + "\n", + "Use schema : { adjustUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/kg\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/m2/dag\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "- For \"mg/m2\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"adjustUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"adjustUnit\":\"m2\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the time unit from the medication dosage information contained in the text.\n", + "The timeunit is the unit by which the frequency of administration is measured.\n", + "\n", + "Use schema : { timeUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"timeUnit\": \"dag\" }\"\n", + "- For \"mg/kg\", return: \"{ \"timeUnit\": \"\" }\"\n", + "- For \"mg/m2/week\", return: \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"mg/2 dagen\", return: \"{ \"timeUnit\": \"2 dagen\" }\"\n", + "- For \"per week\", return \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"per dag\", return \"{ \"timeUnit\": \"week\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"timeUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the frequencies by which the drug can be administered.\n", + "The frequencies field in the schema should be an array of integers.\n", + "\n", + "Use schema : { frequencies: []; timeUnit: string }\n", + "\n", + "Note that the frequencies should be possible times of administrations per dag\n", + "If extraction is not possible return: \"{\"frequencies\":[],\"timeUnit\":\"dag\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"frequencies\":[1,1,1],\"timeUnit\":\"dag\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract all mentioned dose quantities.\n", + "A quantity should match the regular expresion between the ticks '(\\d+(\\.\\d+)?\\s?(mg)(\\/(m2|dag|keer|dosis))?(\\s?\\/\\s?(m2|dag|keer|dosis))?\\s)'\n", + "\n", + "Return dose quantities as a list of JSON\n", + "Use schema :\n", + "{\n", + " \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"quantities\": {\n", + " \"type\": \"array\",\n", + " \"items\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"minQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"maxQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"unit\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"mg\", \"mg/kg\"]\n", + " }\n", + " },\n", + " \"required\": [\"minQty\", \"maxQty\", \"unit\"]\n", + " }\n", + " }\n", + " },\n", + " \"required\": [\"quantities\"]\n", + "}\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"quantities\":[{\"maxQty\":1.5,\"minQty\":1.5,\"unit\":\"mg/m2/dag\"}]}\n", + "\n", + "## Failed test: { doseQuantities = [|{ maxQty = 1.5\n", + " minQty = 1.5\n", + " unit = \"mg/m2/dag\" }|]\n", + " doseUnits = { adjustUnit = \"m2\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"dag\" }\n", + " freqs = { frequencies = [1; 1; 1]\n", + " timeUnit = \"dag\" } } is not { doseQuantities = [|{ maxQty = 0.0\n", + " minQty = 0.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"m2\"\n", " substanceUnit = \"mg\"\n", " timeUnit = \"dag\" }\n", " freqs = { frequencies = [3]\n", " timeUnit = \"dag\" } }\n", + "\n", + "## System:\n", + "You are an expert on medication prescribing, preparation and administration. You will give\n", + "exact answers. If there is no possible answer return an empty string.\n", + "You will be asked to extract structured information from the following text between ''':\n", + "\n", + "'''\n", + "aprepitant\n", + "3 jaar tot 18 jaar en < 40 kg 2 maal per week 40 mg/dosis verdeeld over de week.\n", + "'''\n", + "\n", + "ONLY respond if the response is actually present in the text. If the response cannot be extracted\n", + "respond with an empty string for a textfield or zero for a number field.\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement for the medication substance (substance unit)\n", + "from the medication dosage information contained in the text.\n", + "\n", + "Use schema: { substanceUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + " - For \"mg/kg/dag\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + " - For \"g/m2/dag\", return: \"{ \"substanceUnit\": \"g\" }\"\n", + " - For \"IE/m2\", return: \"{ \"substanceUnit\": \"IE\" }\"\n", + " - For \"mg/2 dagen\", return: \"{ \"substanceUnit\": \"mg\" }\"\n", + "\n", + "\n", + "## Answer:\n", + "{\"substanceUnit\":\"mg\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the unit of measurement by which a medication dose is adjusted,\n", + "such as patient weight or body surface area, from the medication dosage information contained in the text.\n", + "\n", + "Use schema : { adjustUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/kg\", return: \"{ \"adjustUnit\": \"kg\" }\"\n", + "- For \"mg/m2/dag\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "- For \"mg/m2\", return: \"{ \"adjustUnit\": \"m2\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"adjustUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"adjustUnit\":\"\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the time unit from the medication dosage information contained in the text.\n", + "The timeunit is the unit by which the frequency of administration is measured.\n", + "\n", + "Use schema : { timeUnit: string }\n", + "\n", + "Here are some examples and expected output:\n", + "- For \"mg/kg/dag\", return: \"{ \"timeUnit\": \"dag\" }\"\n", + "- For \"mg/kg\", return: \"{ \"timeUnit\": \"\" }\"\n", + "- For \"mg/m2/week\", return: \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"mg/2 dagen\", return: \"{ \"timeUnit\": \"2 dagen\" }\"\n", + "- For \"per week\", return \"{ \"timeUnit\": \"week\" }\"\n", + "- For \"per dag\", return \"{ \"timeUnit\": \"week\" }\"\n", + "\n", + "If extraction is not possible return: \"{\"timeUnit\":\"\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"timeUnit\":\"week\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract the frequencies by which the drug can be administered.\n", + "The frequencies field in the schema should be an array of integers.\n", + "\n", + "Use schema : { frequencies: []; timeUnit: string }\n", + "\n", + "Note that the frequencies should be possible times of administrations per week\n", + "If extraction is not possible return: \"{\"frequencies\":[],\"timeUnit\":\"week\"}\"\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"frequencies\":[2],\"timeUnit\":\"week\"}\n", + "\n", + "\n", + "## Question:\n", + "Use the provided schema to extract all mentioned dose quantities.\n", + "A quantity should match the regular expresion between the ticks '(\\d+(\\.\\d+)?\\s?(mg)(\\/(week|keer|dosis))?(\\s?\\/\\s?(week))?\\s)'\n", + "\n", + "Return dose quantities as a list of JSON\n", + "Use schema :\n", + "{\n", + " \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"quantities\": {\n", + " \"type\": \"array\",\n", + " \"items\": {\n", + " \"type\": \"object\",\n", + " \"properties\": {\n", + " \"minQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"maxQty\": {\n", + " \"type\": \"number\",\n", + " \"minimum\": 0\n", + " },\n", + " \"unit\": {\n", + " \"type\": \"string\",\n", + " \"enum\": [\"mg\", \"mg/kg\"]\n", + " }\n", + " },\n", + " \"required\": [\"minQty\", \"maxQty\", \"unit\"]\n", + " }\n", + " }\n", + " },\n", + " \"required\": [\"quantities\"]\n", + "}\n", + "\n", + "Respond in JSON\n", + "\n", + "\n", + "## Answer:\n", + "{\"quantities\":[{\"maxQty\":40.0,\"minQty\":40.0,\"unit\":\"mg\"},{\"maxQty\":40.0,\"minQty\":40.0,\"unit\":\"mg\"}]}\n", + "\n", + "## Failed test: { doseQuantities = [|{ maxQty = 40.0\n", + " minQty = 40.0\n", + " unit = \"mg\" }; { maxQty = 40.0\n", + " minQty = 40.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"week\" }\n", + " freqs = { frequencies = [2]\n", + " timeUnit = \"week\" } } is not { doseQuantities = [|{ maxQty = 40.0\n", + " minQty = 40.0\n", + " unit = \"mg\" }|]\n", + " doseUnits = { adjustUnit = \"\"\n", + " substanceUnit = \"mg\"\n", + " timeUnit = \"week\" }\n", + " freqs = { frequencies = [2]\n", + " timeUnit = \"week\" } }\n", "score: 0\n" ] } @@ -245,13 +1008,14 @@ "// Ollama.Models.``llama-pro``\n", "// Ollama.Models.``openchat:7b``\n", "// Ollama.Models.``llama2:13b-chat``\n", - " Ollama.Models.mistral\n", + "// Ollama.Models.mistral\n", + " \"gemma2\"\n", " ]\n", " |> List.map (fun model -> \n", " printf $\"- Testing: {model}: \"\n", " let s = \n", " Texts.testMinMaxDoseQtyTexts\n", - " |> List.take 1\n", + " //|> List.take 1\n", " |> test \n", " Ollama.Extract.minMaxDose \n", " (List.iter Message.print) \n", @@ -264,7 +1028,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -280,42 +1044,12 @@ "text": [ "\n", "\n", - "## And the winner is: mistral with a high score: 1 from 6\n", + "## And the winner is: gemma2 with a high score: 0 from 6\n", "## Score: 0\n", "## Text:\n", "\n", "alprazolam\n", "6 jaar tot 18 jaar Startdosering: 0,125 mg/dag, éénmalig. Onderhoudsdosering: Op geleide van klinisch beeld verhogen met stappen van 0,125-0,25 mg/dosis tot max 0,05 mg/kg/dag in 3 doses. Max: 3 mg/dag. Advies inname/toediening: De dagdosis indien mogelijk verdelen over 3 doses.Bij plotselinge extreme slapeloosheid: alleen voor de nacht innemen; dosering op geleide van effect ophogen tot max 0,05 mg/kg, maar niet hoger dan 3 mg/dag.De effectiviteit bij de behandeling van acute angst is discutabel.\n", - "\n", - "## Score: 0\n", - "## Text:\n", - "\n", - "acetylsalicylzuur\n", - "1 maand tot 18 jaar Startdosering:Acetylsalicylzuur: 30 - 50 mg/kg/dag in 3 - 4 doses. Max: 3.000 mg/dag.\n", - "\n", - "## Score: 0\n", - "## Text:\n", - "\n", - "paracetamol\n", - "Oraal: Bij milde tot matige pijn en/of koorts: volgens het Kinderformularium van het NKFK bij een leeftijd van 1 maand–18 jaar: 10–15 mg/kg lichaamsgewicht per keer, zo nodig 4×/dag, max. 60 mg/kg/dag en max. 4 g/dag.\n", - "\n", - "## Score: 0\n", - "## Text:\n", - "\n", - "amitriptyline\n", - "6 jaar tot 18 jaar Startdosering: voor de nacht: 10 mg/dag in 1 dosisOnderhoudsdosering: langzaam ophogen met 10 mg/dag per 4-6 weken naar 10 - 30 mg/dag in 1 dosis. Max: 30 mg/dag. Behandeling met amitriptyline mag niet plotseling worden gestaakt vanwege het optreden van ontwenningsverschijnselen; de dosering moet geleidelijk worden verminderd.Uit de studie van Powers (2017) blijkt dat de werkzaamheid van amitriptyline bij migraine profylaxe niet effectiever is t.o.v. placebo. Desondanks menen experts dat in individuele gevallen behandeling met amitriptyline overwogen kan worden.\n", - "\n", - "## Score: 0\n", - "## Text:\n", - "\n", - "aciclovir\n", - "3 maanden tot 18 jaar 1.500 mg/m2/dag in 3 doses.Behandelduur: Herpes encefalitis: 14-21 dagen Varicella zoster: 7 dagen\n", - "\n", - "## Score: 1\n", - "## Text:\n", - "\n", - "aprepitant\n", - "3 jaar tot 18 jaar en < 40 kg 2 maal per week 40 mg/dosis verdeeld over de week.\n", "\n" ] } diff --git a/src/Informedica.OpenAI.Lib/Notebooks/StructuredJSON_UsingStateMonad.ipynb b/src/Informedica.OpenAI.Lib/Notebooks/StructuredJSON_UsingStateMonad.ipynb index bf3f177..c0b62fc 100644 --- a/src/Informedica.OpenAI.Lib/Notebooks/StructuredJSON_UsingStateMonad.ipynb +++ b/src/Informedica.OpenAI.Lib/Notebooks/StructuredJSON_UsingStateMonad.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -91,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -141,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -193,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -288,7 +288,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -325,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": { "dotnet_interactive": { "language": "fsharp" @@ -397,11 +397,14 @@ "\n", "\n", "## Answer:\n", - "{\"adjustUnit\":\"kg\"}\n", + "{\"adjustUnit\":null}\n", "\n", "\n", "## Question:\n", - "The answer: {\"adjustUnit\":\"kg\"} was not correct because of kg is not mentionned in the text. Please try again answering:\n", + "The answer: |{\"adjustUnit\":null}| was not correct because of \n", + "{\"adjustUnit\":null} is not a valid unit, the unit should not contain '/' and the unit should be one of the following:\n", + "kg, m2, mˆ2\n", + ". Please try again answering:\n", "\n", "\n", "Use the provided schema to extract the unit by which a medication dose is adjusted, such as patient weight or body surface area, from the medication dosage information contained in the text.\n", @@ -419,7 +422,7 @@ "\n", "\n", "## Answer:\n", - "{\"adjustUnit\":\"\"}\n", + "{\"adjustUnit\":null}\n", "\n", "\n", "## Question:\n", @@ -447,7 +450,7 @@ "let un, msgs =\n", " let text = Texts.testTexts[3]\n", " State.run\n", - " (createDoseUnits Ollama.Models.llama2 text)\n", + " (createDoseUnits \"gemma2\" text)\n", " (systemMsg text)\n", "\n", "printfn $\"## The final exctracted structure:\\n{un}\\n\\n\"\n", diff --git a/src/Informedica.OpenAI.Lib/Ollama.fs b/src/Informedica.OpenAI.Lib/Ollama.fs index 7986b21..99fcf2c 100644 --- a/src/Informedica.OpenAI.Lib/Ollama.fs +++ b/src/Informedica.OpenAI.Lib/Ollama.fs @@ -435,6 +435,8 @@ module Ollama = let gemma = "gemma" + let gemma2 = "gemma2" + let ``gemma:7b-instruct`` = "gemma:7b-instruct" let mistral = "mistral"