@awell-health/awell-extensions 2.0.268 → 2.0.270
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js +2 -1
- package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/config/fields.d.ts +10 -0
- package/dist/extensions/shelly/actions/categorizeMessage/config/fields.js +8 -0
- package/dist/extensions/shelly/actions/categorizeMessage/config/fields.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.d.ts +3 -2
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js +7 -2
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js.map +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.d.ts +1 -1
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js +3 -0
- package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js.map +1 -1
- package/dist/extensions/shelly/actions/index.d.ts +7 -0
- package/package.json +1 -1
@@ -26,7 +26,7 @@ exports.categorizeMessage = {
|
|
26
26
|
dataPoints: config_1.dataPoints,
|
27
27
|
onEvent: async ({ payload, onComplete, onError, helpers }) => {
|
28
28
|
// 1. Validate input fields
|
29
|
-
const { message, categories } = config_1.FieldsValidationSchema.parse(payload.fields);
|
29
|
+
const { message, categories, instructions } = config_1.FieldsValidationSchema.parse(payload.fields);
|
30
30
|
// 2. Initialize OpenAI model with metadata
|
31
31
|
const { model, metadata, callbacks } = await (0, createOpenAIModel_1.createOpenAIModel)({
|
32
32
|
settings: {}, // we use built-in API key for OpenAI
|
@@ -39,6 +39,7 @@ exports.categorizeMessage = {
|
|
39
39
|
model,
|
40
40
|
message,
|
41
41
|
categories,
|
42
|
+
instructions,
|
42
43
|
metadata,
|
43
44
|
callbacks,
|
44
45
|
});
|
@@ -1 +1 @@
|
|
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,2BAA2B;IAClC,WAAW,EACT,mEAAmE;IACrE,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,
|
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,2BAA2B;IAClC,WAAW,EACT,mEAAmE;IACrE,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,YAAY,EAAE,GAAG,+BAAsB,CAAC,KAAK,CACxE,OAAO,CAAC,MAAM,CACf,CAAA;QAED,2CAA2C;QAC3C,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,IAAA,qCAAiB,EAAC;YAC7D,QAAQ,EAAE,EAAE,EAAE,qCAAqC;YACnD,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,YAAY;YACZ,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"}
|
@@ -15,14 +15,24 @@ export declare const fields: {
|
|
15
15
|
type: FieldType.STRING;
|
16
16
|
required: true;
|
17
17
|
};
|
18
|
+
instructions: {
|
19
|
+
id: string;
|
20
|
+
label: string;
|
21
|
+
description: string;
|
22
|
+
type: FieldType.TEXT;
|
23
|
+
required: false;
|
24
|
+
};
|
18
25
|
};
|
19
26
|
export declare const FieldsValidationSchema: z.ZodObject<{
|
20
27
|
message: z.ZodString;
|
21
28
|
categories: z.ZodEffects<z.ZodEffects<z.ZodString, string[], string>, string[], string>;
|
29
|
+
instructions: z.ZodOptional<z.ZodString>;
|
22
30
|
}, "strip", z.ZodTypeAny, {
|
23
31
|
message: string;
|
24
32
|
categories: string[];
|
33
|
+
instructions?: string | undefined;
|
25
34
|
}, {
|
26
35
|
message: string;
|
27
36
|
categories: string;
|
37
|
+
instructions?: string | undefined;
|
28
38
|
}>;
|
@@ -21,6 +21,13 @@ exports.fields = {
|
|
21
21
|
type: extensions_core_1.FieldType.STRING,
|
22
22
|
required: true,
|
23
23
|
},
|
24
|
+
instructions: {
|
25
|
+
id: 'instructions',
|
26
|
+
label: 'Instructions',
|
27
|
+
description: 'Add additional instructions prompt for the LLM',
|
28
|
+
type: extensions_core_1.FieldType.TEXT,
|
29
|
+
required: false,
|
30
|
+
},
|
24
31
|
};
|
25
32
|
exports.FieldsValidationSchema = zod_1.default.object({
|
26
33
|
message: zod_1.default.string().min(1, 'Message is required'),
|
@@ -32,5 +39,6 @@ exports.FieldsValidationSchema = zod_1.default.object({
|
|
32
39
|
.refine((arr) => arr.length > 0, {
|
33
40
|
message: 'At least one category is required',
|
34
41
|
}),
|
42
|
+
instructions: zod_1.default.string().optional(),
|
35
43
|
});
|
36
44
|
//# sourceMappingURL=fields.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/categorizeMessage/config/fields.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAqE;AACrE,8CAAwC;AAC3B,QAAA,MAAM,GAAG;IACpB,OAAO,EAAE;QACP,EAAE,EAAE,SAAS;QACb,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,+BAA+B;QAC5C,IAAI,EAAE,2BAAS,CAAC,MAAM,EAAE,8DAA8D;QACtF,QAAQ,EAAE,IAAI;KACf;IACD,UAAU,EAAE;QACV,EAAE,EAAE,YAAY;QAChB,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,iDAAiD;QAC9D,IAAI,EAAE,2BAAS,CAAC,MAAM;QACtB,QAAQ,EAAE,IAAI;KACf;CAC8B,CAAA;AAEpB,QAAA,sBAAsB,GAAG,aAAC,CAAC,MAAM,CAAC;IAC7C,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC;IACjD,UAAU,EAAE,aAAC;SACV,MAAM,EAAE;SACR,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,EAAE,mCAAmC,CAAC;SAC3C,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;SACzD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,EAAE,mCAAmC;KAC7C,CAAC;
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/categorizeMessage/config/fields.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAqE;AACrE,8CAAwC;AAC3B,QAAA,MAAM,GAAG;IACpB,OAAO,EAAE;QACP,EAAE,EAAE,SAAS;QACb,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,+BAA+B;QAC5C,IAAI,EAAE,2BAAS,CAAC,MAAM,EAAE,8DAA8D;QACtF,QAAQ,EAAE,IAAI;KACf;IACD,UAAU,EAAE;QACV,EAAE,EAAE,YAAY;QAChB,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,iDAAiD;QAC9D,IAAI,EAAE,2BAAS,CAAC,MAAM;QACtB,QAAQ,EAAE,IAAI;KACf;IACD,YAAY,EAAE;QACZ,EAAE,EAAE,cAAc;QAClB,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,gDAAgD;QAC7D,IAAI,EAAE,2BAAS,CAAC,IAAI;QACpB,QAAQ,EAAE,KAAK;KAChB;CAC8B,CAAA;AAEpB,QAAA,sBAAsB,GAAG,aAAC,CAAC,MAAM,CAAC;IAC7C,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC;IACjD,UAAU,EAAE,aAAC;SACV,MAAM,EAAE;SACR,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,EAAE,mCAAmC,CAAC;SAC3C,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;SACzD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,EAAE,mCAAmC;KAC7C,CAAC;IACJ,YAAY,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACc,CAAC,CAAA"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { type ChatOpenAI } from '@langchain/openai';
|
2
2
|
import { type AIActionMetadata } from '../../../../../../src/lib/llm/openai/types';
|
3
|
-
import type { BaseCallbackHandler } from
|
3
|
+
import type { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
4
4
|
/**
|
5
5
|
* Uses LLM to categorize a message into predefined categories.
|
6
6
|
* The function follows these steps:
|
@@ -17,10 +17,11 @@ import type { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
17
17
|
* })
|
18
18
|
* // Returns: { category: "Scheduling", explanation: "..." }
|
19
19
|
*/
|
20
|
-
export declare const categorizeMessageWithLLM: ({ model, message, categories, metadata, callbacks, }: {
|
20
|
+
export declare const categorizeMessageWithLLM: ({ model, message, categories, instructions, metadata, callbacks, }: {
|
21
21
|
model: ChatOpenAI;
|
22
22
|
message: string;
|
23
23
|
categories: string[];
|
24
|
+
instructions?: string;
|
24
25
|
metadata: AIActionMetadata;
|
25
26
|
callbacks?: BaseCallbackHandler[];
|
26
27
|
}) => Promise<{
|
@@ -19,16 +19,21 @@ const prompt_1 = require("./prompt");
|
|
19
19
|
* })
|
20
20
|
* // Returns: { category: "Scheduling", explanation: "..." }
|
21
21
|
*/
|
22
|
-
const categorizeMessageWithLLM = async ({ model, message, categories, metadata, callbacks, }) => {
|
22
|
+
const categorizeMessageWithLLM = async ({ model, message, categories, instructions, metadata, callbacks, }) => {
|
23
23
|
var _a, _b;
|
24
24
|
const prompt = await prompt_1.systemPrompt.format({
|
25
25
|
categories: categories.concat('None').join(', '),
|
26
26
|
input: message,
|
27
|
+
instructions: instructions !== null && instructions !== void 0 ? instructions : 'No additional instructions have been provided',
|
27
28
|
});
|
28
29
|
const chain = model.pipe(parser_1.parser);
|
29
30
|
let result;
|
30
31
|
try {
|
31
|
-
result = await chain.invoke(prompt, {
|
32
|
+
result = await chain.invoke(prompt, {
|
33
|
+
metadata,
|
34
|
+
runName: 'ShellyCategorizeMessage',
|
35
|
+
callbacks,
|
36
|
+
});
|
32
37
|
}
|
33
38
|
catch (error) {
|
34
39
|
throw new Error('Failed to categorize the message due to an internal error.');
|
@@ -1 +1 @@
|
|
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,
|
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,YAAY,EACZ,QAAQ,EACR,SAAS,GAQV,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;QACd,YAAY,EACV,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,+CAA+C;KAClE,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,CAAC,MAAM,EAAE;YAClC,QAAQ;YACR,OAAO,EAAE,yBAAyB;YAClC,SAAS;SACV,CAAC,CAAA;IACJ,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;AAnDY,QAAA,wBAAwB,4BAmDpC"}
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.d.ts
CHANGED
@@ -10,4 +10,4 @@ import { ChatPromptTemplate } from '@langchain/core/prompts';
|
|
10
10
|
* {categories} - Available categories, comma-separated
|
11
11
|
* {input} - Message to categorize
|
12
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>;
|
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 Additional Instructions:\n {instructions}\n\n Input:\n {input}\n">, any>;
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js
CHANGED
@@ -29,6 +29,9 @@ exports.systemPrompt = prompts_1.ChatPromptTemplate.fromTemplate(`
|
|
29
29
|
- matched_category: The most suitable category from: {categories}
|
30
30
|
- match_explanation: A brief explanation supporting your decision.
|
31
31
|
|
32
|
+
Additional Instructions:
|
33
|
+
{instructions}
|
34
|
+
|
32
35
|
Input:
|
33
36
|
{input}
|
34
37
|
`);
|
package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/prompt.js.map
CHANGED
@@ -1 +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
|
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;;;;;;;;;;;;;;;;;;;;;CAqB3D,CAAC,CAAA"}
|
@@ -14,6 +14,13 @@ declare const actions: {
|
|
14
14
|
type: import("@awell-health/extensions-core").FieldType.STRING;
|
15
15
|
required: true;
|
16
16
|
};
|
17
|
+
instructions: {
|
18
|
+
id: string;
|
19
|
+
label: string;
|
20
|
+
description: string;
|
21
|
+
type: import("@awell-health/extensions-core").FieldType.TEXT;
|
22
|
+
required: false;
|
23
|
+
};
|
17
24
|
}, Record<string, never>, "category" | "explanation">;
|
18
25
|
generateMessage: import("@awell-health/extensions-core").Action<{
|
19
26
|
communicationObjective: {
|