@celljs/ai-core 3.8.0 → 4.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.
- package/esm/common/chat/index.d.ts +5 -0
- package/esm/common/chat/index.js +6 -0
- package/esm/common/chat/index.js.map +1 -0
- package/esm/common/chat/message/abstract-message.d.ts +9 -0
- package/esm/common/chat/message/abstract-message.js +11 -0
- package/esm/common/chat/message/abstract-message.js.map +1 -0
- package/esm/common/chat/message/assistant-message.d.ts +9 -0
- package/esm/common/chat/message/assistant-message.js +12 -0
- package/esm/common/chat/message/assistant-message.js.map +1 -0
- package/esm/common/chat/message/function-message.d.ts +8 -0
- package/esm/common/chat/message/function-message.js +11 -0
- package/esm/common/chat/message/function-message.js.map +1 -0
- package/esm/common/chat/message/index.d.ts +7 -0
- package/esm/common/chat/message/index.js +8 -0
- package/esm/common/chat/message/index.js.map +1 -0
- package/esm/common/chat/message/message-protocol.d.ts +87 -0
- package/esm/common/chat/message/message-protocol.js +20 -0
- package/esm/common/chat/message/message-protocol.js.map +1 -0
- package/esm/common/chat/message/system-message.d.ts +8 -0
- package/esm/common/chat/message/system-message.js +11 -0
- package/esm/common/chat/message/system-message.js.map +1 -0
- package/esm/common/chat/message/tool-response-message.d.ts +31 -0
- package/esm/common/chat/message/tool-response-message.js +19 -0
- package/esm/common/chat/message/tool-response-message.js.map +1 -0
- package/esm/common/chat/message/user-message.d.ts +8 -0
- package/esm/common/chat/message/user-message.js +11 -0
- package/esm/common/chat/message/user-message.js.map +1 -0
- package/esm/common/chat/metadata/chat-generation-metadata.d.ts +27 -0
- package/esm/common/chat/metadata/chat-generation-metadata.js +16 -0
- package/esm/common/chat/metadata/chat-generation-metadata.js.map +1 -0
- package/esm/common/chat/metadata/index.d.ts +2 -0
- package/esm/common/chat/metadata/index.js +3 -0
- package/esm/common/chat/metadata/index.js.map +1 -0
- package/esm/common/chat/metadata/metadata-protocol.d.ts +127 -0
- package/esm/common/chat/metadata/metadata-protocol.js +92 -0
- package/esm/common/chat/metadata/metadata-protocol.js.map +1 -0
- package/esm/common/chat/model/chat-protocol.d.ts +26 -0
- package/esm/common/chat/model/chat-protocol.js +35 -0
- package/esm/common/chat/model/chat-protocol.js.map +1 -0
- package/esm/common/chat/model/index.d.ts +2 -0
- package/esm/common/chat/model/index.js +3 -0
- package/esm/common/chat/model/index.js.map +1 -0
- package/esm/common/chat/model/proxy-chat-model.d.ts +11 -0
- package/esm/common/chat/model/proxy-chat-model.js +67 -0
- package/esm/common/chat/model/proxy-chat-model.js.map +1 -0
- package/esm/common/chat/prompt/el-prompt-template.d.ts +8 -0
- package/esm/common/chat/prompt/el-prompt-template.js +47 -0
- package/esm/common/chat/prompt/el-prompt-template.js.map +1 -0
- package/esm/common/chat/prompt/index.d.ts +4 -0
- package/esm/common/chat/prompt/index.js +5 -0
- package/esm/common/chat/prompt/index.js.map +1 -0
- package/esm/common/chat/prompt/prompt-protocol.d.ts +49 -0
- package/esm/common/chat/prompt/prompt-protocol.js +2 -0
- package/esm/common/chat/prompt/prompt-protocol.js.map +1 -0
- package/esm/common/chat/prompt/prompt-template.d.ts +6 -0
- package/esm/common/chat/prompt/prompt-template.js +44 -0
- package/esm/common/chat/prompt/prompt-template.js.map +1 -0
- package/esm/common/chat/prompt/prompt.d.ts +13 -0
- package/esm/common/chat/prompt/prompt.js +52 -0
- package/esm/common/chat/prompt/prompt.js.map +1 -0
- package/esm/common/chat/tool/index.d.ts +2 -0
- package/esm/common/chat/tool/index.js +3 -0
- package/esm/common/chat/tool/index.js.map +1 -0
- package/esm/common/chat/tool/tool-handler.d.ts +11 -0
- package/esm/common/chat/tool/tool-handler.js +59 -0
- package/esm/common/chat/tool/tool-handler.js.map +1 -0
- package/esm/common/chat/tool/tool-protocol.d.ts +7 -0
- package/esm/common/chat/tool/tool-protocol.js +2 -0
- package/esm/common/chat/tool/tool-protocol.js.map +1 -0
- package/esm/common/embedding/embedding-protocol.d.ts +120 -0
- package/esm/common/embedding/embedding-protocol.js +56 -0
- package/esm/common/embedding/embedding-protocol.js.map +1 -0
- package/esm/common/embedding/index.d.ts +1 -0
- package/esm/common/embedding/index.js +2 -0
- package/esm/common/embedding/index.js.map +1 -0
- package/esm/common/error/error.d.ts +7 -0
- package/esm/common/error/error.js +12 -0
- package/esm/common/error/error.js.map +1 -0
- package/esm/common/error/index.d.ts +1 -0
- package/esm/common/error/index.js +2 -0
- package/esm/common/error/index.js.map +1 -0
- package/esm/common/index.d.ts +6 -0
- package/esm/common/index.js +7 -0
- package/esm/common/index.js.map +1 -0
- package/esm/common/model/function/function-callback-register.d.ts +8 -0
- package/esm/common/model/function/function-callback-register.js +45 -0
- package/esm/common/model/function/function-callback-register.js.map +1 -0
- package/esm/common/model/function/function-protocol.d.ts +75 -0
- package/esm/common/model/function/function-protocol.js +49 -0
- package/esm/common/model/function/function-protocol.js.map +1 -0
- package/esm/common/model/function/index.d.ts +2 -0
- package/esm/common/model/function/index.js +3 -0
- package/esm/common/model/function/index.js.map +1 -0
- package/esm/common/model/index.d.ts +2 -0
- package/esm/common/model/index.js +3 -0
- package/esm/common/model/index.js.map +1 -0
- package/esm/common/model/model-protocol.d.ts +164 -0
- package/esm/common/model/model-protocol.js +12 -0
- package/esm/common/model/model-protocol.js.map +1 -0
- package/esm/common/module.d.ts +3 -0
- package/esm/common/module.js +4 -0
- package/esm/common/module.js.map +1 -0
- package/esm/common/sse/index.d.ts +3 -0
- package/esm/common/sse/index.js +4 -0
- package/esm/common/sse/index.js.map +1 -0
- package/esm/common/sse/line-decoder.d.ts +14 -0
- package/esm/common/sse/line-decoder.js +51 -0
- package/esm/common/sse/line-decoder.js.map +1 -0
- package/esm/common/sse/sse-decoder.d.ts +26 -0
- package/esm/common/sse/sse-decoder.js +70 -0
- package/esm/common/sse/sse-decoder.js.map +1 -0
- package/esm/common/sse/sse-protocol.d.ts +22 -0
- package/esm/common/sse/sse-protocol.js +2 -0
- package/esm/common/sse/sse-protocol.js.map +1 -0
- package/esm/common/utils/index.d.ts +3 -0
- package/esm/common/utils/index.js +4 -0
- package/esm/common/utils/index.js.map +1 -0
- package/esm/common/utils/prompt-util.d.ts +4 -0
- package/esm/common/utils/prompt-util.js +7 -0
- package/esm/common/utils/prompt-util.js.map +1 -0
- package/esm/common/utils/sse-util.d.ts +10 -0
- package/esm/common/utils/sse-util.js +109 -0
- package/esm/common/utils/sse-util.js.map +1 -0
- package/esm/common/utils/usage-util.d.ts +16 -0
- package/esm/common/utils/usage-util.js +59 -0
- package/esm/common/utils/usage-util.js.map +1 -0
- package/esm/package.json +3 -0
- package/package.json +84 -5
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { MimeType } from '@celljs/core';
|
|
2
|
+
import { Usage } from '../chat/metadata/metadata-protocol.js';
|
|
3
|
+
import { Model, ModelOptions, ModelRequest, ModelResponse, ModelResult, ResponseMetadata, ResultMetadata } from '../model/model-protocol.js';
|
|
4
|
+
export declare const EmbeddingModel: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Enum representing the modality type of the source data.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ModalityType {
|
|
9
|
+
TEXT = "TEXT",
|
|
10
|
+
IMAGE = "IMAGE",
|
|
11
|
+
AUDIO = "AUDIO",
|
|
12
|
+
VIDEO = "VIDEO"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents the metadata for an embedding result.
|
|
16
|
+
*/
|
|
17
|
+
export interface EmbeddingResultMetadata extends ResultMetadata {
|
|
18
|
+
/**
|
|
19
|
+
* The modality type of the source data used to generate the embedding.
|
|
20
|
+
*/
|
|
21
|
+
modalityType: ModalityType;
|
|
22
|
+
/**
|
|
23
|
+
* The document ID associated with the embedding.
|
|
24
|
+
*/
|
|
25
|
+
documentId: string;
|
|
26
|
+
/**
|
|
27
|
+
* The MIME type of the source data used to generate the embedding.
|
|
28
|
+
*/
|
|
29
|
+
mimeType: MimeType;
|
|
30
|
+
/**
|
|
31
|
+
* The document data associated with the embedding.
|
|
32
|
+
*/
|
|
33
|
+
documentData: any;
|
|
34
|
+
}
|
|
35
|
+
export declare namespace EmbeddingResultMetadata {
|
|
36
|
+
const EMPTY: EmbeddingResultMetadata;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Utility class for modality-related operations.
|
|
40
|
+
*/
|
|
41
|
+
export declare class ModalityUtils {
|
|
42
|
+
private static TEXT_MIME_TYPE;
|
|
43
|
+
private static IMAGE_MIME_TYPE;
|
|
44
|
+
private static VIDEO_MIME_TYPE;
|
|
45
|
+
private static AUDIO_MIME_TYPE;
|
|
46
|
+
/**
|
|
47
|
+
* Infers the {@link ModalityType} of the source data used to generate the
|
|
48
|
+
* embedding using the source data {@link MimeType}.
|
|
49
|
+
* @param mimeType the {@link MimeType} of the source data.
|
|
50
|
+
* @return Returns the {@link ModalityType} of the source data used to generate
|
|
51
|
+
* the embedding.
|
|
52
|
+
*/
|
|
53
|
+
static getModalityType(mimeType: MimeType): ModalityType;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Metadata for the embedding response.
|
|
57
|
+
*/
|
|
58
|
+
export interface EmbeddingResponseMetadata extends ResponseMetadata {
|
|
59
|
+
/**
|
|
60
|
+
* The model that handled the request.
|
|
61
|
+
*/
|
|
62
|
+
model: string;
|
|
63
|
+
/**
|
|
64
|
+
* The AI provider specific metadata on API usage.
|
|
65
|
+
* @see Usage
|
|
66
|
+
*/
|
|
67
|
+
usage: Usage;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Represents a single embedding vector.
|
|
71
|
+
*/
|
|
72
|
+
export interface Embedding extends ModelResult<number[]> {
|
|
73
|
+
/**
|
|
74
|
+
* The embedding vector values.
|
|
75
|
+
*/
|
|
76
|
+
embedding: number[];
|
|
77
|
+
/**
|
|
78
|
+
* The embedding index in a list of embeddings.
|
|
79
|
+
*/
|
|
80
|
+
index: number;
|
|
81
|
+
/**
|
|
82
|
+
* The metadata associated with the embedding.
|
|
83
|
+
*/
|
|
84
|
+
metadata: EmbeddingResultMetadata;
|
|
85
|
+
}
|
|
86
|
+
export interface EmbeddingOptions extends ModelOptions {
|
|
87
|
+
/**
|
|
88
|
+
* The name of the embedding model to use.
|
|
89
|
+
*/
|
|
90
|
+
model?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The dimensionality of the embedding vectors.
|
|
93
|
+
*/
|
|
94
|
+
dimensions?: number;
|
|
95
|
+
}
|
|
96
|
+
export interface EmbeddingRequest extends ModelRequest<string[]> {
|
|
97
|
+
/**
|
|
98
|
+
* The list of input strings for the embedding request.
|
|
99
|
+
*/
|
|
100
|
+
inputs: string[];
|
|
101
|
+
/**
|
|
102
|
+
* The options for the embedding request.
|
|
103
|
+
*/
|
|
104
|
+
options: EmbeddingOptions;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Embedding response object.
|
|
108
|
+
*/
|
|
109
|
+
export interface EmbeddingResponse extends ModelResponse<Embedding> {
|
|
110
|
+
/**
|
|
111
|
+
* Embedding data.
|
|
112
|
+
*/
|
|
113
|
+
embeddings: Embedding[];
|
|
114
|
+
/**
|
|
115
|
+
* Embedding metadata.
|
|
116
|
+
*/
|
|
117
|
+
metadata: EmbeddingResponseMetadata;
|
|
118
|
+
}
|
|
119
|
+
export interface EmbeddingModel extends Model<EmbeddingRequest, EmbeddingResponse> {
|
|
120
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { MimeTypeUtils } from '@celljs/core';
|
|
2
|
+
export const EmbeddingModel = Symbol('EmbeddingModel');
|
|
3
|
+
/**
|
|
4
|
+
* Enum representing the modality type of the source data.
|
|
5
|
+
*/
|
|
6
|
+
export var ModalityType;
|
|
7
|
+
(function (ModalityType) {
|
|
8
|
+
ModalityType["TEXT"] = "TEXT";
|
|
9
|
+
ModalityType["IMAGE"] = "IMAGE";
|
|
10
|
+
ModalityType["AUDIO"] = "AUDIO";
|
|
11
|
+
ModalityType["VIDEO"] = "VIDEO";
|
|
12
|
+
})(ModalityType || (ModalityType = {}));
|
|
13
|
+
export var EmbeddingResultMetadata;
|
|
14
|
+
(function (EmbeddingResultMetadata) {
|
|
15
|
+
EmbeddingResultMetadata.EMPTY = {
|
|
16
|
+
modalityType: ModalityType.TEXT,
|
|
17
|
+
documentId: '',
|
|
18
|
+
mimeType: MimeTypeUtils.TEXT_PLAIN,
|
|
19
|
+
documentData: undefined
|
|
20
|
+
};
|
|
21
|
+
})(EmbeddingResultMetadata || (EmbeddingResultMetadata = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Utility class for modality-related operations.
|
|
24
|
+
*/
|
|
25
|
+
export class ModalityUtils {
|
|
26
|
+
/**
|
|
27
|
+
* Infers the {@link ModalityType} of the source data used to generate the
|
|
28
|
+
* embedding using the source data {@link MimeType}.
|
|
29
|
+
* @param mimeType the {@link MimeType} of the source data.
|
|
30
|
+
* @return Returns the {@link ModalityType} of the source data used to generate
|
|
31
|
+
* the embedding.
|
|
32
|
+
*/
|
|
33
|
+
static getModalityType(mimeType) {
|
|
34
|
+
if (!mimeType) {
|
|
35
|
+
return ModalityType.TEXT;
|
|
36
|
+
}
|
|
37
|
+
if (mimeType.isCompatibleWith(ModalityUtils.IMAGE_MIME_TYPE)) {
|
|
38
|
+
return ModalityType.IMAGE;
|
|
39
|
+
}
|
|
40
|
+
else if (mimeType.isCompatibleWith(ModalityUtils.AUDIO_MIME_TYPE)) {
|
|
41
|
+
return ModalityType.AUDIO;
|
|
42
|
+
}
|
|
43
|
+
else if (mimeType.isCompatibleWith(ModalityUtils.VIDEO_MIME_TYPE)) {
|
|
44
|
+
return ModalityType.VIDEO;
|
|
45
|
+
}
|
|
46
|
+
else if (mimeType.isCompatibleWith(ModalityUtils.TEXT_MIME_TYPE)) {
|
|
47
|
+
return ModalityType.TEXT;
|
|
48
|
+
}
|
|
49
|
+
throw new Error('Unsupported MimeType: ' + mimeType);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
ModalityUtils.TEXT_MIME_TYPE = MimeTypeUtils.parseMimeType('text/*');
|
|
53
|
+
ModalityUtils.IMAGE_MIME_TYPE = MimeTypeUtils.parseMimeType('image/*');
|
|
54
|
+
ModalityUtils.VIDEO_MIME_TYPE = MimeTypeUtils.parseMimeType('video/*');
|
|
55
|
+
ModalityUtils.AUDIO_MIME_TYPE = MimeTypeUtils.parseMimeType('audio/*');
|
|
56
|
+
//# sourceMappingURL=embedding-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding-protocol.js","sourceRoot":"","sources":["../../../src/common/embedding/embedding-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,aAAa,EAAE,MAAM,cAAc,CAAC;AAIvD,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAN,IAAY,YAKX;AALD,WAAY,YAAY;IACpB,6BAAa,CAAA;IACb,+BAAe,CAAA;IACf,+BAAe,CAAA;IACf,+BAAe,CAAA;AACnB,CAAC,EALW,YAAY,KAAZ,YAAY,QAKvB;AA2BD,MAAM,KAAW,uBAAuB,CAOvC;AAPD,WAAiB,uBAAuB;IACvB,6BAAK,GAA4B;QAC1C,YAAY,EAAE,YAAY,CAAC,IAAI;QAC/B,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,aAAa,CAAC,UAAU;QAClC,YAAY,EAAE,SAAS;KAC1B,CAAC;AACN,CAAC,EAPgB,uBAAuB,KAAvB,uBAAuB,QAOvC;AAED;;GAEG;AACH,MAAM,OAAO,aAAa;IAMtB;;;;;;OAMG;IACI,MAAM,CAAC,eAAe,CAAC,QAAkB;QAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,OAAO,YAAY,CAAC,IAAI,CAAC;QAC7B,CAAC;QAED,IAAI,QAAQ,CAAC,gBAAgB,CAAC,aAAa,CAAC,eAAe,CAAC,EAAE,CAAC;YAC3D,OAAO,YAAY,CAAC,KAAK,CAAC;QAC9B,CAAC;aAAM,IAAI,QAAQ,CAAC,gBAAgB,CAAC,aAAa,CAAC,eAAe,CAAC,EAAE,CAAC;YAClE,OAAO,YAAY,CAAC,KAAK,CAAC;QAC9B,CAAC;aAAM,IAAI,QAAQ,CAAC,gBAAgB,CAAC,aAAa,CAAC,eAAe,CAAC,EAAE,CAAC;YAClE,OAAO,YAAY,CAAC,KAAK,CAAC;QAC9B,CAAC;aAAM,IAAI,QAAQ,CAAC,gBAAgB,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;YACjE,OAAO,YAAY,CAAC,IAAI,CAAC;QAC7B,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,QAAQ,CAAC,CAAC;IACzD,CAAC;CACJ;AA7BkB,4BAAc,GAAG,aAAa,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACvD,6BAAe,GAAG,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AACzD,6BAAe,GAAG,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AACzD,6BAAe,GAAG,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './embedding-protocol.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/embedding/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CustomError } from '@celljs/core';
|
|
2
|
+
export class AIError extends CustomError {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class NotFoundError extends AIError {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/common/error/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,OAAQ,SAAQ,WAAW;IACpC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ;AAED,MAAM,OAAO,aAAc,SAAQ,OAAO;IACtC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './error.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FunctionCallback, FunctionCallbackRegister, ToolContext } from './function-protocol.js';
|
|
2
|
+
export declare class FunctionCallbackRegisterImpl implements FunctionCallbackRegister {
|
|
3
|
+
private functionCallbacks;
|
|
4
|
+
register(functionCallback: FunctionCallback): void;
|
|
5
|
+
unregister(functionName: string): void;
|
|
6
|
+
call(functionName: string, functionArguments: string, toolContext: ToolContext): Promise<string>;
|
|
7
|
+
resolve(functionNames: string[]): FunctionCallback[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Component } from '@celljs/core';
|
|
8
|
+
import { FunctionCallbackRegister } from './function-protocol.js';
|
|
9
|
+
import { NotFoundError } from '../../error/index.js';
|
|
10
|
+
let FunctionCallbackRegisterImpl = class FunctionCallbackRegisterImpl {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.functionCallbacks = new Map();
|
|
13
|
+
}
|
|
14
|
+
register(functionCallback) {
|
|
15
|
+
this.functionCallbacks.set(functionCallback.name, functionCallback);
|
|
16
|
+
}
|
|
17
|
+
unregister(functionName) {
|
|
18
|
+
this.functionCallbacks.delete(functionName);
|
|
19
|
+
}
|
|
20
|
+
call(functionName, functionArguments, toolContext) {
|
|
21
|
+
const functionCallback = this.functionCallbacks.get(functionName);
|
|
22
|
+
if (functionCallback) {
|
|
23
|
+
return functionCallback.call(functionArguments, toolContext);
|
|
24
|
+
}
|
|
25
|
+
throw new NotFoundError(`Function ${functionName} not found`);
|
|
26
|
+
}
|
|
27
|
+
resolve(functionNames) {
|
|
28
|
+
const functionCallbacks = [];
|
|
29
|
+
new Set(functionNames).forEach(functionName => {
|
|
30
|
+
const functionCallback = this.functionCallbacks.get(functionName);
|
|
31
|
+
if (functionCallback) {
|
|
32
|
+
functionCallbacks.push(functionCallback);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new NotFoundError(`No function callback found for name: ${functionName}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return functionCallbacks;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
FunctionCallbackRegisterImpl = __decorate([
|
|
42
|
+
Component(FunctionCallbackRegister)
|
|
43
|
+
], FunctionCallbackRegisterImpl);
|
|
44
|
+
export { FunctionCallbackRegisterImpl };
|
|
45
|
+
//# sourceMappingURL=function-callback-register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-callback-register.js","sourceRoot":"","sources":["../../../../src/common/model/function/function-callback-register.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAoB,wBAAwB,EAAe,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGrC,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAAlC;QAEK,sBAAiB,GAAkC,IAAI,GAAG,EAA4B,CAAC;IA8BnG,CAAC;IA5BG,QAAQ,CAAC,gBAAkC;QACvC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IACxE,CAAC;IAED,UAAU,CAAC,YAAoB;QAC3B,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,CAAC,YAAoB,EAAE,iBAAyB,EAAE,WAAwB;QAC1E,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAClE,IAAI,gBAAgB,EAAE,CAAC;YACnB,OAAO,gBAAgB,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,IAAI,aAAa,CAAC,YAAY,YAAY,YAAY,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,CAAC,aAAuB;QAC3B,MAAM,iBAAiB,GAAuB,EAAE,CAAC;QACjD,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YAC1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAClE,IAAI,gBAAgB,EAAE,CAAC;gBACnB,iBAAiB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YAC7C,CAAC;iBAAM,CAAC;gBACJ,MAAM,IAAI,aAAa,CAAC,wCAAwC,YAAY,EAAE,CAAC,CAAC;YACpF,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,iBAAiB,CAAC;IAC7B,CAAC;CACJ,CAAA;AAhCY,4BAA4B;IADxC,SAAS,CAAC,wBAAwB,CAAC;GACvB,4BAA4B,CAgCxC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ChatOptions } from '../../chat/prompt/index.js';
|
|
2
|
+
export declare const FunctionCallbackRegister: unique symbol;
|
|
3
|
+
export interface ToolContext extends Record<string, any> {
|
|
4
|
+
}
|
|
5
|
+
export declare namespace ToolContext {
|
|
6
|
+
const TOOL_CALL_HISTORY = "TOOL_CALL_HISTORY";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Represents a model function call handler. Implementations are registered with the
|
|
10
|
+
* Models and called on prompts that trigger the function call.
|
|
11
|
+
*/
|
|
12
|
+
export interface FunctionCallback {
|
|
13
|
+
/**
|
|
14
|
+
* The Function name. Unique within the model.
|
|
15
|
+
*/
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/**
|
|
18
|
+
* The function description. This description is used by the model do
|
|
19
|
+
* decide if the function should be called or not.
|
|
20
|
+
*/
|
|
21
|
+
readonly description: string;
|
|
22
|
+
/**
|
|
23
|
+
* The JSON schema of the function input type.
|
|
24
|
+
*/
|
|
25
|
+
readonly inputTypeSchema: string;
|
|
26
|
+
/**
|
|
27
|
+
* Called when a model detects and triggers a function call. The model is responsible
|
|
28
|
+
* to pass the function arguments in the pre-configured JSON schema format.
|
|
29
|
+
* @param functionArguments JSON string with the function arguments to be passed to the
|
|
30
|
+
* function. The arguments are defined as JSON schema usually registered with the the
|
|
31
|
+
* model.
|
|
32
|
+
* @param toolContext Optional tool context to be passed to the function call.
|
|
33
|
+
* @return String containing the function call response.
|
|
34
|
+
*/
|
|
35
|
+
call(functionArguments: string, toolContext?: ToolContext): Promise<string>;
|
|
36
|
+
}
|
|
37
|
+
export interface FunctionCallingOptions extends ChatOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Function Callbacks to be registered with the ChatClient. For Prompt Options the
|
|
40
|
+
* functionCallbacks are automatically enabled for the duration of the prompt
|
|
41
|
+
* execution. For Default Options the FunctionCallbacks are registered but disabled by
|
|
42
|
+
* default. You have to use "functions" property to list the function names from the
|
|
43
|
+
* ChatClient registry to be used in the chat completion requests.
|
|
44
|
+
*/
|
|
45
|
+
functionCallbacks: FunctionCallback[];
|
|
46
|
+
/**
|
|
47
|
+
* List of function names from the ChatClient registry to be used in the next
|
|
48
|
+
* chat completion requests.
|
|
49
|
+
*/
|
|
50
|
+
functions: Set<string>;
|
|
51
|
+
proxyToolCalls?: boolean;
|
|
52
|
+
toolContext?: ToolContext;
|
|
53
|
+
}
|
|
54
|
+
export declare namespace FunctionCallingOptions {
|
|
55
|
+
function is(obj: any): obj is FunctionCallingOptions;
|
|
56
|
+
function getEnabledFunctionsToCall(runtimeFunctionOptions: FunctionCallingOptions): Set<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Check if the proxyToolCalls is enabled for the given prompt or the default tool
|
|
59
|
+
* call options. The prompt options take precedence over the default options. When the
|
|
60
|
+
* proxyToolCalls is enabled the ChatModel implementation will pass the proxyToolCalls to the
|
|
61
|
+
* function call.
|
|
62
|
+
* @param chatOptions the chat options to check.
|
|
63
|
+
* @param defaultOptions the default tool call options to check.
|
|
64
|
+
* @return true if the proxyToolCalls is enabled, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
function isProxyToolCalls(chatOptions: ChatOptions, defaultOptions: FunctionCallingOptions): boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface FunctionCallbackRegister {
|
|
69
|
+
resolve(functionNames: string[]): FunctionCallback[];
|
|
70
|
+
register(functionCallback: FunctionCallback): void;
|
|
71
|
+
unregister(functionName: string): void;
|
|
72
|
+
call(functionName: string, functionArguments: string, toolContext: ToolContext): Promise<string>;
|
|
73
|
+
}
|
|
74
|
+
export interface PortableFunctionCallingOptions extends FunctionCallingOptions, ChatOptions {
|
|
75
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export const FunctionCallbackRegister = Symbol('FunctionCallbackRegister');
|
|
2
|
+
export var ToolContext;
|
|
3
|
+
(function (ToolContext) {
|
|
4
|
+
ToolContext.TOOL_CALL_HISTORY = 'TOOL_CALL_HISTORY';
|
|
5
|
+
})(ToolContext || (ToolContext = {}));
|
|
6
|
+
export var FunctionCallingOptions;
|
|
7
|
+
(function (FunctionCallingOptions) {
|
|
8
|
+
function is(obj) {
|
|
9
|
+
return obj && obj.functionCallbacks !== undefined && obj.functions !== undefined;
|
|
10
|
+
}
|
|
11
|
+
FunctionCallingOptions.is = is;
|
|
12
|
+
function getEnabledFunctionsToCall(runtimeFunctionOptions) {
|
|
13
|
+
const enabledFunctionsToCall = new Set();
|
|
14
|
+
if (runtimeFunctionOptions) {
|
|
15
|
+
// Add the explicitly enabled functions.
|
|
16
|
+
if (runtimeFunctionOptions.functions) {
|
|
17
|
+
runtimeFunctionOptions.functions.forEach(fn => {
|
|
18
|
+
enabledFunctionsToCall.add(fn);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (runtimeFunctionOptions.functionCallbacks) {
|
|
22
|
+
runtimeFunctionOptions.functionCallbacks.forEach(functionCallback => {
|
|
23
|
+
// Automatically enable the function, usually from prompt callback.
|
|
24
|
+
enabledFunctionsToCall.add(functionCallback.name);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return enabledFunctionsToCall;
|
|
29
|
+
}
|
|
30
|
+
FunctionCallingOptions.getEnabledFunctionsToCall = getEnabledFunctionsToCall;
|
|
31
|
+
/**
|
|
32
|
+
* Check if the proxyToolCalls is enabled for the given prompt or the default tool
|
|
33
|
+
* call options. The prompt options take precedence over the default options. When the
|
|
34
|
+
* proxyToolCalls is enabled the ChatModel implementation will pass the proxyToolCalls to the
|
|
35
|
+
* function call.
|
|
36
|
+
* @param chatOptions the chat options to check.
|
|
37
|
+
* @param defaultOptions the default tool call options to check.
|
|
38
|
+
* @return true if the proxyToolCalls is enabled, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
function isProxyToolCalls(chatOptions, defaultOptions) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (FunctionCallingOptions.is(chatOptions) && chatOptions.proxyToolCalls !== undefined) {
|
|
43
|
+
return chatOptions.proxyToolCalls;
|
|
44
|
+
}
|
|
45
|
+
return (_a = defaultOptions.proxyToolCalls) !== null && _a !== void 0 ? _a : false;
|
|
46
|
+
}
|
|
47
|
+
FunctionCallingOptions.isProxyToolCalls = isProxyToolCalls;
|
|
48
|
+
})(FunctionCallingOptions || (FunctionCallingOptions = {}));
|
|
49
|
+
//# 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":"AAEA,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAI3E,MAAM,KAAW,WAAW,CAE3B;AAFD,WAAiB,WAAW;IACX,6BAAiB,GAAG,mBAAmB,CAAC;AACzD,CAAC,EAFgB,WAAW,KAAX,WAAW,QAE3B;AA2DD,MAAM,KAAW,sBAAsB,CAyCtC;AAzCD,WAAiB,sBAAsB;IACnC,SAAgB,EAAE,CAAC,GAAQ;QACvB,OAAO,GAAG,IAAI,GAAG,CAAC,iBAAiB,KAAK,SAAS,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC;IACrF,CAAC;IAFe,uBAAA,EAAE,KAEjB,CAAA;IAED,SAAgB,yBAAyB,CAAC,sBAA8C;QACpF,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAU,CAAC;QACjD,IAAI,sBAAsB,EAAE,CAAC;YACzB,wCAAwC;YACxC,IAAI,sBAAsB,CAAC,SAAS,EAAE,CAAC;gBACnC,sBAAsB,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;oBAC1C,sBAAsB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACnC,CAAC,CAAC,CAAC;YACP,CAAC;YAED,IAAI,sBAAsB,CAAC,iBAAiB,EAAE,CAAC;gBAC3C,sBAAsB,CAAC,iBAAiB,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE;oBAChE,mEAAmE;oBACnE,sBAAsB,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;gBACtD,CAAC,CAAC,CAAC;YACP,CAAC;QACL,CAAC;QACD,OAAO,sBAAsB,CAAC;IAClC,CAAC;IAlBe,uBAAA,yBAAyB,4BAkBxC,CAAA;IAED;;;;;;;;OAQG;IACH,SAAgB,gBAAgB,CAAC,WAAwB,EAAE,cAAsC;;QAC7F,IAAI,sBAAsB,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACrF,OAAO,WAAW,CAAC,cAAc,CAAC;QACtC,CAAC;QACD,aAAO,cAAc,CAAC,cAAc,mCAAI,KAAK,CAAC;IAClD,CAAC;IALe,uBAAA,gBAAgB,mBAK/B,CAAA;AAEL,CAAC,EAzCgB,sBAAsB,KAAtB,sBAAsB,QAyCtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/model/function/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/model/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
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/index.js';
|
|
11
|
+
import { Observable } from 'rxjs';
|
|
12
|
+
export declare const Model: unique symbol;
|
|
13
|
+
export declare const StreamingModel: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* Interface representing the customizable options for AI model interactions. This marker
|
|
16
|
+
* interface allows for the specification of various settings and parameters that can
|
|
17
|
+
* influence the behavior and output of AI models. It is designed to provide flexibility
|
|
18
|
+
* and adaptability in different AI scenarios, ensuring that the AI models can be
|
|
19
|
+
* fine-tuned according to specific requirements.
|
|
20
|
+
*/
|
|
21
|
+
export interface ModelOptions {
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
httpHeaders?: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Interface representing metadata associated with the results of an AI model. This
|
|
27
|
+
* interface focuses on providing additional context and insights into the results
|
|
28
|
+
* generated by AI models. It could include information like computation time, model
|
|
29
|
+
* version, or other relevant details that enhance understanding and management of AI
|
|
30
|
+
* model outputs in various applications.
|
|
31
|
+
*/
|
|
32
|
+
export interface ResultMetadata {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Interface representing metadata associated with an AI model's response. This interface
|
|
36
|
+
* is designed to provide additional information about the generative response from an AI
|
|
37
|
+
* model, including processing details and model-specific data. It serves as a value
|
|
38
|
+
* object within the core domain, enhancing the understanding and management of AI model
|
|
39
|
+
* responses in various applications.
|
|
40
|
+
*/
|
|
41
|
+
export interface ResponseMetadata {
|
|
42
|
+
readonly extra: Record<string, any>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* This interface provides methods to access the main output of the AI model and the
|
|
46
|
+
* metadata associated with this result. It is designed to offer a standardized and
|
|
47
|
+
* comprehensive way to handle and interpret the outputs generated by AI models, catering
|
|
48
|
+
* to diverse AI applications and use cases.
|
|
49
|
+
*
|
|
50
|
+
* @param <T> the type of the output generated by the AI model
|
|
51
|
+
*/
|
|
52
|
+
export interface ModelResult<T> {
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the output generated by the AI model.
|
|
55
|
+
* The output generated by the AI model
|
|
56
|
+
*/
|
|
57
|
+
readonly output: T;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves the metadata associated with the result of an AI model.
|
|
60
|
+
* The metadata associated with the result
|
|
61
|
+
*/
|
|
62
|
+
readonly metadata: ResultMetadata;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interface representing a request to an AI model. This interface encapsulates the
|
|
66
|
+
* necessary information required to interact with an AI model, including instructions or
|
|
67
|
+
* inputs (of generic type T) and additional model options. It provides a standardized way
|
|
68
|
+
* to send requests to AI models, ensuring that all necessary details are included and can
|
|
69
|
+
* be easily managed.
|
|
70
|
+
*
|
|
71
|
+
* @param <T> the type of instructions or input required by the AI model
|
|
72
|
+
*/
|
|
73
|
+
export interface ModelRequest<T> {
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves the instructions or input required by the AI model.
|
|
76
|
+
* The instructions or input required by the AI model
|
|
77
|
+
*/
|
|
78
|
+
readonly instructions: T;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves the customizable options for AI model interactions.
|
|
81
|
+
* The customizable options for AI model interactions
|
|
82
|
+
*/
|
|
83
|
+
readonly options: ModelOptions;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Interface representing the response received from an AI model. This interface provides
|
|
87
|
+
* methods to access the main result or a list of results generated by the AI model, along
|
|
88
|
+
* with the response metadata. It serves as a standardized way to encapsulate and manage
|
|
89
|
+
* the output from AI models, ensuring easy retrieval and processing of the generated
|
|
90
|
+
* information.
|
|
91
|
+
*
|
|
92
|
+
* @param <T> the type of the result(s) provided by the AI model
|
|
93
|
+
*/
|
|
94
|
+
export interface ModelResponse<T extends ModelResult<any>> {
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves the result of the AI model.
|
|
97
|
+
* The result generated by the AI model
|
|
98
|
+
*/
|
|
99
|
+
readonly result: T;
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves the list of generated outputs by the AI model.
|
|
102
|
+
* The list of generated outputs
|
|
103
|
+
*/
|
|
104
|
+
readonly results: T[];
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the response metadata associated with the AI model's response.
|
|
107
|
+
* The response metadata
|
|
108
|
+
*/
|
|
109
|
+
readonly metadata: ResponseMetadata;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The Model interface provides a generic API for invoking AI models. It is designed
|
|
113
|
+
* to handle the interaction with various types of AI models by abstracting the process of
|
|
114
|
+
* sending requests and receiving responses. The interface uses Java generics to
|
|
115
|
+
* accommodate different types of requests and responses, enhancing flexibility and
|
|
116
|
+
* adaptability across different AI model implementations.
|
|
117
|
+
*
|
|
118
|
+
* @param <TReq> the generic type of the request to the AI model
|
|
119
|
+
* @param <TRes> the generic type of the response from the AI model
|
|
120
|
+
*/
|
|
121
|
+
export interface Model<TReq extends ModelRequest<any>, TRes extends ModelResponse<any>> {
|
|
122
|
+
/**
|
|
123
|
+
* Executes a method call to the AI model.
|
|
124
|
+
* @param request the request object to be sent to the AI model
|
|
125
|
+
* @return the response from the AI model
|
|
126
|
+
*/
|
|
127
|
+
call(request: TReq): Promise<TRes>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Data structure that contains content and metadata.
|
|
131
|
+
*/
|
|
132
|
+
export interface Content {
|
|
133
|
+
/**
|
|
134
|
+
* The content of the message.
|
|
135
|
+
*/
|
|
136
|
+
content: string;
|
|
137
|
+
/**
|
|
138
|
+
* The media associated with the content.
|
|
139
|
+
*/
|
|
140
|
+
media: Media[];
|
|
141
|
+
/**
|
|
142
|
+
* The metadata associated with the content.
|
|
143
|
+
*/
|
|
144
|
+
metadata: Record<string, any>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The StreamingModel interface provides a generic API for invoking an AI models
|
|
148
|
+
* with streaming response. It abstracts the process of sending requests and receiving a
|
|
149
|
+
* streaming responses. The interface uses Java generics to accommodate different types of
|
|
150
|
+
* requests and responses, enhancing flexibility and adaptability across different AI
|
|
151
|
+
* model implementations.
|
|
152
|
+
*
|
|
153
|
+
* @param <TReq> the generic type of the request to the AI model
|
|
154
|
+
* @param <TResChunk> the generic type of a single item in the streaming response from the
|
|
155
|
+
* AI model
|
|
156
|
+
*/
|
|
157
|
+
export interface StreamingModel<TReq extends ModelRequest<any>, TResChunk extends ModelResponse<any>> {
|
|
158
|
+
/**
|
|
159
|
+
* Executes a method call to the AI model.
|
|
160
|
+
* @param request the request object to be sent to the AI model
|
|
161
|
+
* @return the streaming response from the AI model
|
|
162
|
+
*/
|
|
163
|
+
stream(request: TReq): Promise<Observable<TResChunk>>;
|
|
164
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export const Model = Symbol('Model');
|
|
11
|
+
export const StreamingModel = Symbol('StreamingModel');
|
|
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;AAKH,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|