@celljs/ai-core 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/cell.yml +0 -0
  4. package/lib/common/chat/index.d.ts +5 -0
  5. package/lib/common/chat/index.d.ts.map +1 -0
  6. package/lib/common/chat/index.js +21 -0
  7. package/lib/common/chat/index.js.map +1 -0
  8. package/lib/common/chat/message/abstract-message.d.ts +10 -0
  9. package/lib/common/chat/message/abstract-message.d.ts.map +1 -0
  10. package/lib/common/chat/message/abstract-message.js +15 -0
  11. package/lib/common/chat/message/abstract-message.js.map +1 -0
  12. package/lib/common/chat/message/assistant-message.d.ts +9 -0
  13. package/lib/common/chat/message/assistant-message.d.ts.map +1 -0
  14. package/lib/common/chat/message/assistant-message.js +15 -0
  15. package/lib/common/chat/message/assistant-message.js.map +1 -0
  16. package/lib/common/chat/message/function-message.d.ts +9 -0
  17. package/lib/common/chat/message/function-message.d.ts.map +1 -0
  18. package/lib/common/chat/message/function-message.js +15 -0
  19. package/lib/common/chat/message/function-message.js.map +1 -0
  20. package/lib/common/chat/message/index.d.ts +7 -0
  21. package/lib/common/chat/message/index.d.ts.map +1 -0
  22. package/lib/common/chat/message/index.js +23 -0
  23. package/lib/common/chat/message/index.js.map +1 -0
  24. package/lib/common/chat/message/message-protocol.d.ts +41 -0
  25. package/lib/common/chat/message/message-protocol.d.ts.map +1 -0
  26. package/lib/common/chat/message/message-protocol.js +22 -0
  27. package/lib/common/chat/message/message-protocol.js.map +1 -0
  28. package/lib/common/chat/message/system-message.d.ts +9 -0
  29. package/lib/common/chat/message/system-message.d.ts.map +1 -0
  30. package/lib/common/chat/message/system-message.js +15 -0
  31. package/lib/common/chat/message/system-message.js.map +1 -0
  32. package/lib/common/chat/message/user-message.d.ts +9 -0
  33. package/lib/common/chat/message/user-message.d.ts.map +1 -0
  34. package/lib/common/chat/message/user-message.js +15 -0
  35. package/lib/common/chat/message/user-message.js.map +1 -0
  36. package/lib/common/chat/metadata/index.d.ts +2 -0
  37. package/lib/common/chat/metadata/index.d.ts.map +1 -0
  38. package/lib/common/chat/metadata/index.js +18 -0
  39. package/lib/common/chat/metadata/index.js.map +1 -0
  40. package/lib/common/chat/metadata/metadata-protocol.d.ts +108 -0
  41. package/lib/common/chat/metadata/metadata-protocol.d.ts.map +1 -0
  42. package/lib/common/chat/metadata/metadata-protocol.js +41 -0
  43. package/lib/common/chat/metadata/metadata-protocol.js.map +1 -0
  44. package/lib/common/chat/model/chat-protocol.d.ts +15 -0
  45. package/lib/common/chat/model/chat-protocol.d.ts.map +1 -0
  46. package/lib/common/chat/model/chat-protocol.js +3 -0
  47. package/lib/common/chat/model/chat-protocol.js.map +1 -0
  48. package/lib/common/chat/model/index.d.ts +2 -0
  49. package/lib/common/chat/model/index.d.ts.map +1 -0
  50. package/lib/common/chat/model/index.js +18 -0
  51. package/lib/common/chat/model/index.js.map +1 -0
  52. package/lib/common/chat/prompt/index.d.ts +3 -0
  53. package/lib/common/chat/prompt/index.d.ts.map +1 -0
  54. package/lib/common/chat/prompt/index.js +19 -0
  55. package/lib/common/chat/prompt/index.js.map +1 -0
  56. package/lib/common/chat/prompt/prompt-protocol.d.ts +29 -0
  57. package/lib/common/chat/prompt/prompt-protocol.d.ts.map +1 -0
  58. package/lib/common/chat/prompt/prompt-protocol.js +3 -0
  59. package/lib/common/chat/prompt/prompt-protocol.js.map +1 -0
  60. package/lib/common/chat/prompt/prompt.d.ts +14 -0
  61. package/lib/common/chat/prompt/prompt.d.ts.map +1 -0
  62. package/lib/common/chat/prompt/prompt.js +56 -0
  63. package/lib/common/chat/prompt/prompt.js.map +1 -0
  64. package/lib/common/index.d.ts +4 -0
  65. package/lib/common/index.d.ts.map +1 -0
  66. package/lib/common/index.js +20 -0
  67. package/lib/common/index.js.map +1 -0
  68. package/lib/common/model/function/function-protocol.d.ts +47 -0
  69. package/lib/common/model/function/function-protocol.d.ts.map +1 -0
  70. package/lib/common/model/function/function-protocol.js +3 -0
  71. package/lib/common/model/function/function-protocol.js.map +1 -0
  72. package/lib/common/model/function/index.d.ts +2 -0
  73. package/lib/common/model/function/index.d.ts.map +1 -0
  74. package/lib/common/model/function/index.js +18 -0
  75. package/lib/common/model/function/index.js.map +1 -0
  76. package/lib/common/model/index.d.ts +2 -0
  77. package/lib/common/model/index.d.ts.map +1 -0
  78. package/lib/common/model/index.js +18 -0
  79. package/lib/common/model/index.js.map +1 -0
  80. package/lib/common/model/model-protocol.d.ts +160 -0
  81. package/lib/common/model/model-protocol.d.ts.map +1 -0
  82. package/lib/common/model/model-protocol.js +12 -0
  83. package/lib/common/model/model-protocol.js.map +1 -0
  84. package/lib/common/module.d.ts +4 -0
  85. package/lib/common/module.d.ts.map +1 -0
  86. package/lib/common/module.js +6 -0
  87. package/lib/common/module.js.map +1 -0
  88. package/lib/common/utils/index.d.ts +2 -0
  89. package/lib/common/utils/index.d.ts.map +1 -0
  90. package/lib/common/utils/index.js +18 -0
  91. package/lib/common/utils/index.js.map +1 -0
  92. package/lib/common/utils/prompt-util.d.ts +5 -0
  93. package/lib/common/utils/prompt-util.d.ts.map +1 -0
  94. package/lib/common/utils/prompt-util.js +11 -0
  95. package/lib/common/utils/prompt-util.js.map +1 -0
  96. package/lib/package.spec.d.ts +1 -0
  97. package/lib/package.spec.d.ts.map +1 -0
  98. package/lib/package.spec.js +4 -0
  99. package/lib/package.spec.js.map +1 -0
  100. package/package.json +43 -0
  101. package/src/common/chat/index.ts +4 -0
  102. package/src/common/chat/message/abstract-message.ts +13 -0
  103. package/src/common/chat/message/assistant-message.ts +12 -0
  104. package/src/common/chat/message/function-message.ts +12 -0
  105. package/src/common/chat/message/index.ts +6 -0
  106. package/src/common/chat/message/message-protocol.ts +49 -0
  107. package/src/common/chat/message/system-message.ts +12 -0
  108. package/src/common/chat/message/user-message.ts +12 -0
  109. package/src/common/chat/metadata/index.ts +1 -0
  110. package/src/common/chat/metadata/metadata-protocol.ts +154 -0
  111. package/src/common/chat/model/chat-protocol.ts +22 -0
  112. package/src/common/chat/model/index.ts +1 -0
  113. package/src/common/chat/prompt/index.ts +2 -0
  114. package/src/common/chat/prompt/prompt-protocol.ts +44 -0
  115. package/src/common/chat/prompt/prompt.ts +57 -0
  116. package/src/common/index.ts +3 -0
  117. package/src/common/model/function/function-protocol.ts +58 -0
  118. package/src/common/model/function/index.ts +1 -0
  119. package/src/common/model/index.ts +2 -0
  120. package/src/common/model/model-protocol.ts +184 -0
  121. package/src/common/module.ts +4 -0
  122. package/src/common/utils/index.ts +1 -0
  123. package/src/common/utils/prompt-util.ts +7 -0
  124. package/src/package.spec.ts +4 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./prompt-protocol"), exports);
18
+ __exportStar(require("./prompt"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,2CAAyB"}
@@ -0,0 +1,29 @@
1
+ import { ModelOptions, ModelRequest } from '../../model/model-protocol';
2
+ import { Media, Message } from '../message';
3
+ /**
4
+ * The ChatOptions represent the common options, portable across different chat models.
5
+ */
6
+ export interface ChatOptions extends ModelOptions {
7
+ readonly temperature?: number;
8
+ readonly topP?: number;
9
+ readonly topK?: number;
10
+ }
11
+ export interface Prompt extends ModelRequest<Message[]> {
12
+ readonly contents: string;
13
+ copy(): Prompt;
14
+ }
15
+ export interface PromptTemplateStringActions {
16
+ render(model?: Map<String, Object>): string;
17
+ }
18
+ export interface PromptTemplateActions extends PromptTemplateStringActions {
19
+ create(model: Map<String, Object>): Prompt;
20
+ }
21
+ export interface PromptTemplateChatActions {
22
+ createMessages(): Message[];
23
+ createMessages(model: Map<String, Object>): Message[];
24
+ }
25
+ export interface PromptTemplateMessageActions {
26
+ createMessage(mediaList: Media[]): Message;
27
+ createMessage(model: Map<String, Object>): Message;
28
+ }
29
+ //# sourceMappingURL=prompt-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-protocol.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,YAAY;IAE7C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CAE1B;AAED,MAAM,WAAW,MAAO,SAAQ,YAAY,CAAC,OAAO,EAAE,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,IAAI,IAAI,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,2BAA2B;IAExC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;CAE/C;AAED,MAAM,WAAW,qBAAsB,SAAQ,2BAA2B;IAEtE,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;CAE9C;AAED,MAAM,WAAW,yBAAyB;IAEtC,cAAc,IAAI,OAAO,EAAE,CAAC;IAC5B,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;CAEzD;AAED,MAAM,WAAW,4BAA4B;IAEzC,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC3C,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;CAEtD"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=prompt-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-protocol.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-protocol.ts"],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ import { ModelOptions } from '../../model/model-protocol';
2
+ import { Message } from '../message';
3
+ import { ChatOptions, Prompt } from './prompt-protocol';
4
+ export declare class PromptImpl implements Prompt {
5
+ protected messages: Message[];
6
+ protected modelOptions: ChatOptions;
7
+ constructor(messages: Message[] | Message | string, modelOptions?: ChatOptions);
8
+ private instructionsCopy;
9
+ copy(): Prompt;
10
+ get contents(): string;
11
+ get instructions(): Message[];
12
+ get options(): ModelOptions;
13
+ }
14
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAA4B,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAExD,qBAAa,UAAW,YAAW,MAAM;IAErC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAE9B,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC;gBACxB,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,GAAG,MAAM,EAAE,YAAY,GAAE,WAAgB;IAWlF,OAAO,CAAC,gBAAgB;IAexB,IAAI,IAAI,MAAM;IAId,IAAI,QAAQ,IAAI,MAAM,CAMrB;IAED,IAAI,YAAY,IAAI,OAAO,EAAE,CAE5B;IAED,IAAI,OAAO,IAAI,YAAY,CAE1B;CACJ"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromptImpl = void 0;
4
+ const core_1 = require("@celljs/core");
5
+ const message_1 = require("../message");
6
+ class PromptImpl {
7
+ constructor(messages, modelOptions = {}) {
8
+ this.modelOptions = modelOptions;
9
+ if (Array.isArray(messages)) {
10
+ this.messages = messages;
11
+ }
12
+ else if (typeof messages === 'string') {
13
+ this.messages = [new message_1.UserMessage(messages)];
14
+ }
15
+ else {
16
+ this.messages = [messages];
17
+ }
18
+ }
19
+ instructionsCopy() {
20
+ return this.messages.map(message => {
21
+ if (message.messageType === message_1.MessageType.USER) {
22
+ return new message_1.UserMessage(message.content);
23
+ }
24
+ else if (message.messageType === message_1.MessageType.ASSISTANT) {
25
+ return new message_1.UserMessage(message.content);
26
+ }
27
+ else if (message.messageType === message_1.MessageType.SYSTEM) {
28
+ return new message_1.UserMessage(message.content);
29
+ }
30
+ else if (message.messageType === message_1.MessageType.FUNCTION) {
31
+ return new message_1.UserMessage(message.content);
32
+ }
33
+ else {
34
+ throw new core_1.IllegalArgumentError(`Unsupported message type: ${message.messageType}`);
35
+ }
36
+ });
37
+ }
38
+ copy() {
39
+ return new PromptImpl(this.instructionsCopy(), this.modelOptions);
40
+ }
41
+ get contents() {
42
+ let contents = '';
43
+ for (const message of this.messages) {
44
+ contents += message.content;
45
+ }
46
+ return contents;
47
+ }
48
+ get instructions() {
49
+ return this.messages;
50
+ }
51
+ get options() {
52
+ return this.modelOptions;
53
+ }
54
+ }
55
+ exports.PromptImpl = PromptImpl;
56
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAEpD,wCAA+D;AAG/D,MAAa,UAAU;IAKnB,YAAY,QAAsC,EAAE,eAA4B,EAAE;QAC9E,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;SAC5B;aAAM,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YACrC,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,qBAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;SAC/C;aAAM;YACH,IAAI,CAAC,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC;SAC9B;IACL,CAAC;IAEO,gBAAgB;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YAC/B,IAAI,OAAO,CAAC,WAAW,KAAK,qBAAW,CAAC,IAAI,EAAE;gBAC1C,OAAO,IAAI,qBAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAC3C;iBAAM,IAAI,OAAO,CAAC,WAAW,KAAK,qBAAW,CAAC,SAAS,EAAE;gBACtD,OAAO,IAAI,qBAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAC3C;iBAAM,IAAI,OAAO,CAAC,WAAW,KAAK,qBAAW,CAAC,MAAM,EAAE;gBACnD,OAAO,IAAI,qBAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAC3C;iBAAM,IAAI,OAAO,CAAC,WAAW,KAAK,qBAAW,CAAC,QAAQ,EAAE;gBACrD,OAAO,IAAI,qBAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;aAC3C;iBAAM;gBACH,MAAM,IAAI,2BAAoB,CAAC,6BAA6B,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;aACtF;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACD,IAAI;QACA,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,QAAQ;QACR,IAAI,QAAQ,GAAG,EAAE,CAAC;QAClB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjC,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;SAC/B;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AAlDD,gCAkDC"}
@@ -0,0 +1,4 @@
1
+ export * from './chat';
2
+ export * from './model';
3
+ export * from './utils';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./chat"), exports);
18
+ __exportStar(require("./model"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB"}
@@ -0,0 +1,47 @@
1
+ import { ChatOptions } from '../../chat/prompt';
2
+ /**
3
+ * Represents a model function call handler. Implementations are registered with the
4
+ * Models and called on prompts that trigger the function call.
5
+ */
6
+ export interface FunctionCallback {
7
+ /**
8
+ * The Function name. Unique within the model.
9
+ */
10
+ readonly name: string;
11
+ /**
12
+ * The function description. This description is used by the model do
13
+ * decide if the function should be called or not.
14
+ */
15
+ readonly description: string;
16
+ /**
17
+ * The JSON schema of the function input type.
18
+ */
19
+ readonly inputTypeSchema: string;
20
+ /**
21
+ * Called when a model detects and triggers a function call. The model is responsible
22
+ * to pass the function arguments in the pre-configured JSON schema format.
23
+ * @param functionInput JSON string with the function arguments to be passed to the
24
+ * function. The arguments are defined as JSON schema usually registered with the the
25
+ * model.
26
+ * @return String containing the function call response.
27
+ */
28
+ call(functionInput: string): Promise<string>;
29
+ }
30
+ export interface FunctionCallingOptions {
31
+ /**
32
+ * Function Callbacks to be registered with the ChatClient. For Prompt Options the
33
+ * functionCallbacks are automatically enabled for the duration of the prompt
34
+ * execution. For Default Options the FunctionCallbacks are registered but disabled by
35
+ * default. You have to use "functions" property to list the function names from the
36
+ * ChatClient registry to be used in the chat completion requests.
37
+ */
38
+ functionCallbacks: FunctionCallback[];
39
+ /**
40
+ * List of function names from the ChatClient registry to be used in the next
41
+ * chat completion requests.
42
+ */
43
+ functions: Set<String>;
44
+ }
45
+ export interface PortableFunctionCallingOptions extends FunctionCallingOptions, ChatOptions {
46
+ }
47
+ //# sourceMappingURL=function-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-protocol.d.ts","sourceRoot":"","sources":["../../../../src/common/model/function/function-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAE7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC;;;;;;;OAOG;IACH,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAEhD;AAED,MAAM,WAAW,sBAAsB;IAEnC;;;;;;OAMG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IAEtC;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,8BAA+B,SAAQ,sBAAsB,EAAE,WAAW;CAE1F"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=function-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-protocol.js","sourceRoot":"","sources":["../../../../src/common/model/function/function-protocol.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './function-protocol';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/model/function/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./function-protocol"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/model/function/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
@@ -0,0 +1,2 @@
1
+ export * from './model-protocol';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/model/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./model-protocol"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,mDAAiC"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Provides a set of interfaces and classes for a generic API designed to interact with
3
+ * various AI models. This package includes interfaces for handling AI model calls,
4
+ * requests, responses, results, and associated metadata. It is designed to offer a
5
+ * flexible and adaptable framework for interacting with different types of AI models,
6
+ * abstracting the complexities involved in model invocation and result processing. The
7
+ * use of generics enhances the API's capability to work with a wide range of models,
8
+ * ensuring a broad applicability across diverse AI scenarios.
9
+ */
10
+ import { Media } from '../chat';
11
+ import { Observable } from 'rxjs';
12
+ /**
13
+ * Interface representing the customizable options for AI model interactions. This marker
14
+ * interface allows for the specification of various settings and parameters that can
15
+ * influence the behavior and output of AI models. It is designed to provide flexibility
16
+ * and adaptability in different AI scenarios, ensuring that the AI models can be
17
+ * fine-tuned according to specific requirements.
18
+ */
19
+ export interface ModelOptions {
20
+ }
21
+ /**
22
+ * Interface representing metadata associated with the results of an AI model. This
23
+ * interface focuses on providing additional context and insights into the results
24
+ * generated by AI models. It could include information like computation time, model
25
+ * version, or other relevant details that enhance understanding and management of AI
26
+ * model outputs in various applications.
27
+ */
28
+ export interface ResultMetadata {
29
+ }
30
+ /**
31
+ * Interface representing metadata associated with an AI model's response. This interface
32
+ * is designed to provide additional information about the generative response from an AI
33
+ * model, including processing details and model-specific data. It serves as a value
34
+ * object within the core domain, enhancing the understanding and management of AI model
35
+ * responses in various applications.
36
+ */
37
+ export interface ResponseMetadata {
38
+ }
39
+ /**
40
+ * This interface provides methods to access the main output of the AI model and the
41
+ * metadata associated with this result. It is designed to offer a standardized and
42
+ * comprehensive way to handle and interpret the outputs generated by AI models, catering
43
+ * to diverse AI applications and use cases.
44
+ *
45
+ * @param <T> the type of the output generated by the AI model
46
+ */
47
+ export interface ModelResult<T> {
48
+ /**
49
+ * Retrieves the output generated by the AI model.
50
+ * The output generated by the AI model
51
+ */
52
+ readonly output: T;
53
+ /**
54
+ * Retrieves the metadata associated with the result of an AI model.
55
+ * The metadata associated with the result
56
+ */
57
+ readonly metadata: ResultMetadata;
58
+ }
59
+ /**
60
+ * Interface representing a request to an AI model. This interface encapsulates the
61
+ * necessary information required to interact with an AI model, including instructions or
62
+ * inputs (of generic type T) and additional model options. It provides a standardized way
63
+ * to send requests to AI models, ensuring that all necessary details are included and can
64
+ * be easily managed.
65
+ *
66
+ * @param <T> the type of instructions or input required by the AI model
67
+ */
68
+ export interface ModelRequest<T> {
69
+ /**
70
+ * Retrieves the instructions or input required by the AI model.
71
+ * The instructions or input required by the AI model
72
+ */
73
+ readonly instructions: T;
74
+ /**
75
+ * Retrieves the customizable options for AI model interactions.
76
+ * The customizable options for AI model interactions
77
+ */
78
+ readonly options: ModelOptions;
79
+ }
80
+ /**
81
+ * Interface representing the response received from an AI model. This interface provides
82
+ * methods to access the main result or a list of results generated by the AI model, along
83
+ * with the response metadata. It serves as a standardized way to encapsulate and manage
84
+ * the output from AI models, ensuring easy retrieval and processing of the generated
85
+ * information.
86
+ *
87
+ * @param <T> the type of the result(s) provided by the AI model
88
+ */
89
+ export interface ModelResponse<T extends ModelResult<any>> {
90
+ /**
91
+ * Retrieves the result of the AI model.
92
+ * The result generated by the AI model
93
+ */
94
+ readonly result: T;
95
+ /**
96
+ * Retrieves the list of generated outputs by the AI model.
97
+ * The list of generated outputs
98
+ */
99
+ readonly results: T[];
100
+ /**
101
+ * Retrieves the response metadata associated with the AI model's response.
102
+ * The response metadata
103
+ */
104
+ readonly metadata: ResponseMetadata;
105
+ }
106
+ /**
107
+ * The Model interface provides a generic API for invoking AI models. It is designed
108
+ * to handle the interaction with various types of AI models by abstracting the process of
109
+ * sending requests and receiving responses. The interface uses Java generics to
110
+ * accommodate different types of requests and responses, enhancing flexibility and
111
+ * adaptability across different AI model implementations.
112
+ *
113
+ * @param <TReq> the generic type of the request to the AI model
114
+ * @param <TRes> the generic type of the response from the AI model
115
+ */
116
+ export interface Model<TReq extends ModelRequest<any>, TRes extends ModelResponse<any>> {
117
+ /**
118
+ * Executes a method call to the AI model.
119
+ * @param request the request object to be sent to the AI model
120
+ * @return the response from the AI model
121
+ */
122
+ call(request: TReq): Promise<TRes>;
123
+ }
124
+ /**
125
+ * Data structure that contains content and metadata.
126
+ */
127
+ export interface Content {
128
+ /**
129
+ * Get the content of the message.
130
+ */
131
+ readonly content: string;
132
+ /**
133
+ * Get the media associated with the content.
134
+ */
135
+ readonly media: Media[];
136
+ /**
137
+ * return Get the metadata associated with the content.
138
+ */
139
+ readonly metadata: Record<string, any>;
140
+ }
141
+ /**
142
+ * The StreamingModel interface provides a generic API for invoking an AI models
143
+ * with streaming response. It abstracts the process of sending requests and receiving a
144
+ * streaming responses. The interface uses Java generics to accommodate different types of
145
+ * requests and responses, enhancing flexibility and adaptability across different AI
146
+ * model implementations.
147
+ *
148
+ * @param <TReq> the generic type of the request to the AI model
149
+ * @param <TResChunk> the generic type of a single item in the streaming response from the
150
+ * AI model
151
+ */
152
+ export interface StreamingModel<TReq extends ModelRequest<any>, TResChunk extends ModelResponse<any>> {
153
+ /**
154
+ * Executes a method call to the AI model.
155
+ * @param request the request object to be sent to the AI model
156
+ * @return the streaming response from the AI model
157
+ */
158
+ stream(request: TReq): Observable<TResChunk>;
159
+ }
160
+ //# sourceMappingURL=model-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/model/model-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;CAAG;AAEhC;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;CAAG;AAElC;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;CAAG;AAEpC;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CAErC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;CAElC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC;IAErD;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;CAEvC;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,KAAK,CAAC,IAAI,SAAS,YAAY,CAAC,GAAG,CAAC,EAAE,IAAI,SAAS,aAAa,CAAC,GAAG,CAAC;IAElF;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAEtC;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IAEpB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAE1C;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc,CAAC,IAAI,SAAS,YAAY,CAAC,GAAG,CAAC,EAAE,SAAS,SAAS,aAAa,CAAC,GAAG,CAAC;IAEhG;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;CAEhD"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * Provides a set of interfaces and classes for a generic API designed to interact with
4
+ * various AI models. This package includes interfaces for handling AI model calls,
5
+ * requests, responses, results, and associated metadata. It is designed to offer a
6
+ * flexible and adaptable framework for interacting with different types of AI models,
7
+ * abstracting the complexities involved in model invocation and result processing. The
8
+ * use of generics enhances the API's capability to work with a wide range of models,
9
+ * ensuring a broad applicability across diverse AI scenarios.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ //# sourceMappingURL=model-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-protocol.js","sourceRoot":"","sources":["../../../src/common/model/model-protocol.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,4 @@
1
+ import './index';
2
+ declare const _default: import("inversify/lib/interfaces/interfaces").interfaces.ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/common/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC;;AAEjB,wBAA0B"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@celljs/core");
4
+ require("./index");
5
+ exports.default = (0, core_1.autoBind)();
6
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/common/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;AAEjB,kBAAe,IAAA,eAAQ,GAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './prompt-util';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./prompt-util"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B"}
@@ -0,0 +1,5 @@
1
+ import { ChatOptions, Message, Prompt } from '../chat';
2
+ export declare abstract class PromptUtil {
3
+ static create(messages: Message[] | Message | string, options?: ChatOptions): Prompt;
4
+ }
5
+ //# sourceMappingURL=prompt-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-util.d.ts","sourceRoot":"","sources":["../../../src/common/utils/prompt-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAc,MAAM,SAAS,CAAC;AAEnE,8BAAsB,UAAU;WACd,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,GAAG,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM;CAGlG"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromptUtil = void 0;
4
+ const chat_1 = require("../chat");
5
+ class PromptUtil {
6
+ static create(messages, options = {}) {
7
+ return new chat_1.PromptImpl(messages, options);
8
+ }
9
+ }
10
+ exports.PromptUtil = PromptUtil;
11
+ //# sourceMappingURL=prompt-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-util.js","sourceRoot":"","sources":["../../../src/common/utils/prompt-util.ts"],"names":[],"mappings":";;;AAAA,kCAAmE;AAEnE,MAAsB,UAAU;IACrB,MAAM,CAAC,MAAM,CAAC,QAAsC,EAAE,UAAuB,EAAE;QAClF,OAAO,IAAI,iBAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;CACJ;AAJD,gCAIC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=package.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ describe('ai-core package', () => {
2
+ it('support ai-core coverage statistics', () => { });
3
+ });
4
+ //# sourceMappingURL=package.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAE7B,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@celljs/ai-core",
3
+ "version": "3.0.0",
4
+ "description": "Core domain for AI programming",
5
+ "main": "lib/common/index.js",
6
+ "typings": "lib/common/index.d.ts",
7
+ "dependencies": {
8
+ "@celljs/core": "3.0.0",
9
+ "@celljs/http": "3.0.0",
10
+ "rxjs": "^6.6.0"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "keywords": [
16
+ "cell-component"
17
+ ],
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/cellbang/cell.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/cellbang/cell/issues"
25
+ },
26
+ "homepage": "https://github.com/cellbang/cell",
27
+ "files": [
28
+ "lib",
29
+ "src",
30
+ "cell.yml"
31
+ ],
32
+ "scripts": {
33
+ "lint": "cell-component lint",
34
+ "build": "cell-component build",
35
+ "watch": "cell-component watch",
36
+ "clean": "cell-component clean",
37
+ "test": "cell-component test:js"
38
+ },
39
+ "devDependencies": {
40
+ "@celljs/component": "3.0.0"
41
+ },
42
+ "gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
43
+ }
@@ -0,0 +1,4 @@
1
+ export * from './message';
2
+ export * from './metadata';
3
+ export * from './prompt';
4
+ export * from './model';