@awell-health/awell-extensions 2.0.152 → 2.0.153
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.js +33 -113
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/findAppointmentsByPrompt.js.map +1 -1
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.d.ts +2 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.js +15 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/getAppoitnmentCountByStatus.js.map +1 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM.d.ts +14 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM.js +36 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/findAppointmentsByPromptWithLLM.js.map +1 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/parser.d.ts +17 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/parser.js +14 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/parser.js.map +1 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/prompt.d.ts +2 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/prompt.js +24 -0
- package/dist/extensions/elation/actions/findAppointmentsByPrompt/lib/findAppointmentsByPromptWithLLM/prompt.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/findFutureAppointment.d.ts +1 -1
- package/dist/extensions/elation/actions/findFutureAppointment/findFutureAppointment.js +32 -90
- package/dist/extensions/elation/actions/findFutureAppointment/findFutureAppointment.js.map +1 -1
- package/dist/extensions/elation/actions/findFutureAppointment/formatAppointments.d.ts +2 -0
- package/dist/extensions/elation/actions/findFutureAppointment/formatAppointments.js +18 -0
- package/dist/extensions/elation/actions/findFutureAppointment/formatAppointments.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/getFutureAppoitnments.d.ts +3 -0
- package/dist/extensions/elation/actions/findFutureAppointment/getFutureAppoitnments.js +15 -0
- package/dist/extensions/elation/actions/findFutureAppointment/getFutureAppoitnments.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/findAppointmentWithLLM.d.ts +14 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/findAppointmentWithLLM.js +29 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/findAppointmentWithLLM.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/parser.d.ts +17 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/parser.js +16 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/parser.js.map +1 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/prompt.d.ts +2 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/prompt.js +20 -0
- package/dist/extensions/elation/actions/findFutureAppointment/lib/findAppointmentWithLLM/prompt.js.map +1 -0
- package/dist/extensions/elation/actions/index.d.ts +0 -210
- package/dist/extensions/elation/actions/updatePatientTags/config/types.d.ts +29 -0
- package/dist/extensions/elation/actions/updatePatientTags/config/types.js +21 -0
- package/dist/extensions/elation/actions/updatePatientTags/config/types.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/getTagsFromLLM.d.ts +13 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/getTagsFromLLM.js +29 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/getTagsFromLLM.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/parser.d.ts +13 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/parser.js +7 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/parser.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/prompt.d.ts +2 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/prompt.js +22 -0
- package/dist/extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/prompt.js.map +1 -0
- package/dist/extensions/elation/actions/updatePatientTags/updatePatientTags.d.ts +8 -0
- package/dist/extensions/elation/actions/updatePatientTags/updatePatientTags.js +35 -77
- package/dist/extensions/elation/actions/updatePatientTags/updatePatientTags.js.map +1 -1
- package/dist/extensions/elation/actions/updatePatientTags/updateTags.d.ts +2 -0
- package/dist/extensions/elation/actions/updatePatientTags/updateTags.js +18 -0
- package/dist/extensions/elation/actions/updatePatientTags/updateTags.js.map +1 -0
- package/dist/extensions/elation/settings.d.ts +1 -10
- package/dist/extensions/elation/settings.js +0 -8
- package/dist/extensions/elation/settings.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.d.ts +10 -2
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js +32 -24
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.d.ts +22 -2
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js +22 -7
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.d.ts +20 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.js +18 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.js.map +1 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.d.ts +13 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js +35 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/actions/generateMessage/generateMessage.d.ts +10 -2
- package/dist/extensions/shelly/actions/generateMessage/generateMessage.js +33 -25
- package/dist/extensions/shelly/actions/generateMessage/generateMessage.js.map +1 -1
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/generateMessageWithLLM.d.ts +18 -2
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/generateMessageWithLLM.js +23 -10
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/generateMessageWithLLM.js.map +1 -1
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/parser.d.ts +28 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/parser.js +17 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/parser.js.map +1 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/prompt.d.ts +10 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/prompt.js +121 -0
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/actions/index.d.ts +7 -63
- package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.d.ts +1 -2
- package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.js.map +1 -1
- package/dist/extensions/shelly/actions/reviewMedicationExtraction/reviewMedicationExtraction.d.ts +1 -2
- package/dist/extensions/shelly/actions/reviewMedicationExtraction/reviewMedicationExtraction.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/{constants.js → prompt.js} +1 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.d.ts +22 -2
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js +30 -8
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.d.ts +1 -2
- package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js +24 -21
- package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.d.ts +10 -2
- package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js +42 -28
- package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js.map +1 -1
- package/dist/extensions/shelly/actions/summarizeFormsInStep/summarizeFormsInStep.d.ts +1 -2
- package/dist/extensions/shelly/actions/summarizeFormsInStep/summarizeFormsInStep.js +29 -26
- package/dist/extensions/shelly/actions/summarizeFormsInStep/summarizeFormsInStep.js.map +1 -1
- package/dist/extensions/shelly/index.js +2 -3
- package/dist/extensions/shelly/index.js.map +1 -1
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/{constants.js → prompt.js} +1 -1
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/prompt.js.map +1 -0
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/summarizeFormWithLLM.d.ts +23 -2
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/summarizeFormWithLLM.js +33 -9
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/summarizeFormWithLLM.js.map +1 -1
- package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.d.ts +1 -5
- package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js +5 -20
- package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js.map +1 -1
- package/dist/src/lib/llm/openai/constants.d.ts +28 -0
- package/dist/src/lib/llm/openai/constants.js +32 -0
- package/dist/src/lib/llm/openai/constants.js.map +1 -0
- package/dist/src/lib/llm/openai/createOpenAIModel.d.ts +23 -0
- package/dist/src/lib/llm/openai/createOpenAIModel.js +89 -0
- package/dist/src/lib/llm/openai/createOpenAIModel.js.map +1 -0
- package/dist/src/lib/llm/openai/index.d.ts +3 -0
- package/dist/src/lib/llm/openai/index.js +20 -0
- package/dist/src/lib/llm/openai/index.js.map +1 -0
- package/dist/src/lib/llm/openai/types.d.ts +63 -0
- package/dist/src/lib/llm/openai/types.js +3 -0
- package/dist/src/lib/llm/openai/types.js.map +1 -0
- package/package.json +5 -4
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.d.ts +0 -24
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js +0 -33
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/constants.d.ts +0 -24
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/constants.js +0 -123
- package/dist/extensions/shelly/actions/generateMessage/lib/generateMessageWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/lib/summarizeFormWithLLM/constants.js.map +0 -1
- package/dist/extensions/shelly/settings.d.ts +0 -17
- package/dist/extensions/shelly/settings.js +0 -17
- package/dist/extensions/shelly/settings.js.map +0 -1
- /package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/{constants.d.ts → prompt.d.ts} +0 -0
- /package/dist/extensions/shelly/lib/summarizeFormWithLLM/{constants.d.ts → prompt.d.ts} +0 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.systemPrompt = void 0;
|
4
|
+
const prompts_1 = require("@langchain/core/prompts");
|
5
|
+
exports.systemPrompt = prompts_1.ChatPromptTemplate.fromTemplate(`
|
6
|
+
You are a clinical data manager. You will receive a list (array) of patient tags for a single patient and instructions about which tags to add, update, or remove. These tags are used to assign particular attributes to patients which can help with patient care, like grouping of patients, categorizing patients for reporting, or identifying patients for care.
|
7
|
+
|
8
|
+
Important instructions:
|
9
|
+
- The maximum number of tags is 10.
|
10
|
+
- The max length of a single tag is 100 characters.
|
11
|
+
- Ensure tags are unique.
|
12
|
+
|
13
|
+
|
14
|
+
Input array: {existingTags}
|
15
|
+
Instruction: {prompt}
|
16
|
+
|
17
|
+
|
18
|
+
Output a JSON object with two keys:
|
19
|
+
1. updatedTags: The updated array of tags. If the input array is empty, the output should be an empty array.
|
20
|
+
2. explanation: A readable explanation of the changes made to the tags and why
|
21
|
+
`);
|
22
|
+
//# sourceMappingURL=prompt.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../../../extensions/elation/actions/updatePatientTags/lib/getTagsFromLLM/prompt.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAE/C,QAAA,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;CAgB3D,CAAC,CAAA"}
|
@@ -1,4 +1,12 @@
|
|
1
1
|
import { type Action } from '@awell-health/extensions-core';
|
2
2
|
import { type settings } from '../../settings';
|
3
3
|
import { fields, dataPoints } from './config';
|
4
|
+
/**
|
5
|
+
* Awell Action: Update Patient Tags
|
6
|
+
*
|
7
|
+
* Takes existing tags and instructions, uses LLM to:
|
8
|
+
* 1. Generate updated list of tags
|
9
|
+
* 2. Provide explanation for changes
|
10
|
+
* 3. Update tags in Elation
|
11
|
+
*/
|
4
12
|
export declare const updatePatientTags: Action<typeof fields, typeof settings, keyof typeof dataPoints>;
|
@@ -2,103 +2,61 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.updatePatientTags = void 0;
|
4
4
|
const extensions_core_1 = require("@awell-health/extensions-core");
|
5
|
+
const addEventLog_1 = require("../../../../src/lib/awell/addEventLog");
|
5
6
|
const client_1 = require("../../client");
|
6
7
|
const config_1 = require("./config");
|
7
|
-
const
|
8
|
-
const
|
9
|
-
const
|
10
|
-
const
|
8
|
+
const updateTags_1 = require("./updateTags");
|
9
|
+
const getTagsFromLLM_1 = require("./lib/getTagsFromLLM/getTagsFromLLM");
|
10
|
+
const createOpenAIModel_1 = require("../../../../src/lib/llm/openai/createOpenAIModel");
|
11
|
+
const constants_1 = require("../../../../src/lib/llm/openai/constants");
|
12
|
+
/**
|
13
|
+
* Awell Action: Update Patient Tags
|
14
|
+
*
|
15
|
+
* Takes existing tags and instructions, uses LLM to:
|
16
|
+
* 1. Generate updated list of tags
|
17
|
+
* 2. Provide explanation for changes
|
18
|
+
* 3. Update tags in Elation
|
19
|
+
*/
|
11
20
|
exports.updatePatientTags = {
|
12
21
|
key: 'updatePatientTags',
|
13
22
|
category: extensions_core_1.Category.EHR_INTEGRATIONS,
|
14
|
-
title: '🪄 Update patient tags',
|
23
|
+
title: '🪄 Update patient tags (Beta)',
|
15
24
|
description: 'Update patient tags in Elation.',
|
16
25
|
fields: config_1.fields,
|
17
26
|
previewable: false,
|
18
27
|
dataPoints: config_1.dataPoints,
|
19
|
-
onEvent: async ({ payload, onComplete, onError }) => {
|
28
|
+
onEvent: async ({ payload, onComplete, onError, helpers }) => {
|
29
|
+
// 1. Validate input and initialize API client
|
20
30
|
const { prompt, patientId } = config_1.FieldsValidationSchema.parse(payload.fields);
|
21
31
|
const api = (0, client_1.makeAPIClient)(payload.settings);
|
22
|
-
|
23
|
-
if (openAiApiKey === undefined || openAiApiKey === '') {
|
24
|
-
await onError({
|
25
|
-
events: [
|
26
|
-
{
|
27
|
-
date: new Date().toISOString(),
|
28
|
-
text: { en: 'OpenAI API key is required for this action.' },
|
29
|
-
error: {
|
30
|
-
category: 'SERVER_ERROR',
|
31
|
-
message: 'OpenAI API key is required for this action.',
|
32
|
-
},
|
33
|
-
},
|
34
|
-
],
|
35
|
-
});
|
36
|
-
return;
|
37
|
-
}
|
32
|
+
// 2. Get existing tags
|
38
33
|
const { tags } = await api.getPatient(patientId);
|
39
34
|
const existingTags = tags !== null && tags !== void 0 ? tags : [];
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
// 3. Initialize OpenAI model with metadata and callbacks
|
36
|
+
const { model, metadata, callbacks } = await (0, createOpenAIModel_1.createOpenAIModel)({
|
37
|
+
settings: payload.settings,
|
38
|
+
helpers,
|
39
|
+
payload,
|
40
|
+
modelType: constants_1.OPENAI_MODELS.GPT4o
|
41
|
+
});
|
42
|
+
// 4. Generate updated tags
|
43
|
+
const { validatedTags, explanation } = await (0, getTagsFromLLM_1.getTagsFromLLM)({
|
44
|
+
model,
|
45
|
+
existingTags,
|
46
|
+
prompt,
|
47
|
+
metadata,
|
48
|
+
callbacks
|
46
49
|
});
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
- The maximum number of tags is 10.
|
51
|
-
- The max length of a single tag is 100 characters.
|
52
|
-
- Ensure tags are unique.
|
53
|
-
|
54
|
-
Input array: ${JSON.stringify(existingTags)}
|
55
|
-
Instruction: ${prompt}
|
56
|
-
|
57
|
-
Output a JSON object with two keys:
|
58
|
-
1. updatedTags: The updated array of tags. If the input array is empty, the output should be an empty array.
|
59
|
-
2. explanation: A readable explanation of the changes made to the tags and why`;
|
60
|
-
const SingleTagSchema = zod_1.z.string().max(100).describe('A single tag');
|
61
|
-
const TagsSchema = zod_1.z
|
62
|
-
.array(SingleTagSchema)
|
63
|
-
.max(10)
|
64
|
-
.refine((items) => new Set(items).size === items.length, {
|
65
|
-
message: 'All items must be unique, no duplicate values allowed',
|
66
|
-
})
|
67
|
-
.describe('The updated array of tags');
|
68
|
-
const parser = output_parsers_1.StructuredOutputParser.fromZodSchema(zod_1.z.object({
|
69
|
-
updatedTags: TagsSchema,
|
70
|
-
explanation: zod_1.z
|
71
|
-
.string()
|
72
|
-
.describe('A readable explanation of the changes made to the tags and why'),
|
73
|
-
}));
|
74
|
-
let result;
|
75
|
-
try {
|
76
|
-
const chain = ChatModelGPT4o.pipe(parser);
|
77
|
-
result = await chain.invoke(systemPrompt);
|
78
|
-
}
|
79
|
-
catch (invokeError) {
|
80
|
-
console.error('Error invoking ChatModelGPT4o for updatePatientTags:', invokeError);
|
81
|
-
throw new Error('Failed to update patient tags.');
|
82
|
-
}
|
83
|
-
const validatedTags = TagsSchema.parse(result.updatedTags);
|
84
|
-
if (validatedTags.length === 0) {
|
85
|
-
await api.updatePatient(patientId, {
|
86
|
-
// @ts-expect-error - elation api does not clear tags on an empty array
|
87
|
-
tags: ' ',
|
88
|
-
});
|
89
|
-
}
|
90
|
-
else {
|
91
|
-
await api.updatePatient(patientId, {
|
92
|
-
tags: validatedTags,
|
93
|
-
});
|
94
|
-
}
|
50
|
+
// 5. Update tags in Elation
|
51
|
+
await (0, updateTags_1.updateElationTags)(api, patientId, validatedTags);
|
52
|
+
// 6. Complete action with results
|
95
53
|
await onComplete({
|
96
54
|
data_points: {
|
97
55
|
updatedTags: validatedTags.join(', '),
|
98
56
|
},
|
99
57
|
events: [
|
100
58
|
(0, addEventLog_1.addActivityEventLog)({
|
101
|
-
message: `Previous patient tags: ${(existingTags === null || existingTags === void 0 ? void 0 : existingTags.length) > 0 ? existingTags === null || existingTags === void 0 ? void 0 : existingTags.join(', ') : 'No tags'}\nUpdated patient tags: ${validatedTags.join(', ')}\nExplanation: ${
|
59
|
+
message: `Previous patient tags: ${(existingTags === null || existingTags === void 0 ? void 0 : existingTags.length) > 0 ? existingTags === null || existingTags === void 0 ? void 0 : existingTags.join(', ') : 'No tags'}\nUpdated patient tags: ${validatedTags.join(', ')}\nExplanation: ${explanation}`,
|
102
60
|
}),
|
103
61
|
],
|
104
62
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updatePatientTags.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/updatePatientTags/updatePatientTags.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;
|
1
|
+
{"version":3,"file":"updatePatientTags.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/updatePatientTags/updatePatientTags.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,uEAA2E;AAE3E,yCAA4C;AAC5C,qCAAqE;AACrE,6CAAgD;AAChD,wEAAoE;AACpE,wFAAoF;AACpF,wEAAwE;AAExE;;;;;;;GAOG;AACU,QAAA,iBAAiB,GAI1B;IACF,GAAG,EAAE,mBAAmB;IACxB,QAAQ,EAAE,0BAAQ,CAAC,gBAAgB;IACnC,KAAK,EAAE,+BAA+B;IACtC,WAAW,EAAE,iCAAiC;IAC9C,MAAM,EAAN,eAAM;IACN,WAAW,EAAE,KAAK;IAClB,UAAU,EAAV,mBAAU;IACV,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EAAiB,EAAE;QAC1E,8CAA8C;QAC9C,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,+BAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC1E,MAAM,GAAG,GAAG,IAAA,sBAAa,EAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QAE3C,uBAAuB;QACvB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAChD,MAAM,YAAY,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAA;QAE/B,yDAAyD;QACzD,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,qCAAiB,EAAC;YAC7D,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,OAAO;YACP,OAAO;YACP,SAAS,EAAE,yBAAa,CAAC,KAAK;SAC/B,CAAC,CAAA;QAEF,2BAA2B;QAC3B,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,MAAM,IAAA,+BAAc,EAAC;YAC1D,KAAK;YACL,YAAY;YACZ,MAAM;YACN,QAAQ;YACR,SAAS;SACV,CAAC,CAAA;QAEF,4BAA4B;QAC5B,MAAM,IAAA,8BAAiB,EAAC,GAAG,EAAE,SAAS,EAAE,aAAa,CAAC,CAAA;QAEtD,kCAAkC;QAClC,MAAM,UAAU,CAAC;YACf,WAAW,EAAE;gBACX,WAAW,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;aACtC;YACD,MAAM,EAAE;gBACN,IAAA,iCAAmB,EAAC;oBAClB,OAAO,EAAE,0BAA0B,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,IAAG,CAAC,CAAC,CAAC,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,2BAA2B,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,WAAW,EAAE;iBACrL,CAAC;aACH;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.updateElationTags = void 0;
|
4
|
+
const updateElationTags = async (api, patientId, tags) => {
|
5
|
+
if (tags.length === 0) {
|
6
|
+
await api.updatePatient(patientId, {
|
7
|
+
// @ts-expect-error - elation api does not clear tags on an empty array
|
8
|
+
tags: ' ',
|
9
|
+
});
|
10
|
+
}
|
11
|
+
else {
|
12
|
+
await api.updatePatient(patientId, {
|
13
|
+
tags,
|
14
|
+
});
|
15
|
+
}
|
16
|
+
};
|
17
|
+
exports.updateElationTags = updateElationTags;
|
18
|
+
//# sourceMappingURL=updateTags.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"updateTags.js","sourceRoot":"","sources":["../../../../../extensions/elation/actions/updatePatientTags/updateTags.ts"],"names":[],"mappings":";;;AAEO,MAAM,iBAAiB,GAAG,KAAK,EAAE,GAAqB,EAAE,SAAiB,EAAE,IAAc,EAAiB,EAAE;IAC/G,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,GAAG,CAAC,aAAa,CAAC,SAAS,EAAE;YACjC,uEAAuE;YACvE,IAAI,EAAE,GAAG;SACV,CAAC,CAAA;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,CAAC,aAAa,CAAC,SAAS,EAAE;YACjC,IAAI;SACL,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA;AAXU,QAAA,iBAAiB,qBAW3B"}
|
@@ -42,20 +42,12 @@ export declare const settings: {
|
|
42
42
|
description: string;
|
43
43
|
required: false;
|
44
44
|
};
|
45
|
-
openAiApiKey: {
|
46
|
-
key: string;
|
47
|
-
label: string;
|
48
|
-
obfuscated: true;
|
49
|
-
required: false;
|
50
|
-
description: string;
|
51
|
-
};
|
52
45
|
};
|
53
46
|
export declare const SettingsValidationSchema: z.ZodObject<{
|
54
47
|
base_url: z.ZodString;
|
55
48
|
auth_url: z.ZodString;
|
56
49
|
client_id: z.ZodString;
|
57
50
|
client_secret: z.ZodString;
|
58
|
-
openAiApiKey: z.ZodOptional<z.ZodString>;
|
59
51
|
/**
|
60
52
|
* Elation now uses client credentials authentication.
|
61
53
|
* We don't remove the settings just yet for backward compatibility for existing care flows.
|
@@ -70,7 +62,6 @@ export declare const SettingsValidationSchema: z.ZodObject<{
|
|
70
62
|
base_url: string;
|
71
63
|
username?: string | undefined;
|
72
64
|
password?: string | undefined;
|
73
|
-
openAiApiKey?: string | undefined;
|
74
65
|
}, {
|
75
66
|
auth_url: string;
|
76
67
|
client_id: string;
|
@@ -78,5 +69,5 @@ export declare const SettingsValidationSchema: z.ZodObject<{
|
|
78
69
|
base_url: string;
|
79
70
|
username?: string | undefined;
|
80
71
|
password?: string | undefined;
|
81
|
-
openAiApiKey?: string | undefined;
|
82
72
|
}>;
|
73
|
+
export type SettingsType = z.infer<typeof SettingsValidationSchema>;
|
@@ -45,20 +45,12 @@ exports.settings = {
|
|
45
45
|
description: '⚠️ Deprecated: Elation now uses client credentials authentication. This setting is no longer required and should be removed from your settings.',
|
46
46
|
required: false,
|
47
47
|
},
|
48
|
-
openAiApiKey: {
|
49
|
-
key: 'openAiApiKey',
|
50
|
-
label: 'OpenAI API key ',
|
51
|
-
obfuscated: true,
|
52
|
-
required: false,
|
53
|
-
description: 'Required for some actions only.',
|
54
|
-
},
|
55
48
|
};
|
56
49
|
exports.SettingsValidationSchema = zod_1.z.object({
|
57
50
|
base_url: zod_1.z.string().min(1),
|
58
51
|
auth_url: zod_1.z.string().min(1),
|
59
52
|
client_id: zod_1.z.string().min(1),
|
60
53
|
client_secret: zod_1.z.string().min(1),
|
61
|
-
openAiApiKey: zod_1.z.string().optional(),
|
62
54
|
/**
|
63
55
|
* Elation now uses client credentials authentication.
|
64
56
|
* We don't remove the settings just yet for backward compatibility for existing care flows.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../extensions/elation/settings.ts"],"names":[],"mappings":";;;AACA,6BAAwC;AAE3B,QAAA,QAAQ,GAAG;IACtB,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,8BAA8B;QAC3C,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,mBAAmB;QAC1B,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,sDAAsD;QACnE,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE,WAAW;QAClB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,mDAAmD;QAChE,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,GAAG,EAAE,eAAe;QACpB,KAAK,EAAE,eAAe;QACtB,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,uDAAuD;QACpE,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,KAAK;QACjB,WAAW,EACT,iJAAiJ;QACnJ,QAAQ,EAAE,KAAK;KAChB;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,IAAI;QAChB,WAAW,EACT,iJAAiJ;QACnJ,QAAQ,EAAE,KAAK;KAChB;
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../extensions/elation/settings.ts"],"names":[],"mappings":";;;AACA,6BAAwC;AAE3B,QAAA,QAAQ,GAAG;IACtB,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,8BAA8B;QAC3C,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,mBAAmB;QAC1B,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,sDAAsD;QACnE,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE,WAAW;QAClB,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,mDAAmD;QAChE,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,GAAG,EAAE,eAAe;QACpB,KAAK,EAAE,eAAe;QACtB,UAAU,EAAE,IAAI;QAChB,WAAW,EAAE,uDAAuD;QACpE,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,KAAK;QACjB,WAAW,EACT,iJAAiJ;QACnJ,QAAQ,EAAE,KAAK;KAChB;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,IAAI;QAChB,WAAW,EACT,iJAAiJ;QACnJ,QAAQ,EAAE,KAAK;KAChB;CACgC,CAAA;AAEtB,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC;;;;OAIG;IACH,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACoB,CAAC,CAAA"}
|
@@ -1,4 +1,12 @@
|
|
1
1
|
import { type Action } from '@awell-health/extensions-core';
|
2
|
-
import { type settings } from '../../settings';
|
3
2
|
import { fields, dataPoints } from './config';
|
4
|
-
|
3
|
+
/**
|
4
|
+
* Awell Action: Message Categorization
|
5
|
+
*
|
6
|
+
* Takes a message and predefined categories as input, uses LLM to:
|
7
|
+
* 1. Determine the most appropriate category
|
8
|
+
* 2. Provide explanation for the categorization
|
9
|
+
*
|
10
|
+
* @returns category and HTML-formatted explanation
|
11
|
+
*/
|
12
|
+
export declare const categorizeMessage: Action<typeof fields, Record<string, never>, keyof typeof dataPoints>;
|
@@ -3,42 +3,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.categorizeMessage = void 0;
|
4
4
|
const extensions_core_1 = require("@awell-health/extensions-core");
|
5
5
|
const categorizeMessageWithLLM_1 = require("./lib/categorizeMessageWithLLM");
|
6
|
-
const
|
6
|
+
const createOpenAIModel_1 = require("../../../../src/lib/llm/openai/createOpenAIModel");
|
7
|
+
const constants_1 = require("../../../../src/lib/llm/openai/constants");
|
7
8
|
const config_1 = require("./config");
|
8
9
|
const utils_1 = require("../../../../src/utils");
|
10
|
+
/**
|
11
|
+
* Awell Action: Message Categorization
|
12
|
+
*
|
13
|
+
* Takes a message and predefined categories as input, uses LLM to:
|
14
|
+
* 1. Determine the most appropriate category
|
15
|
+
* 2. Provide explanation for the categorization
|
16
|
+
*
|
17
|
+
* @returns category and HTML-formatted explanation
|
18
|
+
*/
|
9
19
|
exports.categorizeMessage = {
|
10
20
|
key: 'categorizeMessage',
|
11
21
|
category: extensions_core_1.Category.WORKFLOW,
|
12
22
|
title: 'Categorize Message',
|
13
|
-
description: '
|
23
|
+
description: 'Categorizes messages into predefined categories with explanation.',
|
14
24
|
fields: config_1.fields,
|
15
25
|
previewable: false,
|
16
26
|
dataPoints: config_1.dataPoints,
|
17
27
|
onEvent: async ({ payload, onComplete, onError, helpers }) => {
|
18
|
-
|
19
|
-
|
28
|
+
// 1. Validate input fields
|
29
|
+
const { message, categories } = config_1.FieldsValidationSchema.parse(payload.fields);
|
30
|
+
// 2. Initialize OpenAI model with metadata
|
31
|
+
const { model, metadata, callbacks } = await (0, createOpenAIModel_1.createOpenAIModel)({
|
32
|
+
settings: payload.settings,
|
33
|
+
helpers,
|
20
34
|
payload,
|
35
|
+
modelType: constants_1.OPENAI_MODELS.GPT4oMini,
|
36
|
+
});
|
37
|
+
// 3. Perform categorization
|
38
|
+
const result = await (0, categorizeMessageWithLLM_1.categorizeMessageWithLLM)({
|
39
|
+
model,
|
40
|
+
message,
|
41
|
+
categories,
|
42
|
+
metadata,
|
43
|
+
callbacks
|
44
|
+
});
|
45
|
+
// 4. Format and return results
|
46
|
+
const explanationHtml = await (0, utils_1.markdownToHtml)(result.explanation);
|
47
|
+
await onComplete({
|
48
|
+
data_points: { category: result.category, explanation: explanationHtml }
|
21
49
|
});
|
22
|
-
try {
|
23
|
-
const categorization_result = await (0, categorizeMessageWithLLM_1.categorizeMessageWithLLM)({
|
24
|
-
ChatModelGPT4oMini,
|
25
|
-
message,
|
26
|
-
categories,
|
27
|
-
});
|
28
|
-
const category = categorization_result.category;
|
29
|
-
const explanationHtml = await (0, utils_1.markdownToHtml)(categorization_result.explanation);
|
30
|
-
await onComplete({
|
31
|
-
data_points: {
|
32
|
-
category,
|
33
|
-
explanation: explanationHtml,
|
34
|
-
},
|
35
|
-
});
|
36
|
-
}
|
37
|
-
catch (error) {
|
38
|
-
console.error('Error categorizing message:', error);
|
39
|
-
// Catch in extention server
|
40
|
-
throw new Error('Error categorizing message');
|
41
|
-
}
|
42
50
|
},
|
43
51
|
};
|
44
52
|
//# sourceMappingURL=categorizeMessage.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"categorizeMessage.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/categorizeMessage/categorizeMessage.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,6EAAyE;AACzE,
|
1
|
+
{"version":3,"file":"categorizeMessage.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/categorizeMessage/categorizeMessage.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,6EAAyE;AACzE,wFAAoF;AACpF,wEAAwE;AACxE,qCAAqE;AACrE,iDAAsD;AAEtD;;;;;;;;GAQG;AACU,QAAA,iBAAiB,GAI1B;IACF,GAAG,EAAE,mBAAmB;IACxB,QAAQ,EAAE,0BAAQ,CAAC,QAAQ;IAC3B,KAAK,EAAE,oBAAoB;IAC3B,WAAW,EAAE,mEAAmE;IAChF,MAAM,EAAN,eAAM;IACN,WAAW,EAAE,KAAK;IAClB,UAAU,EAAV,mBAAU;IAEV,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EAAiB,EAAE;QAC1E,2BAA2B;QAC3B,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,+BAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE5E,2CAA2C;QAC3C,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,qCAAiB,EAAC;YAC7D,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,OAAO;YACP,OAAO;YACP,SAAS,EAAE,yBAAa,CAAC,SAAS;SACnC,CAAC,CAAA;QAEF,4BAA4B;QAC5B,MAAM,MAAM,GAAG,MAAM,IAAA,mDAAwB,EAAC;YAC5C,KAAK;YACL,OAAO;YACP,UAAU;YACV,QAAQ;YACR,SAAS;SACV,CAAC,CAAA;QAEF,+BAA+B;QAC/B,MAAM,eAAe,GAAG,MAAM,IAAA,sBAAc,EAAC,MAAM,CAAC,WAAW,CAAC,CAAA;QAChE,MAAM,UAAU,CAAC;YACf,WAAW,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE;SACzE,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
@@ -1,8 +1,28 @@
|
|
1
1
|
import { type ChatOpenAI } from '@langchain/openai';
|
2
|
-
|
3
|
-
|
2
|
+
import { type AIActionMetadata } from '../../../../../../src/lib/llm/openai/types';
|
3
|
+
import type { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
4
|
+
/**
|
5
|
+
* Uses LLM to categorize a message into predefined categories.
|
6
|
+
* The function follows these steps:
|
7
|
+
* 1. Formats prompt with available categories
|
8
|
+
* 2. Runs LLM chain with structured output parsing
|
9
|
+
* 3. Validates and processes the result
|
10
|
+
*
|
11
|
+
* @example
|
12
|
+
* const result = await categorizeMessageWithLLM({
|
13
|
+
* model,
|
14
|
+
* message: "I need to schedule an appointment",
|
15
|
+
* categories: ["Scheduling", "Medical Question"],
|
16
|
+
* metadata: { ... }
|
17
|
+
* })
|
18
|
+
* // Returns: { category: "Scheduling", explanation: "..." }
|
19
|
+
*/
|
20
|
+
export declare const categorizeMessageWithLLM: ({ model, message, categories, metadata, callbacks, }: {
|
21
|
+
model: ChatOpenAI;
|
4
22
|
message: string;
|
5
23
|
categories: string[];
|
24
|
+
metadata: AIActionMetadata;
|
25
|
+
callbacks?: BaseCallbackHandler[];
|
6
26
|
}) => Promise<{
|
7
27
|
category: string;
|
8
28
|
explanation: string;
|
@@ -1,21 +1,36 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.categorizeMessageWithLLM = void 0;
|
4
|
-
const
|
5
|
-
|
6
|
-
|
4
|
+
const parser_1 = require("./parser");
|
5
|
+
const prompt_1 = require("./prompt");
|
6
|
+
/**
|
7
|
+
* Uses LLM to categorize a message into predefined categories.
|
8
|
+
* The function follows these steps:
|
9
|
+
* 1. Formats prompt with available categories
|
10
|
+
* 2. Runs LLM chain with structured output parsing
|
11
|
+
* 3. Validates and processes the result
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* const result = await categorizeMessageWithLLM({
|
15
|
+
* model,
|
16
|
+
* message: "I need to schedule an appointment",
|
17
|
+
* categories: ["Scheduling", "Medical Question"],
|
18
|
+
* metadata: { ... }
|
19
|
+
* })
|
20
|
+
* // Returns: { category: "Scheduling", explanation: "..." }
|
21
|
+
*/
|
22
|
+
const categorizeMessageWithLLM = async ({ model, message, categories, metadata, callbacks, }) => {
|
7
23
|
var _a, _b;
|
8
|
-
const prompt = await
|
24
|
+
const prompt = await prompt_1.systemPrompt.format({
|
9
25
|
categories: categories.concat('None').join(', '),
|
10
26
|
input: message,
|
11
27
|
});
|
12
|
-
const chain =
|
28
|
+
const chain = model.pipe(parser_1.parser);
|
13
29
|
let result;
|
14
30
|
try {
|
15
|
-
result = await chain.invoke(prompt);
|
31
|
+
result = await chain.invoke(prompt, { metadata, runName: 'ShellyCategorizeMessage', callbacks });
|
16
32
|
}
|
17
33
|
catch (error) {
|
18
|
-
console.error('Error invoking the chain:', error);
|
19
34
|
throw new Error('Failed to categorize the message due to an internal error.');
|
20
35
|
}
|
21
36
|
const matchedCategory = (_a = result.matched_category) !== null && _a !== void 0 ? _a : 'None';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"categorizeMessageWithLLM.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"categorizeMessageWithLLM.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,qCAAuC;AAKvC;;;;;;;;;;;;;;;GAeG;AACI,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,KAAK,EACL,OAAO,EACP,UAAU,EACV,QAAQ,EACR,SAAS,GAOV,EAAsD,EAAE;;IACvD,MAAM,MAAM,GAAG,MAAM,qBAAY,CAAC,MAAM,CAAC;QACvC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAChD,KAAK,EAAE,OAAO;KACf,CAAC,CAAA;IAEF,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,eAAM,CAAC,CAAA;IAEhC,IAAI,MAAM,CAAA;IACV,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CACzB,MAAM,EACN,EAAE,QAAQ,EAAE,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,CAC5D,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAA;IACH,CAAC;IAED,MAAM,eAAe,GAAG,MAAA,MAAM,CAAC,gBAAgB,mCAAI,MAAM,CAAA;IACzD,IAAI,QAAgB,CAAA;IACpB,IAAI,WAAW,GAAW,MAAA,MAAM,CAAC,iBAAiB,mCAAI,EAAE,CAAA;IAExD,yCAAyC;IACzC,IAAI,UAAU,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;QACzC,QAAQ,GAAG,eAAe,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,MAAM,CAAA;QACjB,WAAW;YACT,oEAAoE,CAAA;IACxE,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAA;AAClC,CAAC,CAAA;AA9CY,QAAA,wBAAwB,4BA8CpC"}
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.d.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { StructuredOutputParser } from 'langchain/output_parsers';
|
2
|
+
import { z } from 'zod';
|
3
|
+
/**
|
4
|
+
* Structured Output Parser
|
5
|
+
* Ensures LLM response follows the format:
|
6
|
+
* {
|
7
|
+
* matched_category: string // One of the provided categories or "None"
|
8
|
+
* match_explanation: string // Brief explanation of the categorization
|
9
|
+
* }
|
10
|
+
*/
|
11
|
+
export declare const parser: StructuredOutputParser<z.ZodObject<{
|
12
|
+
matched_category: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
13
|
+
match_explanation: z.ZodString;
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
15
|
+
matched_category: string;
|
16
|
+
match_explanation: string;
|
17
|
+
}, {
|
18
|
+
match_explanation: string;
|
19
|
+
matched_category?: string | undefined;
|
20
|
+
}>>;
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parser = void 0;
|
4
|
+
const output_parsers_1 = require("langchain/output_parsers");
|
5
|
+
const zod_1 = require("zod");
|
6
|
+
/**
|
7
|
+
* Structured Output Parser
|
8
|
+
* Ensures LLM response follows the format:
|
9
|
+
* {
|
10
|
+
* matched_category: string // One of the provided categories or "None"
|
11
|
+
* match_explanation: string // Brief explanation of the categorization
|
12
|
+
* }
|
13
|
+
*/
|
14
|
+
exports.parser = output_parsers_1.StructuredOutputParser.fromZodSchema(zod_1.z.object({
|
15
|
+
matched_category: zod_1.z.string().optional().default('None'),
|
16
|
+
match_explanation: zod_1.z.string(),
|
17
|
+
}));
|
18
|
+
//# sourceMappingURL=parser.js.map
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/parser.ts"],"names":[],"mappings":";;;AAAA,6DAAiE;AACjE,6BAAuB;AAEvB;;;;;;;GAOG;AACU,QAAA,MAAM,GAAG,uCAAsB,CAAC,aAAa,CACxD,OAAC,CAAC,MAAM,CAAC;IACP,gBAAgB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;IACvD,iBAAiB,EAAE,OAAC,CAAC,MAAM,EAAE;CAC9B,CAAC,CACH,CAAA"}
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ChatPromptTemplate } from '@langchain/core/prompts';
|
2
|
+
/**
|
3
|
+
* System Prompt Template
|
4
|
+
* Instructs the LLM to:
|
5
|
+
* 1. Choose a category from the provided list
|
6
|
+
* 2. Explain the choice
|
7
|
+
* 3. Return "None" if no category fits
|
8
|
+
*
|
9
|
+
* Variables:
|
10
|
+
* {categories} - Available categories, comma-separated
|
11
|
+
* {input} - Message to categorize
|
12
|
+
*/
|
13
|
+
export declare const systemPrompt: ChatPromptTemplate<import("@langchain/core/prompts").ParamsFromFString<"\n You are an expert in categorizing different patient messages in a clinical context.\n Use your expertise to solve the message categorization task:\n 1. Categorize the input message into **one of the provided categories**: {categories}. If no category fits, return \"None\".\n 2. Provide a concise explanation of why the message belongs to the selected category.\n \n Important Instructions:\n - The message may be in multiple languages.\n - **Only** choose from the provided list of categories. **Do not create new categories** or alter the given ones.\n - If no category fits perfectly, or if the match is unclear, return \"None\" without guessing.\n - Carefully verify your selection before submitting your answer.\n \n Respond exclusively with a valid JSON object containing the following keys:\n - matched_category: The most suitable category from: {categories}\n - match_explanation: A brief explanation supporting your decision.\n\n Input:\n {input}\n">, any>;
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.systemPrompt = void 0;
|
4
|
+
const prompts_1 = require("@langchain/core/prompts");
|
5
|
+
/**
|
6
|
+
* System Prompt Template
|
7
|
+
* Instructs the LLM to:
|
8
|
+
* 1. Choose a category from the provided list
|
9
|
+
* 2. Explain the choice
|
10
|
+
* 3. Return "None" if no category fits
|
11
|
+
*
|
12
|
+
* Variables:
|
13
|
+
* {categories} - Available categories, comma-separated
|
14
|
+
* {input} - Message to categorize
|
15
|
+
*/
|
16
|
+
exports.systemPrompt = prompts_1.ChatPromptTemplate.fromTemplate(`
|
17
|
+
You are an expert in categorizing different patient messages in a clinical context.
|
18
|
+
Use your expertise to solve the message categorization task:
|
19
|
+
1. Categorize the input message into **one of the provided categories**: {categories}. If no category fits, return "None".
|
20
|
+
2. Provide a concise explanation of why the message belongs to the selected category.
|
21
|
+
|
22
|
+
Important Instructions:
|
23
|
+
- The message may be in multiple languages.
|
24
|
+
- **Only** choose from the provided list of categories. **Do not create new categories** or alter the given ones.
|
25
|
+
- If no category fits perfectly, or if the match is unclear, return "None" without guessing.
|
26
|
+
- Carefully verify your selection before submitting your answer.
|
27
|
+
|
28
|
+
Respond exclusively with a valid JSON object containing the following keys:
|
29
|
+
- matched_category: The most suitable category from: {categories}
|
30
|
+
- match_explanation: A brief explanation supporting your decision.
|
31
|
+
|
32
|
+
Input:
|
33
|
+
{input}
|
34
|
+
`);
|
35
|
+
//# sourceMappingURL=prompt.js.map
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAE5D;;;;;;;;;;GAUG;AACU,QAAA,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;CAkB3D,CAAC,CAAA"}
|
@@ -1,4 +1,12 @@
|
|
1
1
|
import { type Action } from '@awell-health/extensions-core';
|
2
|
-
import { type settings } from '../../settings';
|
3
2
|
import { fields, dataPoints } from './config';
|
4
|
-
|
3
|
+
/**
|
4
|
+
* Awell Action: Message Generation
|
5
|
+
*
|
6
|
+
* Takes communication objective and personalization inputs, uses LLM to:
|
7
|
+
* 1. Generate a personalized message
|
8
|
+
* 2. Create appropriate subject line
|
9
|
+
*
|
10
|
+
* @returns subject and HTML-formatted message
|
11
|
+
*/
|
12
|
+
export declare const generateMessage: Action<typeof fields, Record<string, never>, keyof typeof dataPoints>;
|