@awell-health/awell-extensions 2.0.22 → 2.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) 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/medicationFromImage/medicationFromImage.js +37 -23
  20. package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.js.map +1 -1
  21. package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.test.js +123 -3
  22. package/dist/extensions/shelly/actions/medicationFromImage/medicationFromImage.test.js.map +1 -1
  23. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.d.ts +15 -5
  24. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.js +21 -6
  25. package/dist/extensions/shelly/actions/summarizeCareFlow/config/fields.js.map +1 -1
  26. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.d.ts +2 -0
  27. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js +37 -0
  28. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/constants.js.map +1 -0
  29. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.d.ts +1 -0
  30. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.js +6 -0
  31. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/index.js.map +1 -0
  32. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.d.ts +7 -0
  33. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js +22 -0
  34. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.js.map +1 -0
  35. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.d.ts +1 -0
  36. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.js +42 -0
  37. package/dist/extensions/shelly/actions/summarizeCareFlow/lib/summarizeCareFlowWithLLM/summarizeCareFlowWithLLM.test.js.map +1 -0
  38. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js +23 -10
  39. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.js.map +1 -1
  40. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.js +57 -26
  41. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlow.test.js.map +1 -1
  42. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.d.ts +1 -0
  43. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.js +58 -0
  44. package/dist/extensions/shelly/actions/summarizeCareFlow/summarizeCareFlowRealOpenAI.test.js.map +1 -0
  45. package/dist/extensions/shelly/actions/summarizeForm/config/fields.d.ts +15 -5
  46. package/dist/extensions/shelly/actions/summarizeForm/config/fields.js +21 -6
  47. package/dist/extensions/shelly/actions/summarizeForm/config/fields.js.map +1 -1
  48. package/dist/extensions/shelly/actions/summarizeForm/lib/getResponseText/getResponseText.js +2 -1
  49. package/dist/extensions/shelly/actions/summarizeForm/lib/getResponseText/getResponseText.js.map +1 -1
  50. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.d.ts +2 -0
  51. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.js +37 -0
  52. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/constants.js.map +1 -0
  53. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.d.ts +1 -0
  54. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.js +6 -0
  55. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/index.js.map +1 -0
  56. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.d.ts +7 -0
  57. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.js +22 -0
  58. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.js.map +1 -0
  59. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.d.ts +1 -0
  60. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.js +54 -0
  61. package/dist/extensions/shelly/actions/summarizeForm/lib/summarizeFormWithLLM/summarizeFormWithLLM.test.js.map +1 -0
  62. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js +25 -8
  63. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.js.map +1 -1
  64. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.test.js +69 -31
  65. package/dist/extensions/shelly/actions/summarizeForm/summarizeForm.test.js.map +1 -1
  66. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.d.ts +1 -0
  67. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.js +71 -0
  68. package/dist/extensions/shelly/actions/summarizeForm/summarizeFormRealOpenAI.test.js.map +1 -0
  69. package/dist/extensions/shelly/lib/api/index.d.ts +1 -0
  70. package/dist/extensions/shelly/lib/api/index.js +6 -0
  71. package/dist/extensions/shelly/lib/api/index.js.map +1 -0
  72. package/dist/extensions/shelly/lib/api/medicationExtractorApi.d.ts +19 -0
  73. package/dist/extensions/shelly/lib/api/medicationExtractorApi.js +60 -0
  74. package/dist/extensions/shelly/lib/api/medicationExtractorApi.js.map +1 -0
  75. package/dist/extensions/shelly/lib/constants.d.ts +1 -0
  76. package/dist/extensions/shelly/lib/constants.js +2 -1
  77. package/dist/extensions/shelly/lib/constants.js.map +1 -1
  78. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.d.ts +3 -2
  79. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js +20 -3
  80. package/dist/extensions/shelly/lib/validatePayloadAndCreateSdk.js.map +1 -1
  81. package/dist/extensions/shelly/types.d.ts +16 -0
  82. package/dist/extensions/shelly/types.js +3 -0
  83. package/dist/extensions/shelly/types.js.map +1 -0
  84. package/package.json +3 -1
  85. package/dist/extensions/shelly/actions/categorizeMessage/realTest.test.js.map +0 -1
  86. /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,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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":"categorizeMess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AA,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,EA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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,CAA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;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,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.medicationFromImage = void 0;
4
- // import { AwellSdk } from '@awell-health/awell-sdk'
5
4
  const extensions_core_1 = require("@awell-health/extensions-core");
6
5
  const lib_1 = require("../../lib");
7
6
  const config_1 = require("./config");
7
+ const api_1 = require("../../lib/api");
8
+ const medicationExtractorApi_1 = require("../../lib/api/medicationExtractorApi");
8
9
  exports.medicationFromImage = {
9
10
  key: 'medicationFromImage',
10
11
  category: extensions_core_1.Category.WORKFLOW,
@@ -14,32 +15,45 @@ exports.medicationFromImage = {
14
15
  previewable: false,
15
16
  dataPoints: config_1.dataPoints,
16
17
  onEvent: async ({ payload, onComplete, onError, helpers }) => {
17
- const { fields: { imageUrl }, } = await (0, lib_1.validatePayloadAndCreateSdk)({
18
+ const { fields: { imageUrl }, pathway: { id: pathwayId }, activity: { id: activityId }, } = await (0, lib_1.validatePayloadAndCreateSdk)({
18
19
  fieldsSchema: config_1.FieldsValidationSchema,
19
20
  payload,
20
21
  });
21
- console.log(imageUrl);
22
- // Call whatever API with the file URL and get back JSON (ideally in the following format)
23
- const data = await Promise.resolve({
24
- medications: [
25
- {
26
- product_rxcui: '809854',
27
- product_name: 'hydrochlorothiazide 12.5 MG / quinapril 10 MG Oral Tablet [Accuretic]',
28
- brand_name: 'Accuretic',
29
- dose_form_name: 'Oral Tablet',
30
- prescribable_name: 'Accuretic 10 MG / 12.5 MG Oral Tablet',
31
- extracted_medication_name: 'Accuretic',
32
- extracted_brand_name: 'Accuretic',
33
- extracted_dosage: '10 mg / 12.5 mg',
34
- extracted_ndcg: '0006-0711-31', // National Drug Code (optional)
22
+ try {
23
+ const medicationExtractorApi = new api_1.MedicationExtractorApi();
24
+ const data = await medicationExtractorApi.extractMedicationFromImage({
25
+ imageUrl,
26
+ context: { pathwayId, activityId },
27
+ });
28
+ await onComplete({
29
+ data_points: {
30
+ data: JSON.stringify({
31
+ medications: data.medications,
32
+ }),
35
33
  },
36
- ],
37
- });
38
- await onComplete({
39
- data_points: {
40
- data: JSON.stringify(data),
41
- },
42
- });
34
+ });
35
+ }
36
+ catch (error) {
37
+ if (error instanceof medicationExtractorApi_1.FetchError) {
38
+ await onError({
39
+ events: [
40
+ {
41
+ date: new Date().toISOString(),
42
+ text: {
43
+ en: `${error.statusCode} (${error.statusText}): ${error.responseBody}`,
44
+ },
45
+ error: {
46
+ category: 'SERVER_ERROR',
47
+ message: `${error.statusCode} (${error.statusText}): ${error.responseBody}`,
48
+ },
49
+ },
50
+ ],
51
+ });
52
+ return;
53
+ }
54
+ // Other errors are handled in extensions-server
55
+ throw error;
56
+ }
43
57
  },
44
58
  };
45
59
  //# sourceMappingURL=medicationFromImage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"medicationFromImage.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/medicationFromImage/medicationFromImage.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AACrD,mEAAqE;AACrE,mCAAuD;AAEvD,qCAAqE;AAExD,QAAA,mBAAmB,GAI5B;IACF,GAAG,EAAE,qBAAqB;IAC1B,QAAQ,EAAE,0BAAQ,CAAC,QAAQ;IAC3B,KAAK,EAAE,+BAA+B;IACtC,WAAW,EAAE,oDAAoD;IACjE,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,MAAM,EAAE,EAAE,QAAQ,EAAE,GACrB,GAAG,MAAM,IAAA,iCAA2B,EAAC;YACpC,YAAY,EAAE,+BAAsB;YACpC,OAAO;SACR,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAErB,0FAA0F;QAC1F,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC;YACjC,WAAW,EAAE;gBACX;oBACE,aAAa,EAAE,QAAQ;oBACvB,YAAY,EACV,uEAAuE;oBACzE,UAAU,EAAE,WAAW;oBACvB,cAAc,EAAE,aAAa;oBAC7B,iBAAiB,EAAE,uCAAuC;oBAC1D,yBAAyB,EAAE,WAAW;oBACtC,oBAAoB,EAAE,WAAW;oBACjC,gBAAgB,EAAE,iBAAiB;oBACnC,cAAc,EAAE,cAAc,EAAE,gCAAgC;iBACjE;aACF;SACF,CAAC,CAAA;QAEF,MAAM,UAAU,CAAC;YACf,WAAW,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;aAC3B;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
1
+ {"version":3,"file":"medicationFromImage.js","sourceRoot":"","sources":["../../../../../extensions/shelly/actions/medicationFromImage/medicationFromImage.ts"],"names":[],"mappings":";;;AAAA,mEAAqE;AACrE,mCAAuD;AAEvD,qCAAqE;AACrE,uCAAsD;AACtD,iFAAiE;AAEpD,QAAA,mBAAmB,GAI5B;IACF,GAAG,EAAE,qBAAqB;IAC1B,QAAQ,EAAE,0BAAQ,CAAC,QAAQ;IAC3B,KAAK,EAAE,+BAA+B;IACtC,WAAW,EAAE,oDAAoD;IACjE,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,MAAM,EAAE,EAAE,QAAQ,EAAE,EACpB,OAAO,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAC1B,QAAQ,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,GAC7B,GAAG,MAAM,IAAA,iCAA2B,EAAC;YACpC,YAAY,EAAE,+BAAsB;YACpC,OAAO;SACR,CAAC,CAAA;QAEF,IAAI;YACF,MAAM,sBAAsB,GAAG,IAAI,4BAAsB,EAAE,CAAA;YAE3D,MAAM,IAAI,GAAG,MAAM,sBAAsB,CAAC,0BAA0B,CAAC;gBACnE,QAAQ;gBACR,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE;aACnC,CAAC,CAAA;YAEF,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,IAAI,EAAE,IAAI,CAAC,SAAS,C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