@awell-health/awell-extensions 2.0.22 → 2.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/dist/extensions/shelly/actions/categorizeMessage/{realTest.test.js → callingRealOpenAITest.test.js} +5 -3
  2. package/dist/extensions/shelly/actions/categorizeMessage/callingRealOpenAITest.test.js.map +1 -0
  3. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js +8 -4
  4. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.js.map +1 -1
  5. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.test.js +21 -17
  6. package/dist/extensions/shelly/actions/categorizeMessage/categorizeMessage.test.js.map +1 -1
  7. package/dist/extensions/shelly/actions/categorizeMessage/config/datapoints.d.ts +4 -0
  8. package/dist/extensions/shelly/actions/categorizeMessage/config/datapoints.js +4 -0
  9. package/dist/extensions/shelly/actions/categorizeMessage/config/datapoints.js.map +1 -1
  10. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.d.ts +7 -4
  11. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js +27 -9
  12. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.js.map +1 -1
  13. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.test.js +19 -17
  14. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.test.js.map +1 -1
  15. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.d.ts +13 -7
  16. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js +15 -5
  17. package/dist/extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.js.map +1 -1
  18. package/dist/extensions/shelly/actions/index.d.ts +19 -5
  19. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.d.ts +15 -5
  20. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.js +21 -6
  21. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.js.map +1 -1
  22. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.d.ts +2 -0
  23. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js +37 -0
  24. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js.map +1 -0
  25. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.d.ts +1 -0
  26. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.js +6 -0
  27. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.js.map +1 -0
  28. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.d.ts +7 -0
  29. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js +22 -0
  30. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js.map +1 -0
  31. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.d.ts +1 -0
  32. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.js +42 -0
  33. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.js.map +1 -0
  34. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js +23 -10
  35. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js.map +1 -1
  36. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.js +57 -26
  37. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.js.map +1 -1
  38. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.d.ts +1 -0
  39. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.js +58 -0
  40. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.js.map +1 -0
  41. package/dist/extensions/shelly/actions/summarizeForm/config/fields.d.ts +15 -5
  42. package/dist/extensions/shelly/actions/summarizeForm/config/fields.js +21 -6
  43. package/dist/extensions/shelly/actions/summarizeForm/config/fields.js.map +1 -1
  44. package/dist/extensions/shelly/actions/summarizeForm/lib/getResponseText/getResponseText.js +2 -1
  45. package/dist/extensions/shelly/actions/summarizeForm/lib/getResponseText/getResponseText.js.map +1 -1
  46. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.d.ts +2 -0
  47. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.js +37 -0
  48. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.js.map +1 -0
  49. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.d.ts +1 -0
  50. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.js +6 -0
  51. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.js.map +1 -0
  52. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.d.ts +7 -0
  53. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.js +22 -0
  54. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.js.map +1 -0
  55. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.d.ts +1 -0
  56. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.js +54 -0
  57. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.js.map +1 -0
  58. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js +25 -8
  59. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js.map +1 -1
  60. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.test.js +69 -31
  61. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.test.js.map +1 -1
  62. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.d.ts +1 -0
  63. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.js +71 -0
  64. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.js.map +1 -0
  65. package/dist/extensions/shelly/lib/constants.d.ts +1 -0
  66. package/dist/extensions/shelly/lib/constants.js +2 -1
  67. package/dist/extensions/shelly/lib/constants.js.map +1 -1
  68. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.d.ts +3 -2
  69. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js +20 -3
  70. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js.map +1 -1
  71. package/package.json +1 -1
  72. package/dist/extensions/shelly/actions/categorizeMessage/realTest.test.js.map +0 -1
  73. /package/dist/extensions/shelly/actions/categorizeMessage/{realTest.test.d.ts → callingRealOpenAITest.test.d.ts} +0 -0
@@ -31,7 +31,8 @@ describe.skip('categorizeMessage - Real LLM calls', () => {
31
31
  // Real LangChain function is called
32
32
  expect(onComplete).toHaveBeenCalledWith({
33
33
  data_points: {
34
- category: 'Appointment Scheduling', // Expected category from real LLM
34
+ category: 'Appointment Scheduling',
35
+ explanation: 'The message explicitly states a desire to schedule an appointment, which directly aligns with the Appointment Scheduling category.',
35
36
  },
36
37
  });
37
38
  expect(onError).not.toHaveBeenCalled();
@@ -53,10 +54,11 @@ describe.skip('categorizeMessage - Real LLM calls', () => {
53
54
  // Real LangChain function is called and returns "None"
54
55
  expect(onComplete).toHaveBeenCalledWith({
55
56
  data_points: {
56
- category: 'None', // Expected no match
57
+ category: 'None',
58
+ explanation: 'Categorization was ambiguous; we could not find a proper category.',
57
59
  },
58
60
  });
59
61
  expect(onError).not.toHaveBeenCalled();
60
62
  });
61
63
  });
62
- //# sourceMappingURL=realTest.test.js.map
64
+ //# sourceMappingURL=callingRealOpenAITest.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callingRealOpenAITest.test.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/categorizeMessage/callingRealOpenAITest.test.ts"],"names":[],"mappings":";;AAAA,mEAA2D;AAC3D,mCAA6C;AAC7C,wBAAqC;AACrC,yBAAsB;AAEtB,MAAM,QAAQ,GAAG;IACf,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;CAC1C,CAAA;AAED,8BAA8B;AAC9B,QAAQ,CAAC,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;IACvD,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GACjE,6BAAW,CAAC,UAAU,CAAC,oBAAiB,CAAC,CAAA;IAE3C,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,EAAE,CAAA,CAAC,+BAA+B;QAC5C,IAAI,CAAC,aAAa,EAAE,CAAA,CAAC,2BAA2B;IAClD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yFAAyF,EAAE,KAAK,IAAI,EAAE;QACvG,MAAM,OAAO,GAAG,IAAA,2BAAmB,EAAC;YAClC,MAAM,EAAE;gBACN,OAAO,EAAE,wDAAwD;gBACjE,UAAU,EACR,8FAA8F;aACjG;YACD,QAAQ;SACT,CAAC,CAAA;QAEF,MAAM,eAAe,CAAC,OAAO,CAAC;YAC5B,OAAO;YACP,UAAU;YACV,OAAO;YACP,OAAO;SACR,CAAC,CAAA;QAEF,oCAAoC;QACpC,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;YACtC,WAAW,EAAE;gBACX,QAAQ,EAAE,wBAAwB;gBAClC,WAAW,EACT,oIAAoI;aACvI;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;IACxC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kFAAkF,EAAE,KAAK,IAAI,EAAE;QAChG,MAAM,OAAO,GAAG,IAAA,2BAAmB,EAAC;YAClC,MAAM,EAAE;gBACN,OAAO,EAAE,iCAAiC;gBAC1C,UAAU,EACR,8FAA8F;aACjG;YACD,QAAQ;SACT,CAAC,CAAA;QAEF,MAAM,eAAe,CAAC,OAAO,CAAC;YAC5B,OAAO;YACP,UAAU;YACV,OAAO;YACP,OAAO;SACR,CAAC,CAAA;QAEF,uDAAuD;QACvD,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;YACtC,WAAW,EAAE;gBACX,QAAQ,EAAE,MAAM;gBAChB,WAAW,EACT,oEAAoE;aACvE;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -9,24 +9,28 @@ exports.categorizeMessage = {
9
9
  key: 'categorizeMessage',
10
10
  category: extensions_core_1.Category.WORKFLOW,
11
11
  title: 'Categorize Message',
12
- description: 'Categorize the input message into set of predefined categories',
12
+ description: 'Categorize the input message into set of predefined categories and provides explanation.',
13
13
  fields: config_1.fields,
14
14
  previewable: false,
15
15
  dataPoints: config_1.dataPoints,
16
16
  onEvent: async ({ payload, onComplete, onError, helpers }) => {
17
- const { langChainOpenAiSdk, fields: { categories, message }, } = await (0, lib_1.validatePayloadAndCreateSdk)({
17
+ const { ChatModelGPT4oMini, fields: { categories, message }, } = await (0, lib_1.validatePayloadAndCreateSdk)({
18
18
  fieldsSchema: config_1.FieldsValidationSchema,
19
19
  payload,
20
20
  });
21
21
  try {
22
- const category = await (0, categorizeMessageWithLLM_1.categorizeMessageWithLLM)({
23
- langChainOpenAiSdk,
22
+ const categorization_result = await (0, categorizeMessageWithLLM_1.categorizeMessageWithLLM)({
23
+ ChatModelGPT4oMini,
24
24
  message,
25
25
  categories,
26
26
  });
27
+ console.log(categorization_result);
28
+ const category = categorization_result.category;
29
+ const explanation = categorization_result.explanation;
27
30
  await onComplete({
28
31
  data_points: {
29
32
  category,
33
+ explanation,
30
34
  },
31
35
  });
32
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"categorizeMessage.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/categorizeMessage/categorizeMessage.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,6EAAyE;AACzE,mCAAuD;AAEvD,qCAAqE;AAExD,QAAA,iBAAiB,GAI1B;IACF,GAAG,EAAE,mBAAmB;IACxB,QAAQ,EAAE,0BAAQ,CAAC,QAAQ;IAC3B,KAAK,EAAE,oBAAoB;IAC3B,WAAW,EAAE,gEAAgE;IAC7E,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,MAAM,EACJ,kBAAkB,EAClB,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,GAChC,GAAG,MAAM,IAAA,iCAA2B,EAAC;YACpC,YAAY,EAAE,+BAAsB;YACpC,OAAO;SACR,CAAC,CAAA;QAEF,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,IAAA,mDAAwB,EAAC;gBAC9C,kBAAkB;gBAClB,OAAO;gBACP,UAAU;aACX,CAAC,CAAA;YAEF,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,QAAQ;iBACT;aACF,CAAC,CAAA;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAA;YACnD,4BAA4B;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC9C;IACH,CAAC;CACF,CAAA"}
1
+ {"version":3,"file":"categorizeMessage.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/categorizeMessage/categorizeMessage.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,6EAAyE;AACzE,mCAAuD;AAEvD,qCAAqE;AAExD,QAAA,iBAAiB,GAI1B;IACF,GAAG,EAAE,mBAAmB;IACxB,QAAQ,EAAE,0BAAQ,CAAC,QAAQ;IAC3B,KAAK,EAAE,oBAAoB;IAC3B,WAAW,EACT,0FAA0F;IAC5F,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,MAAM,EACJ,kBAAkB,EAClB,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,GAChC,GAAG,MAAM,IAAA,iCAA2B,EAAC;YACpC,YAAY,EAAE,+BAAsB;YACpC,OAAO;SACR,CAAC,CAAA;QAEF,IAAI;YACF,MAAM,qBAAqB,GAAG,MAAM,IAAA,mDAAwB,EAAC;gBAC3D,kBAAkB;gBAClB,OAAO;gBACP,UAAU;aACX,CAAC,CAAA;YAEF,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;YAClC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAA;YAC/C,MAAM,WAAW,GAAG,qBAAqB,CAAC,WAAW,CAAA;YAErD,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,QAAQ;oBACR,WAAW;iBACZ;aACF,CAAC,CAAA;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAA;YACnD,4BAA4B;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC9C;IACH,CAAC;CACF,CAAA"}
@@ -4,15 +4,23 @@ const extensions_core_1 = require("@awell-health/extensions-core");
4
4
  const tests_1 = require("@/tests");
5
5
  const _1 = require(".");
6
6
  const openai_1 = require("@langchain/openai");
7
- jest.mock('@langchain/openai', () => ({
8
- OpenAI: jest.fn().mockImplementation(() => ({
9
- pipe: jest.fn().mockReturnThis(),
10
- invoke: jest.fn().mockResolvedValue({
11
- matched_entity: 'Appointment Scheduling',
12
- }),
13
- })),
14
- }));
15
- const mockedOpenAiSdk = jest.mocked(openai_1.OpenAI);
7
+ // Mock the module
8
+ jest.mock('@langchain/openai', () => {
9
+ const mockInvoke = jest.fn().mockResolvedValue({
10
+ matched_category: 'Appointment Scheduling',
11
+ match_explanation: 'The message contains a request for scheduling an appointment.',
12
+ });
13
+ const mockChain = {
14
+ invoke: mockInvoke,
15
+ };
16
+ const mockPipe = jest.fn().mockReturnValue(mockChain);
17
+ const mockChatOpenAI = jest.fn().mockImplementation(() => ({
18
+ pipe: mockPipe,
19
+ }));
20
+ return {
21
+ ChatOpenAI: mockChatOpenAI,
22
+ };
23
+ });
16
24
  describe('categorizeMessage - Mocked LLM calls', () => {
17
25
  const { onComplete, onError, helpers, extensionAction, clearMocks } = extensions_core_1.TestHelpers.fromAction(_1.categorizeMessage);
18
26
  beforeEach(() => {
@@ -20,11 +28,6 @@ describe('categorizeMessage - Mocked LLM calls', () => {
20
28
  jest.clearAllMocks();
21
29
  });
22
30
  it('should work', async () => {
23
- const mockedOpenAiInstance = new openai_1.OpenAI();
24
- jest.spyOn(mockedOpenAiInstance, 'invoke').mockResolvedValue({
25
- // @ts-expect-error fine, we have a parser
26
- matched_entity: 'Appointment Scheduling',
27
- });
28
31
  const categorizeMessageWithLLMSpy = jest.spyOn(require('./lib/categorizeMessageWithLLM'), 'categorizeMessageWithLLM');
29
32
  const payload = (0, tests_1.generateTestPayload)({
30
33
  fields: {
@@ -41,9 +44,9 @@ describe('categorizeMessage - Mocked LLM calls', () => {
41
44
  onError,
42
45
  helpers,
43
46
  });
44
- expect(mockedOpenAiSdk).toHaveBeenCalled();
47
+ expect(openai_1.ChatOpenAI).toHaveBeenCalled();
45
48
  expect(categorizeMessageWithLLMSpy).toHaveBeenCalledWith({
46
- langChainOpenAiSdk: expect.any(Object),
49
+ ChatModelGPT4oMini: expect.any(Object),
47
50
  message: 'I would like to schedule an appointment for next week.',
48
51
  categories: [
49
52
  'Appointment Scheduling',
@@ -54,7 +57,8 @@ describe('categorizeMessage - Mocked LLM calls', () => {
54
57
  });
55
58
  expect(onComplete).toHaveBeenCalledWith({
56
59
  data_points: {
57
- category: 'Appointment Scheduling', // Expected category
60
+ category: 'Appointment Scheduling',
61
+ explanation: 'The message contains a request for scheduling an appointment.',
58
62
  },
59
63
  });
60
64
  expect(onError).not.toHaveBeenCalled();
@@ -1 +1 @@
1
- {"version":3,"file":"categorizeMessage.test.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/categorizeMessage/categorizeMessage.test.ts"],"names":[],"mappings":";;AAAA,mEAA2D;AAC3D,mCAA6C;AAC7C,wBAAqC;AACrC,8CAA0C;AAE1C,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1C,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,cAAc,EAAE;QAChC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;YAClC,cAAc,EAAE,wBAAwB;SACzC,CAAC;KACH,CAAC,CAAC;CACJ,CAAC,CAAC,CAAA;AAEH,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,eAAM,CAAC,CAAA;AAE3C,QAAQ,CAAC,sCAAsC,EAAE,GAAG,EAAE;IACpD,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GACjE,6BAAW,CAAC,UAAU,CAAC,oBAAiB,CAAC,CAAA;IAE3C,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,EAAE,CAAA;QACZ,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC3B,MAAM,oBAAoB,GAAG,IAAI,eAAM,EAAE,CAAA;QAEzC,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC,iBAAiB,CAAC;YAC3D,0CAA0C;YAC1C,cAAc,EAAE,wBAAwB;SACzC,CAAC,CAAA;QAEF,MAAM,2BAA2B,GAAG,IAAI,CAAC,KAAK,CAC5C,OAAO,CAAC,gCAAgC,CAAC,EACzC,0BAA0B,CAC3B,CAAA;QAED,MAAM,OAAO,GAAG,IAAA,2BAAmB,EAAC;YAClC,MAAM,EAAE;gBACN,OAAO,EAAE,wDAAwD;gBACjE,UAAU,EACR,8FAA8F;aACjG;YACD,QAAQ,EAAE;gBACR,YAAY,EAAE,GAAG;aAClB;SACF,CAAC,CAAA;QAEF,MAAM,eAAe,CAAC,OAAO,CAAC;YAC5B,OAAO;YACP,UAAU;YACV,OAAO;YACP,OAAO;SACR,CAAC,CAAA;QAEF,MAAM,CAAC,eAAe,CAAC,CAAC,gBAAgB,EAAE,CAAA;QAC1C,MAAM,CAAC,2BAA2B,CAAC,CAAC,oBAAoB,CAAC;YACvD,kBAAkB,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YACtC,OAAO,EAAE,wDAAwD;YACjE,UAAU,EAAE;gBACV,wBAAwB;gBACxB,sBAAsB;gBACtB,2BAA2B;gBAC3B,wBAAwB;aACzB;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;YACtC,WAAW,EAAE;gBACX,QAAQ,EAAE,wBAAwB,EAAE,oBAAoB;aACzD;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"categorizeMessage.test.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/categorizeMessage/categorizeMessage.test.ts"],"names":[],"mappings":";;AAAA,mEAA2D;AAC3D,mCAA6C;AAC7C,wBAAqC;AACrC,8CAA8C;AAE9C,kBAAkB;AAClB,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QAC7C,gBAAgB,EAAE,wBAAwB;QAC1C,iBAAiB,EACf,+DAA+D;KAClE,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG;QAChB,MAAM,EAAE,UAAU;KACnB,CAAA;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;IAErD,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAC;QACzD,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC,CAAA;IAEH,OAAO;QACL,UAAU,EAAE,cAAc;KAC3B,CAAA;AACH,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,sCAAsC,EAAE,GAAG,EAAE;IACpD,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GACjE,6BAAW,CAAC,UAAU,CAAC,oBAAiB,CAAC,CAAA;IAE3C,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,EAAE,CAAA;QACZ,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAC3B,MAAM,2BAA2B,GAAG,IAAI,CAAC,KAAK,CAC5C,OAAO,CAAC,gCAAgC,CAAC,EACzC,0BAA0B,CAC3B,CAAA;QAED,MAAM,OAAO,GAAG,IAAA,2BAAmB,EAAC;YAClC,MAAM,EAAE;gBACN,OAAO,EAAE,wDAAwD;gBACjE,UAAU,EACR,8FAA8F;aACjG;YACD,QAAQ,EAAE;gBACR,YAAY,EAAE,GAAG;aAClB;SACF,CAAC,CAAA;QAEF,MAAM,eAAe,CAAC,OAAO,CAAC;YAC5B,OAAO;YACP,UAAU;YACV,OAAO;YACP,OAAO;SACR,CAAC,CAAA;QAEF,MAAM,CAAC,mBAAU,CAAC,CAAC,gBAAgB,EAAE,CAAA;QACrC,MAAM,CAAC,2BAA2B,CAAC,CAAC,oBAAoB,CAAC;YACvD,kBAAkB,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YACtC,OAAO,EAAE,wDAAwD;YACjE,UAAU,EAAE;gBACV,wBAAwB;gBACxB,sBAAsB;gBACtB,2BAA2B;gBAC3B,wBAAwB;aACzB;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC;YACtC,WAAW,EAAE;gBACX,QAAQ,EAAE,wBAAwB;gBAClC,WAAW,EACT,+DAA+D;aAClE;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -3,4 +3,8 @@ export declare const dataPoints: {
3
3
  key: string;
4
4
  valueType: "string";
5
5
  };
6
+ explanation: {
7
+ key: string;
8
+ valueType: "string";
9
+ };
6
10
  };
@@ -6,5 +6,9 @@ exports.dataPoints = {
6
6
  key: 'category',
7
7
  valueType: 'string',
8
8
  },
9
+ explanation: {
10
+ key: 'explanation',
11
+ valueType: 'string',
12
+ },
9
13
  };
10
14
  //# sourceMappingURL=datapoints.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"datapoints.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/categorizeMessage/config/datapoints.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG;IACxB,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,SAAS,EAAE,QAAQ;KACpB;CAC4C,CAAA"}
1
+ {"version":3,"file":"datapoints.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/categorizeMessage/config/datapoints.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG;IACxB,QAAQ,EAAE;QACR,GAAG,EAAE,UAAU;QACf,SAAS,EAAE,QAAQ;KACpB;IACD,WAAW,EAAE;QACX,GAAG,EAAE,aAAa;QAClB,SAAS,EAAE,QAAQ;KACpB;CAC4C,CAAA"}
@@ -1,6 +1,9 @@
1
- import { type OpenAI } from '@langchain/openai';
2
- export declare const categorizeMessageWithLLM: ({ langChainOpenAiSdk, message, categories, }: {
3
- langChainOpenAiSdk: OpenAI;
1
+ import { type ChatOpenAI } from '@langchain/openai';
2
+ export declare const categorizeMessageWithLLM: ({ ChatModelGPT4oMini, message, categories, }: {
3
+ ChatModelGPT4oMini: ChatOpenAI;
4
4
  message: string;
5
5
  categories: string[];
6
- }) => Promise<string>;
6
+ }) => Promise<{
7
+ category: string;
8
+ explanation: string;
9
+ }>;
@@ -2,21 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.categorizeMessageWithLLM = void 0;
4
4
  const constants_1 = require("./constants");
5
- const categorizeMessageWithLLM = async ({ langChainOpenAiSdk, message, categories, }) => {
6
- var _a;
5
+ // TODO: remove console logs eventually
6
+ const categorizeMessageWithLLM = async ({ ChatModelGPT4oMini, message, categories, }) => {
7
+ var _a, _b;
7
8
  const prompt = await constants_1.systemPrompt.format({
8
9
  categories: categories.concat('None').join(', '),
9
10
  input: message,
10
11
  });
11
- const chain = langChainOpenAiSdk.pipe(constants_1.parser);
12
+ const chain = ChatModelGPT4oMini.pipe(constants_1.parser);
12
13
  console.log('Prompt:', prompt);
13
- const result = await chain.invoke(prompt);
14
+ let result;
15
+ try {
16
+ result = await chain.invoke(prompt);
17
+ }
18
+ catch (error) {
19
+ console.error('Error invoking the chain:', error);
20
+ throw new Error('Failed to categorize the message due to an internal error.');
21
+ }
14
22
  console.log('Result', typeof result);
15
- const matchedEntity = (_a = result.matched_entity) !== null && _a !== void 0 ? _a : 'None';
16
- console.log('I am matching:', matchedEntity);
17
- // Ensure that the returned matched entity is valid
18
- const category = categories.includes(matchedEntity) ? matchedEntity : 'None';
19
- return category;
23
+ const matchedCategory = (_a = result.matched_category) !== null && _a !== void 0 ? _a : 'None';
24
+ let category;
25
+ let explanation = (_b = result.match_explanation) !== null && _b !== void 0 ? _b : '';
26
+ console.log('Matched Category:', matchedCategory);
27
+ console.log('Explanation:', explanation);
28
+ // Check if the matched category is valid
29
+ if (categories.includes(matchedCategory)) {
30
+ category = matchedCategory;
31
+ }
32
+ else {
33
+ category = 'None';
34
+ explanation =
35
+ 'Categorization was ambiguous; we could not find a proper category.';
36
+ }
37
+ return { category, explanation };
20
38
  };
21
39
  exports.categorizeMessageWithLLM = categorizeMessageWithLLM;
22
40
  //# sourceMappingURL=categorizeMessageWithLLM.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"categorizeMessageWithLLM.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAG3C,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,kBAAkB,EAClB,OAAO,EACP,UAAU,GAKX,EAAmB,EAAE;;IACpB,MAAM,MAAM,GAAG,MAAM,wBAAY,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,kBAAkB,CAAC,IAAI,CAAC,kBAAM,CAAC,CAAA;IAC7C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC9B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAEzC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,MAAM,CAAC,CAAA;IAEpC,MAAM,aAAa,GAAG,MAAA,MAAM,CAAC,cAAc,mCAAI,MAAM,CAAA;IACrD,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA;IAE5C,mDAAmD;IACnD,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAA;IAE5E,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AA3BY,QAAA,wBAAwB,4BA2BpC"}
1
+ {"version":3,"file":"categorizeMessageWithLLM.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAGlD,uCAAuC;AAChC,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC7C,kBAAkB,EAClB,OAAO,EACP,UAAU,GAKX,EAAsD,EAAE;;IACvD,MAAM,MAAM,GAAG,MAAM,wBAAY,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,kBAAkB,CAAC,IAAI,CAAC,kBAAM,CAAC,CAAA;IAC7C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC9B,IAAI,MAAM,CAAA;IACV,IAAI;QACF,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;KACpC;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;QACjD,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAA;KACF;IAED,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,MAAM,CAAC,CAAA;IAEpC,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,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAA;IACjD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;IACxC,yCAAyC;IACzC,IAAI,UAAU,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;QACxC,QAAQ,GAAG,eAAe,CAAA;KAC3B;SAAM;QACL,QAAQ,GAAG,MAAM,CAAA;QACjB,WAAW;YACT,oEAAoE,CAAA;KACvE;IAED,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAA;AAClC,CAAC,CAAA;AA5CY,QAAA,wBAAwB,4BA4CpC"}
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("dotenv/config");
4
4
  const _1 = require("./");
5
5
  describe('categorizeMessageWithLLM', () => {
6
- let langChainOpenAiSdkMock;
6
+ let ChatModelGPT4oMiniMock;
7
7
  beforeEach(() => {
8
- // Create a mock for langChainOpenAiSdk
9
- langChainOpenAiSdkMock = {
8
+ ChatModelGPT4oMiniMock = {
10
9
  pipe: jest.fn().mockReturnThis(),
11
- invoke: jest.fn(), // Will mock this separately for each test
10
+ invoke: jest.fn(),
12
11
  };
13
12
  });
14
13
  it('should categorize a message about scheduling an appointment using real LLM', async () => {
15
- langChainOpenAiSdkMock.invoke.mockResolvedValue({
14
+ ChatModelGPT4oMiniMock.invoke.mockResolvedValue({
16
15
  // @ts-expect-error it's fine, we have a parser
17
- matched_entity: 'Appointment Scheduling',
16
+ matched_category: 'Appointment Scheduling',
17
+ match_explanation: 'The message contains a request for scheduling an appointment.',
18
18
  });
19
19
  const categories = [
20
20
  'Appointment Scheduling',
@@ -24,16 +24,17 @@ describe('categorizeMessageWithLLM', () => {
24
24
  ];
25
25
  const message = 'I would like to schedule an appointment for next week.';
26
26
  const result = await (0, _1.categorizeMessageWithLLM)({
27
- langChainOpenAiSdk: langChainOpenAiSdkMock,
27
+ ChatModelGPT4oMini: ChatModelGPT4oMiniMock,
28
28
  message,
29
29
  categories,
30
30
  });
31
- expect(result).toBe('Appointment Scheduling'); // Expected category
31
+ expect(result.category).toBe('Appointment Scheduling');
32
32
  });
33
33
  it('should categorize a message about medication using real LLM', async () => {
34
- langChainOpenAiSdkMock.invoke.mockResolvedValue({
34
+ ChatModelGPT4oMiniMock.invoke.mockResolvedValue({
35
35
  // @ts-expect-error it's fine, we have a parser
36
- matched_entity: 'Medication Questions',
36
+ matched_category: 'Medication Questions',
37
+ match_explanation: 'The message contains a request for medication information.',
37
38
  });
38
39
  const categories = [
39
40
  'Appointment Scheduling',
@@ -43,16 +44,17 @@ describe('categorizeMessageWithLLM', () => {
43
44
  ];
44
45
  const message = 'Can you tell me the correct dosage for my medication?';
45
46
  const result = await (0, _1.categorizeMessageWithLLM)({
46
- langChainOpenAiSdk: langChainOpenAiSdkMock,
47
+ ChatModelGPT4oMini: ChatModelGPT4oMiniMock,
47
48
  message,
48
49
  categories,
49
50
  });
50
- expect(result).toBe('Medication Questions'); // Expected category
51
+ expect(result.category).toBe('Medication Questions');
51
52
  });
52
53
  it('should return "None" when the message does not match any category using real LLM', async () => {
53
- langChainOpenAiSdkMock.invoke.mockResolvedValue({
54
+ ChatModelGPT4oMiniMock.invoke.mockResolvedValue({
54
55
  // @ts-expect-error it's fine, we have a parser
55
- matched_entity: 'None',
56
+ matched_category: 'None',
57
+ match_explanation: 'The message does not contain any information about scheduling or medication.',
56
58
  });
57
59
  const categories = [
58
60
  'Appointment Scheduling',
@@ -60,13 +62,13 @@ describe('categorizeMessageWithLLM', () => {
60
62
  'Medication Questions',
61
63
  'Administrative Assistance',
62
64
  ];
63
- const message = 'Is it going to rain tomorrow?'; // Non-related medical category
65
+ const message = 'Is it going to rain tomorrow?';
64
66
  const result = await (0, _1.categorizeMessageWithLLM)({
65
- langChainOpenAiSdk: langChainOpenAiSdkMock,
67
+ ChatModelGPT4oMini: ChatModelGPT4oMiniMock,
66
68
  message,
67
69
  categories,
68
70
  });
69
- expect(result).toBe('None'); // No match expected
71
+ expect(result.category).toBe('None');
70
72
  });
71
73
  });
72
74
  //# sourceMappingURL=categorizeMessageWithLLM.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"categorizeMessageWithLLM.test.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.test.ts"],"names":[],"mappings":";;AAAA,yBAAsB;AACtB,yBAA6C;AAG7C,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,sBAA2C,CAAA;IAE/C,UAAU,CAAC,GAAG,EAAE;QACd,uCAAuC;QACvC,sBAAsB,GAAG;YACvB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,cAAc,EAAE;YAChC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,0CAA0C;SAC5B,CAAA;IACrC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;QAC1F,sBAAsB,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAC9C,+CAA+C;YAC/C,cAAc,EAAE,wBAAwB;SACzC,CAAC,CAAA;QAEF,MAAM,UAAU,GAAG;YACjB,wBAAwB;YACxB,0BAA0B;YAC1B,sBAAsB;YACtB,2BAA2B;SAC5B,CAAA;QACD,MAAM,OAAO,GAAG,wDAAwD,CAAA;QAExE,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAwB,EAAC;YAC5C,kBAAkB,EAAE,sBAAsB;YAC1C,OAAO;YACP,UAAU;SACX,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA,CAAC,oBAAoB;IACpE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,sBAAsB,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAC9C,+CAA+C;YAC/C,cAAc,EAAE,sBAAsB;SACvC,CAAC,CAAA;QAEF,MAAM,UAAU,GAAG;YACjB,wBAAwB;YACxB,0BAA0B;YAC1B,sBAAsB;YACtB,2BAA2B;SAC5B,CAAA;QACD,MAAM,OAAO,GAAG,uDAAuD,CAAA;QAEvE,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAwB,EAAC;YAC5C,kBAAkB,EAAE,sBAAsB;YAC1C,OAAO;YACP,UAAU;SACX,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA,CAAC,oBAAoB;IAClE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kFAAkF,EAAE,KAAK,IAAI,EAAE;QAChG,sBAAsB,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAC9C,+CAA+C;YAC/C,cAAc,EAAE,MAAM;SACvB,CAAC,CAAA;QAEF,MAAM,UAAU,GAAG;YACjB,wBAAwB;YACxB,0BAA0B;YAC1B,sBAAsB;YACtB,2BAA2B;SAC5B,CAAA;QACD,MAAM,OAAO,GAAG,+BAA+B,CAAA,CAAC,+BAA+B;QAE/E,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAwB,EAAC;YAC5C,kBAAkB,EAAE,sBAAsB;YAC1C,OAAO;YACP,UAAU;SACX,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,CAAC,oBAAoB;IAClD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"categorizeMessageWithLLM.test.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/categorizeMessageWithLLM.test.ts"],"names":[],"mappings":";;AAAA,yBAAsB;AACtB,yBAA6C;AAG7C,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,sBAA+C,CAAA;IAEnD,UAAU,CAAC,GAAG,EAAE;QACd,sBAAsB,GAAG;YACvB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,cAAc,EAAE;YAChC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;SACoB,CAAA;IACzC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;QAC1F,sBAAsB,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAC9C,+CAA+C;YAC/C,gBAAgB,EAAE,wBAAwB;YAC1C,iBAAiB,EACf,+DAA+D;SAClE,CAAC,CAAA;QAEF,MAAM,UAAU,GAAG;YACjB,wBAAwB;YACxB,0BAA0B;YAC1B,sBAAsB;YACtB,2BAA2B;SAC5B,CAAA;QACD,MAAM,OAAO,GAAG,wDAAwD,CAAA;QAExE,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAwB,EAAC;YAC5C,kBAAkB,EAAE,sBAAsB;YAC1C,OAAO;YACP,UAAU;SACX,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,sBAAsB,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAC9C,+CAA+C;YAC/C,gBAAgB,EAAE,sBAAsB;YACxC,iBAAiB,EACf,4DAA4D;SAC/D,CAAC,CAAA;QAEF,MAAM,UAAU,GAAG;YACjB,wBAAwB;YACxB,0BAA0B;YAC1B,sBAAsB;YACtB,2BAA2B;SAC5B,CAAA;QACD,MAAM,OAAO,GAAG,uDAAuD,CAAA;QAEvE,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAwB,EAAC;YAC5C,kBAAkB,EAAE,sBAAsB;YAC1C,OAAO;YACP,UAAU;SACX,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kFAAkF,EAAE,KAAK,IAAI,EAAE;QAChG,sBAAsB,CAAC,MAAM,CAAC,iBAAiB,CAAC;YAC9C,+CAA+C;YAC/C,gBAAgB,EAAE,MAAM;YACxB,iBAAiB,EACf,8EAA8E;SACjF,CAAC,CAAA;QAEF,MAAM,UAAU,GAAG;YACjB,wBAAwB;YACxB,0BAA0B;YAC1B,sBAAsB;YACtB,2BAA2B;SAC5B,CAAA;QACD,MAAM,OAAO,GAAG,+BAA+B,CAAA;QAE/C,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAwB,EAAC;YAC5C,kBAAkB,EAAE,sBAAsB;YAC1C,OAAO;YACP,UAAU;SACX,CAAC,CAAA;QAEF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -2,17 +2,23 @@ import { ChatPromptTemplate } from '@langchain/core/prompts';
2
2
  import { StructuredOutputParser } from 'langchain/output_parsers';
3
3
  import { z } from 'zod';
4
4
  export declare const messageCategoriesSchema: z.ZodObject<{
5
- matched_entity: z.ZodDefault<z.ZodOptional<z.ZodString>>;
5
+ matched_category: z.ZodDefault<z.ZodOptional<z.ZodString>>;
6
+ match_explanation: z.ZodString;
6
7
  }, "strip", z.ZodTypeAny, {
7
- matched_entity: string;
8
+ matched_category: string;
9
+ match_explanation: string;
8
10
  }, {
9
- matched_entity?: string | undefined;
11
+ match_explanation: string;
12
+ matched_category?: string | undefined;
10
13
  }>;
11
14
  export declare const parser: StructuredOutputParser<z.ZodObject<{
12
- matched_entity: z.ZodDefault<z.ZodOptional<z.ZodString>>;
15
+ matched_category: z.ZodDefault<z.ZodOptional<z.ZodString>>;
16
+ match_explanation: z.ZodString;
13
17
  }, "strip", z.ZodTypeAny, {
14
- matched_entity: string;
18
+ matched_category: string;
19
+ match_explanation: string;
15
20
  }, {
16
- matched_entity?: string | undefined;
21
+ match_explanation: string;
22
+ matched_category?: string | undefined;
17
23
  }>>;
18
- export declare const systemPrompt: ChatPromptTemplate<import("@langchain/core/prompts").ParamsFromFString<"\n You are an expert in categorizing messages. Your task is to match the provided message to one of the following categories: {categories}.\n If no match is found, return \"None.\"\n \n Please respond with a valid JSON object with the following key: matched_entity.\n \n \n Input:\n {input}\n ">, any>;
24
+ export declare const systemPrompt: ChatPromptTemplate<import("@langchain/core/prompts").ParamsFromFString<"\n You are an expert in categorizing messages different messages in a clinical context.\n Use your expertise to solve the critical task:\n 1. Match the provided message to one of the following categories: {categories}.\n 2. Provide a one-sentence explanation of why the message fits the chosen category.\n \n Instructions for categorization:\n - The message may be in different languages.\n - It is crucial that you only select a category from the provided list.\n - If no match is found, or if the match is ambiguous, return \"None\".\n It is critical to double-check your work before returning the final result.\n \n Respond exclusively with a valid JSON object containing the following keys:\n - matched_category: The selected category or \"None\".\n - match_explanation: A one-sentence explanation of the match. Make sure to provide clear and concise explanation to justify your decision.\n \n Input:\n {input}\n ">, any>;
@@ -6,17 +6,27 @@ const output_parsers_1 = require("langchain/output_parsers");
6
6
  const zod_1 = require("zod");
7
7
  // Define the Zod schema for the structured response
8
8
  exports.messageCategoriesSchema = zod_1.z.object({
9
- matched_entity: zod_1.z.string().optional().default('None'), // The matched category
9
+ matched_category: zod_1.z.string().optional().default('None'),
10
+ match_explanation: zod_1.z.string(), // One-sentence explanation of the match
10
11
  });
11
12
  // Create a structured output parser
12
13
  exports.parser = output_parsers_1.StructuredOutputParser.fromZodSchema(exports.messageCategoriesSchema);
13
- // Update the prompt to enforce a structured JSON response
14
+ // TODO: move prompt to LangSmith + further tune
14
15
  exports.systemPrompt = prompts_1.ChatPromptTemplate.fromTemplate(`
15
- You are an expert in categorizing messages. Your task is to match the provided message to one of the following categories: {categories}.
16
- If no match is found, return "None."
16
+ You are an expert in categorizing messages different messages in a clinical context.
17
+ Use your expertise to solve the critical task:
18
+ 1. Match the provided message to one of the following categories: {categories}.
19
+ 2. Provide a one-sentence explanation of why the message fits the chosen category.
17
20
 
18
- Please respond with a valid JSON object with the following key: matched_entity.
21
+ Instructions for categorization:
22
+ - The message may be in different languages.
23
+ - It is crucial that you only select a category from the provided list.
24
+ - If no match is found, or if the match is ambiguous, return "None".
25
+ It is critical to double-check your work before returning the final result.
19
26
 
27
+ Respond exclusively with a valid JSON object containing the following keys:
28
+ - matched_category: The selected category or "None".
29
+ - match_explanation: A one-sentence explanation of the match. Make sure to provide clear and concise explanation to justify your decision.
20
30
 
21
31
  Input:
22
32
  {input}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAC5D,6DAAiE;AACjE,6BAAuB;AAEvB,oDAAoD;AACvC,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,uBAAuB;CAC/E,CAAC,CAAA;AAEF,oCAAoC;AACvB,QAAA,MAAM,GAAG,uCAAsB,CAAC,aAAa,CACxD,+BAAuB,CACxB,CAAA;AAED,0DAA0D;AAC7C,QAAA,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;;;;;;;;;OASrD,CAAC,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/categorizeMessage/lib/categorizeMessageWithLLM/constants.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAC5D,6DAAiE;AACjE,6BAAuB;AAEvB,oDAAoD;AACvC,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,gBAAgB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;IACvD,iBAAiB,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,wCAAwC;CACxE,CAAC,CAAA;AAEF,oCAAoC;AACvB,QAAA,MAAM,GAAG,uCAAsB,CAAC,aAAa,CACxD,+BAAuB,CACxB,CAAA;AAED,gDAAgD;AACnC,QAAA,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;OAkBrD,CAAC,CAAA"}
@@ -1,10 +1,17 @@
1
1
  declare const actions: {
2
2
  summarizeForm: import("@awell-health/extensions-core").Action<{
3
- prompt: {
3
+ additionalInstructions: {
4
4
  id: string;
5
5
  label: string;
6
6
  description: string;
7
- type: import("@awell-health/extensions-core").FieldType.TEXT;
7
+ type: import("@awell-health/extensions-core").FieldType.STRING;
8
+ required: false;
9
+ };
10
+ stakeholder: {
11
+ id: string;
12
+ label: string;
13
+ description: string;
14
+ type: import("@awell-health/extensions-core").FieldType.STRING;
8
15
  required: false;
9
16
  };
10
17
  }, {
@@ -17,11 +24,18 @@ declare const actions: {
17
24
  };
18
25
  }, "summary">;
19
26
  summarizeCareFlow: import("@awell-health/extensions-core").Action<{
20
- prompt: {
27
+ additionalInstructions: {
21
28
  id: string;
22
29
  label: string;
23
30
  description: string;
24
- type: import("@awell-health/extensions-core").FieldType.TEXT;
31
+ type: import("@awell-health/extensions-core").FieldType.STRING;
32
+ required: false;
33
+ };
34
+ stakeholder: {
35
+ id: string;
36
+ label: string;
37
+ description: string;
38
+ type: import("@awell-health/extensions-core").FieldType.STRING;
25
39
  required: false;
26
40
  };
27
41
  }, {
@@ -56,7 +70,7 @@ declare const actions: {
56
70
  required: true;
57
71
  description: string;
58
72
  };
59
- }, "category">;
73
+ }, "category" | "explanation">;
60
74
  medicationFromImage: import("@awell-health/extensions-core").Action<{
61
75
  imageUrl: {
62
76
  id: string;
@@ -1,18 +1,28 @@
1
1
  import { FieldType } from '@awell-health/extensions-core';
2
2
  import z from 'zod';
3
3
  export declare const fields: {
4
- prompt: {
4
+ additionalInstructions: {
5
5
  id: string;
6
6
  label: string;
7
7
  description: string;
8
- type: FieldType.TEXT;
8
+ type: FieldType.STRING;
9
+ required: false;
10
+ };
11
+ stakeholder: {
12
+ id: string;
13
+ label: string;
14
+ description: string;
15
+ type: FieldType.STRING;
9
16
  required: false;
10
17
  };
11
18
  };
12
19
  export declare const FieldsValidationSchema: z.ZodObject<{
13
- prompt: z.ZodOptional<z.ZodString>;
20
+ additionalInstructions: z.ZodDefault<z.ZodOptional<z.ZodString>>;
21
+ stakeholder: z.ZodEffects<z.ZodOptional<z.ZodString>, string, string | undefined>;
14
22
  }, "strip", z.ZodTypeAny, {
15
- prompt?: string | undefined;
23
+ additionalInstructions: string;
24
+ stakeholder: string;
16
25
  }, {
17
- prompt?: string | undefined;
26
+ additionalInstructions?: string | undefined;
27
+ stakeholder?: string | undefined;
18
28
  }>;
@@ -7,15 +7,30 @@ exports.FieldsValidationSchema = exports.fields = void 0;
7
7
  const extensions_core_1 = require("@awell-health/extensions-core");
8
8
  const zod_1 = __importDefault(require("zod"));
9
9
  exports.fields = {
10
- prompt: {
11
- id: 'prompt',
12
- label: 'Prompt',
13
- description: 'Leave blank to use the default prompt',
14
- type: extensions_core_1.FieldType.TEXT,
10
+ additionalInstructions: {
11
+ id: 'additionalInstructions',
12
+ label: 'Additional instructions',
13
+ description: 'Specify additional instructions for summarization, for example format, length, what to focus on etc. If not specified, default instructions will be used.',
14
+ type: extensions_core_1.FieldType.STRING,
15
+ required: false,
16
+ },
17
+ stakeholder: {
18
+ id: 'stakeholder',
19
+ label: 'Stakeholder',
20
+ description: 'Defaults to "Clinician"',
21
+ type: extensions_core_1.FieldType.STRING,
15
22
  required: false,
16
23
  },
17
24
  };
18
25
  exports.FieldsValidationSchema = zod_1.default.object({
19
- prompt: zod_1.default.string().optional(),
26
+ additionalInstructions: zod_1.default.string().optional().default(''),
27
+ stakeholder: zod_1.default
28
+ .string()
29
+ .optional()
30
+ .transform((val) => {
31
+ if (val === undefined || val === '')
32
+ return 'Clinician';
33
+ return val;
34
+ }),
20
35
  });
21
36
  //# sourceMappingURL=fields.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/summarizeCareFlow/config/fields.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAqE;AACrE,8CAAwC;AAE3B,QAAA,MAAM,GAAG;IACpB,MAAM,EAAE;QACN,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,uCAAuC;QACpD,IAAI,EAAE,2BAAS,CAAC,IAAI;QACpB,QAAQ,EAAE,KAAK;KAChB;CAC8B,CAAA;AAEpB,QAAA,sBAAsB,GAAG,aAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACoB,CAAC,CAAA"}
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../../../extensions/shelly/actions/summarizeCareFlow/config/fields.ts"],"names":[],"mappings":";;;;;;AAAA,mEAAqE;AACrE,8CAAwC;AAE3B,QAAA,MAAM,GAAG;IACpB,sBAAsB,EAAE;QACtB,EAAE,EAAE,wBAAwB;QAC5B,KAAK,EAAE,yBAAyB;QAChC,WAAW,EACT,2JAA2J;QAC7J,IAAI,EAAE,2BAAS,CAAC,MAAM;QACtB,QAAQ,EAAE,KAAK;KAChB;IACD,WAAW,EAAE;QACX,EAAE,EAAE,aAAa;QACjB,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,yBAAyB;QACtC,IAAI,EAAE,2BAAS,CAAC,MAAM;QACtB,QAAQ,EAAE,KAAK;KAChB;CAC8B,CAAA;AAEpB,QAAA,sBAAsB,GAAG,aAAC,CAAC,MAAM,CAAC;IAC7C,sBAAsB,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IACzD,WAAW,EAAE,aAAC;SACX,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,SAAS,CAAC,CAAC,GAAG,EAAU,EAAE;QACzB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;YAAE,OAAO,WAAW,CAAA;QAEvD,OAAO,GAAG,CAAA;IACZ,CAAC,CAAC;CAC6C,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { ChatPromptTemplate } from '@langchain/core/prompts';
2
+ export declare const systemPrompt: ChatPromptTemplate<import("@langchain/core/prompts").ParamsFromFString<"\n You are an assistant that provides summaries of activities performed in a care flow for different stakeholders in a healthcare setting.\n A care flow consists of tracks, steps, and actions that can be performed by a patient, a clinician, or the system itself. These actions may include patient tasks (e.g., form submissions), clinician interventions (e.g., messages sent), or system-triggered activities (e.g., API calls).\n \n Your job is to provide a clear, human-readable summary of these activities in chronological order, ensuring the summary is tailored for the specific stakeholder. Focus on activity names and descriptions, avoiding any mention of IDs or technical details.\n \n Instructions for summarizing:\n - Summarize the care flow activities in the order they were performed, maintaining the chronological sequence.\n - Ensure the summary is concise, clear, and relevant to the stakeholder's needs.\n - Focus on activity names, titles, and the nature of the actions (e.g., patient submitted a form, clinician responded to a message).\n - Do not include any IDs, internal codes, or technical jargon—only human-readable information.\n - Tailor the summary to the specific stakeholder, emphasizing the information most relevant to their role.\n - Avoid making assumptions about actions not explicitly mentioned in the input.\n - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible. \n \n Format:\n - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible.\n - Format it as an easy-to-grasp timeline with all important values and information. \n - Always mention track, step, and action names if applicable unless otherwise specified in the additional instructions.\n - Never format it in markdown with bold, italic, etc., unless otherwise specified in the additional instructions.\n - Do not list usign words like next, finally, just list sumamries in bullet points, concisely.\n\n Additional Instructions:\n {additionalInstructions}\n\n Stakeholder:\n {stakeholder}\n\n Content to summarize:\n {input}\n ">, any>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.systemPrompt = void 0;
4
+ const prompts_1 = require("@langchain/core/prompts");
5
+ // TODO: move prompt to LangSmith + further tune
6
+ exports.systemPrompt = prompts_1.ChatPromptTemplate.fromTemplate(`
7
+ You are an assistant that provides summaries of activities performed in a care flow for different stakeholders in a healthcare setting.
8
+ A care flow consists of tracks, steps, and actions that can be performed by a patient, a clinician, or the system itself. These actions may include patient tasks (e.g., form submissions), clinician interventions (e.g., messages sent), or system-triggered activities (e.g., API calls).
9
+
10
+ Your job is to provide a clear, human-readable summary of these activities in chronological order, ensuring the summary is tailored for the specific stakeholder. Focus on activity names and descriptions, avoiding any mention of IDs or technical details.
11
+
12
+ Instructions for summarizing:
13
+ - Summarize the care flow activities in the order they were performed, maintaining the chronological sequence.
14
+ - Ensure the summary is concise, clear, and relevant to the stakeholder's needs.
15
+ - Focus on activity names, titles, and the nature of the actions (e.g., patient submitted a form, clinician responded to a message).
16
+ - Do not include any IDs, internal codes, or technical jargon—only human-readable information.
17
+ - Tailor the summary to the specific stakeholder, emphasizing the information most relevant to their role.
18
+ - Avoid making assumptions about actions not explicitly mentioned in the input.
19
+ - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible.
20
+
21
+ Format:
22
+ - Provide the summary as a set of bullet points unless otherwise specified in the instructions. Make it as concise as possible.
23
+ - Format it as an easy-to-grasp timeline with all important values and information.
24
+ - Always mention track, step, and action names if applicable unless otherwise specified in the additional instructions.
25
+ - Never format it in markdown with bold, italic, etc., unless otherwise specified in the additional instructions.
26
+ - Do not list usign words like next, finally, just list sumamries in bullet points, concisely.
27
+
28
+ Additional Instructions:
29
+ {additionalInstructions}
30
+
31
+ Stakeholder:
32
+ {stakeholder}
33
+
34
+ Content to summarize:
35
+ {input}
36
+ `);
37
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.ts"],"names":[],"mappings":";;;AAAA,qDAA4D;AAE5D,gDAAgD;AACnC,QAAA,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BzD,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export { summarizeCareFlowWithLLM } from './summarizeCareFlowWithLLM';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.summarizeCareFlowWithLLM = void 0;
4
+ var summarizeCareFlowWithLLM_1 = require("./summarizeCareFlowWithLLM");
5
+ Object.defineProperty(exports, "summarizeCareFlowWithLLM", { enumerable: true, get: function () { return summarizeCareFlowWithLLM_1.summarizeCareFlowWithLLM; } });
6
+ //# sourceMappingURL=index.js.map