@celljs/ai-core 3.2.0 → 3.3.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/README.md +107 -0
- package/lib/common/chat/message/assistant-message.d.ts +3 -2
- package/lib/common/chat/message/assistant-message.d.ts.map +1 -1
- package/lib/common/chat/message/assistant-message.js +2 -1
- package/lib/common/chat/message/assistant-message.js.map +1 -1
- package/lib/common/chat/message/index.d.ts +1 -0
- package/lib/common/chat/message/index.d.ts.map +1 -1
- package/lib/common/chat/message/index.js +1 -0
- package/lib/common/chat/message/index.js.map +1 -1
- package/lib/common/chat/message/message-protocol.d.ts +23 -1
- package/lib/common/chat/message/message-protocol.d.ts.map +1 -1
- package/lib/common/chat/message/message-protocol.js +1 -0
- package/lib/common/chat/message/message-protocol.js.map +1 -1
- package/lib/common/chat/message/tool-response-message.d.ts +32 -0
- package/lib/common/chat/message/tool-response-message.d.ts.map +1 -0
- package/lib/common/chat/message/tool-response-message.js +23 -0
- package/lib/common/chat/message/tool-response-message.js.map +1 -0
- package/lib/common/chat/metadata/chat-generation-metadata.d.ts +28 -0
- package/lib/common/chat/metadata/chat-generation-metadata.d.ts.map +1 -0
- package/lib/common/chat/metadata/chat-generation-metadata.js +21 -0
- package/lib/common/chat/metadata/chat-generation-metadata.js.map +1 -0
- package/lib/common/chat/metadata/index.d.ts +1 -0
- package/lib/common/chat/metadata/index.d.ts.map +1 -1
- package/lib/common/chat/metadata/index.js +1 -0
- package/lib/common/chat/metadata/index.js.map +1 -1
- package/lib/common/chat/metadata/metadata-protocol.d.ts +2 -0
- package/lib/common/chat/metadata/metadata-protocol.d.ts.map +1 -1
- package/lib/common/chat/metadata/metadata-protocol.js.map +1 -1
- package/lib/common/chat/prompt/index.d.ts +1 -0
- package/lib/common/chat/prompt/index.d.ts.map +1 -1
- package/lib/common/chat/prompt/index.js +1 -0
- package/lib/common/chat/prompt/index.js.map +1 -1
- package/lib/common/chat/prompt/prompt-protocol.d.ts +17 -16
- package/lib/common/chat/prompt/prompt-protocol.d.ts.map +1 -1
- package/lib/common/chat/prompt/prompt-protocol.js +2 -0
- package/lib/common/chat/prompt/prompt-protocol.js.map +1 -1
- package/lib/common/chat/prompt/prompt-template.d.ts +8 -0
- package/lib/common/chat/prompt/prompt-template.d.ts.map +1 -0
- package/lib/common/chat/prompt/prompt-template.js +34 -0
- package/lib/common/chat/prompt/prompt-template.js.map +1 -0
- package/lib/common/embedding/embedding-protocol.d.ts +11 -8
- package/lib/common/embedding/embedding-protocol.d.ts.map +1 -1
- package/lib/common/embedding/embedding-protocol.js +10 -1
- package/lib/common/embedding/embedding-protocol.js.map +1 -1
- package/lib/common/error/error.d.ts +5 -0
- package/lib/common/error/error.d.ts.map +1 -0
- package/lib/common/error/error.js +11 -0
- package/lib/common/error/error.js.map +1 -0
- package/lib/common/error/index.d.ts +2 -0
- package/lib/common/error/index.d.ts.map +1 -0
- package/lib/common/error/index.js +5 -0
- package/lib/common/error/index.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/model/function/function-protocol.d.ts +2 -2
- package/lib/common/model/function/function-protocol.d.ts.map +1 -1
- package/lib/common/model/model-protocol.d.ts +2 -1
- package/lib/common/model/model-protocol.d.ts.map +1 -1
- package/lib/common/sse/index.d.ts +4 -0
- package/lib/common/sse/index.d.ts.map +1 -0
- package/lib/common/sse/index.js +7 -0
- package/lib/common/sse/index.js.map +1 -0
- package/lib/common/sse/line-decoder.d.ts +15 -0
- package/lib/common/sse/line-decoder.d.ts.map +1 -0
- package/lib/common/sse/line-decoder.js +54 -0
- package/lib/common/sse/line-decoder.js.map +1 -0
- package/lib/common/sse/sse-decoder.d.ts +27 -0
- package/lib/common/sse/sse-decoder.d.ts.map +1 -0
- package/lib/common/sse/sse-decoder.js +74 -0
- package/lib/common/sse/sse-decoder.js.map +1 -0
- package/lib/common/sse/sse-protocol.d.ts +23 -0
- package/lib/common/sse/sse-protocol.d.ts.map +1 -0
- package/lib/common/sse/sse-protocol.js +4 -0
- package/lib/common/sse/sse-protocol.js.map +1 -0
- package/lib/common/utils/index.d.ts +1 -0
- package/lib/common/utils/index.d.ts.map +1 -1
- package/lib/common/utils/index.js +1 -0
- package/lib/common/utils/index.js.map +1 -1
- package/lib/common/utils/sse-util.d.ts +10 -0
- package/lib/common/utils/sse-util.d.ts.map +1 -0
- package/lib/common/utils/sse-util.js +109 -0
- package/lib/common/utils/sse-util.js.map +1 -0
- package/package.json +5 -5
- package/src/common/chat/message/assistant-message.ts +5 -3
- package/src/common/chat/message/index.ts +1 -0
- package/src/common/chat/message/message-protocol.ts +27 -1
- package/src/common/chat/message/tool-response-message.ts +40 -0
- package/src/common/chat/metadata/chat-generation-metadata.ts +38 -0
- package/src/common/chat/metadata/index.ts +1 -0
- package/src/common/chat/metadata/metadata-protocol.ts +2 -0
- package/src/common/chat/prompt/index.ts +1 -0
- package/src/common/chat/prompt/prompt-protocol.ts +18 -28
- package/src/common/chat/prompt/prompt-template.ts +26 -0
- package/src/common/embedding/embedding-protocol.ts +17 -8
- package/src/common/error/error.ts +7 -0
- package/src/common/error/index.ts +1 -0
- package/src/common/index.ts +2 -0
- package/src/common/model/function/function-protocol.ts +2 -2
- package/src/common/model/model-protocol.ts +4 -2
- package/src/common/sse/index.ts +3 -0
- package/src/common/sse/line-decoder.ts +65 -0
- package/src/common/sse/sse-decoder.ts +88 -0
- package/src/common/sse/sse-protocol.ts +25 -0
- package/src/common/utils/index.ts +1 -0
- package/src/common/utils/sse-util.ts +111 -0
package/README.md
CHANGED
|
@@ -1 +1,108 @@
|
|
|
1
1
|
# Cell - AI Core Component
|
|
2
|
+
|
|
3
|
+
## 概览
|
|
4
|
+
|
|
5
|
+
AI Core 模块是一个用于与 AI 模型服务交互的库,提供了生成聊天响应和嵌入向量的功能。通过简单易用的 API 接口,支持消息的创建、请求的发送和响应的处理。是所有 AI 模块的基础,提供了 AI 模块通用的 API 接口。
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## 特性
|
|
9
|
+
|
|
10
|
+
- 生成聊天响应
|
|
11
|
+
- 生成嵌入向量
|
|
12
|
+
- 支持流式响应
|
|
13
|
+
- 支持多种模型参数配置
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
使用 npm 安装 AI Core 模块:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @celljs/ai-core
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
或者使用 yarn:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @celljs/ai-core
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
AI Core 模块是所有 AI 模块的基础,提供了 AI 模块通用的 API 接口,包括消息的创建、请求的发送和响应的处理。所以在使用 AI Core 模块之前,需要先安装厂商对应的模型服务适配模块。例如:`@celljs/ai-ollama`。
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @celljs/ai-ollama
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
或者使用 yarn:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
yarn add @celljs/ai-ollama
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 快速开始
|
|
42
|
+
|
|
43
|
+
以下是一个简单的示例,展示如何使用 AI Ollama 模块生成聊天响应和嵌入向量:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { AssistantMessage, PromptTemplate } from '@celljs/ai-core';
|
|
47
|
+
import { Component Autowired } from '@celljs/core';
|
|
48
|
+
|
|
49
|
+
@Component()
|
|
50
|
+
export class OllamaDemo {
|
|
51
|
+
@Autowired(OllamChatModel)
|
|
52
|
+
private chatModel: ChatModel;
|
|
53
|
+
|
|
54
|
+
@Autowired(EmbeddingModel)
|
|
55
|
+
private embeddingModel: EmbeddingModel;
|
|
56
|
+
|
|
57
|
+
@Autowired(PromptTemplate)
|
|
58
|
+
private promptTemplate: PromptTemplate;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Chat with Ollama
|
|
62
|
+
*/
|
|
63
|
+
async chat() {
|
|
64
|
+
const prompt = await this.promptTemplate.create(
|
|
65
|
+
'Hello {name}',
|
|
66
|
+
{
|
|
67
|
+
chatOptions: { model: 'llama3.2' },
|
|
68
|
+
variables: { name: 'Ollama' }
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
const response = await this.chatModel.call(prompt);
|
|
72
|
+
console.log(response.result.output);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Stream chat response
|
|
77
|
+
*/
|
|
78
|
+
async stream() {
|
|
79
|
+
const prompt = await this.promptTemplate.create(
|
|
80
|
+
'Hello {name}',
|
|
81
|
+
{
|
|
82
|
+
chatOptions: { model: 'llama3.2' },
|
|
83
|
+
variables: { name: 'Ollama' }
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
const response$ = await this.chatModel.stream(prompt);
|
|
87
|
+
response$.subscribe({
|
|
88
|
+
next: response => console.log(response.result.output),
|
|
89
|
+
complete: () => console.log('Chat completed!')
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Embed text to vector
|
|
95
|
+
*/
|
|
96
|
+
async embed() {
|
|
97
|
+
const response = await this.embeddingModel.call({
|
|
98
|
+
inputs: ['text to embed'],
|
|
99
|
+
options: { model: 'llama3.2' }
|
|
100
|
+
});
|
|
101
|
+
console.log(response.result.embeddings);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 许可证
|
|
107
|
+
|
|
108
|
+
本项目采用 MIT 许可证。
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractMessage } from './abstract-message';
|
|
2
|
-
import { Media } from './message-protocol';
|
|
2
|
+
import { Media, ToolCall } from './message-protocol';
|
|
3
3
|
export declare class AssistantMessage extends AbstractMessage {
|
|
4
4
|
readonly content: string;
|
|
5
5
|
readonly media: Media[];
|
|
6
6
|
readonly metadata: Record<string, any>;
|
|
7
|
-
|
|
7
|
+
readonly toolCalls: ToolCall[];
|
|
8
|
+
constructor(content?: string, media?: Media[], metadata?: Record<string, any>, toolCalls?: ToolCall[]);
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=assistant-message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/message/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAe,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/message/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAe,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAElE,qBAAa,gBAAiB,SAAQ,eAAe;aAG3B,OAAO,EAAE,MAAM;aACf,KAAK,EAAE,KAAK,EAAE;aACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC/C,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE;gBAHZ,OAAO,GAAE,MAAW,EACpB,KAAK,GAAE,KAAK,EAAO,EACnB,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAC3C,SAAS,GAAE,QAAQ,EAAO;CAI1C"}
|
|
@@ -4,11 +4,12 @@ exports.AssistantMessage = void 0;
|
|
|
4
4
|
const abstract_message_1 = require("./abstract-message");
|
|
5
5
|
const message_protocol_1 = require("./message-protocol");
|
|
6
6
|
class AssistantMessage extends abstract_message_1.AbstractMessage {
|
|
7
|
-
constructor(content, media = [], metadata = {}) {
|
|
7
|
+
constructor(content = '', media = [], metadata = {}, toolCalls = []) {
|
|
8
8
|
super(message_protocol_1.MessageType.ASSISTANT, content, media, metadata);
|
|
9
9
|
this.content = content;
|
|
10
10
|
this.media = media;
|
|
11
11
|
this.metadata = metadata;
|
|
12
|
+
this.toolCalls = toolCalls;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
exports.AssistantMessage = AssistantMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/common/chat/message/assistant-message.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AACrD,
|
|
1
|
+
{"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../../../src/common/chat/message/assistant-message.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AACrD,yDAAkE;AAElE,MAAa,gBAAiB,SAAQ,kCAAe;IAEjD,YACsB,UAAkB,EAAE,EACpB,QAAiB,EAAE,EACnB,WAAgC,EAAE,EAC3C,YAAwB,EAAE;QAEnC,KAAK,CAAC,8BAAW,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QALrC,YAAO,GAAP,OAAO,CAAa;QACpB,UAAK,GAAL,KAAK,CAAc;QACnB,aAAQ,GAAR,QAAQ,CAA0B;QAC3C,cAAS,GAAT,SAAS,CAAiB;IAGvC,CAAC;CACJ;AAVD,4CAUC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/message/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/message/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC"}
|
|
@@ -7,4 +7,5 @@ tslib_1.__exportStar(require("./user-message"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./system-message"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./assistant-message"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./function-message"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./tool-response-message"), exports);
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/message/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC;AACnC,yDAA+B;AAC/B,2DAAiC;AACjC,8DAAoC;AACpC,6DAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/message/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC;AACnC,yDAA+B;AAC/B,2DAAiC;AACjC,8DAAoC;AACpC,6DAAmC;AACnC,kEAAwC"}
|
|
@@ -22,7 +22,8 @@ export declare enum MessageType {
|
|
|
22
22
|
USER = "user",
|
|
23
23
|
ASSISTANT = "assistant",
|
|
24
24
|
SYSTEM = "system",
|
|
25
|
-
FUNCTION = "function"
|
|
25
|
+
FUNCTION = "function",
|
|
26
|
+
TOOL = "tool"
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* The Message interface represents a message that can be sent or received in a chat
|
|
@@ -38,4 +39,25 @@ export interface Message extends Content {
|
|
|
38
39
|
export declare namespace Message {
|
|
39
40
|
function isMessage(obj: any): obj is Message;
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Represents a tool call.
|
|
44
|
+
*/
|
|
45
|
+
export interface ToolCall {
|
|
46
|
+
/**
|
|
47
|
+
* The unique identifier for the tool call.
|
|
48
|
+
*/
|
|
49
|
+
id: string;
|
|
50
|
+
/**
|
|
51
|
+
* The type of the tool.
|
|
52
|
+
*/
|
|
53
|
+
type: string;
|
|
54
|
+
/**
|
|
55
|
+
* The name of the tool.
|
|
56
|
+
*/
|
|
57
|
+
name: string;
|
|
58
|
+
/**
|
|
59
|
+
* The arguments passed to the tool.
|
|
60
|
+
*/
|
|
61
|
+
arguments: string;
|
|
62
|
+
}
|
|
41
63
|
//# sourceMappingURL=message-protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-protocol.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/message/message-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,KAAK;IAElB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;CAEtB;AAED;;;GAGG;AACH,oBAAY,WAAW;IACnB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,QAAQ,aAAa;
|
|
1
|
+
{"version":3,"file":"message-protocol.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/message/message-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,KAAK;IAElB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;CAEtB;AAED;;;GAGG;AACH,oBAAY,WAAW;IACnB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,IAAI,SAAS;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,OAAQ,SAAQ,OAAO;IACpC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACrC;AAED,yBAAiB,OAAO,CAAC;IACrB,SAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,OAAO,CAElD;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -11,6 +11,7 @@ var MessageType;
|
|
|
11
11
|
MessageType["ASSISTANT"] = "assistant";
|
|
12
12
|
MessageType["SYSTEM"] = "system";
|
|
13
13
|
MessageType["FUNCTION"] = "function";
|
|
14
|
+
MessageType["TOOL"] = "tool";
|
|
14
15
|
})(MessageType = exports.MessageType || (exports.MessageType = {}));
|
|
15
16
|
var Message;
|
|
16
17
|
(function (Message) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-protocol.js","sourceRoot":"","sources":["../../../../src/common/chat/message/message-protocol.ts"],"names":[],"mappings":";;;AAqBA;;;GAGG;AACH,IAAY,
|
|
1
|
+
{"version":3,"file":"message-protocol.js","sourceRoot":"","sources":["../../../../src/common/chat/message/message-protocol.ts"],"names":[],"mappings":";;;AAqBA;;;GAGG;AACH,IAAY,WAMX;AAND,WAAY,WAAW;IACnB,4BAAa,CAAA;IACb,sCAAuB,CAAA;IACvB,gCAAiB,CAAA;IACjB,oCAAqB,CAAA;IACrB,4BAAa,CAAA;AACjB,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB;AAcD,IAAiB,OAAO,CAIvB;AAJD,WAAiB,OAAO;IACpB,SAAgB,SAAS,CAAC,GAAQ;QAC9B,OAAO,GAAG,IAAI,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC;IAChD,CAAC;IAFe,iBAAS,YAExB,CAAA;AACL,CAAC,EAJgB,OAAO,GAAP,eAAO,KAAP,eAAO,QAIvB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AbstractMessage } from './abstract-message';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a tool response.
|
|
4
|
+
*/
|
|
5
|
+
export interface ToolResponse {
|
|
6
|
+
/**
|
|
7
|
+
* The unique identifier for the tool.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* The name of the tool.
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* The response data from the tool.
|
|
16
|
+
*/
|
|
17
|
+
responseData: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The ToolResponseMessage class represents a message with a function content in a chat
|
|
21
|
+
* application.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ToolResponseMessage extends AbstractMessage {
|
|
24
|
+
readonly responses: ToolResponse[];
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of ToolResponseMessage.
|
|
27
|
+
* @param responses The list of tool responses.
|
|
28
|
+
* @param metadata Additional metadata.
|
|
29
|
+
*/
|
|
30
|
+
constructor(responses: ToolResponse[], metadata?: Record<string, any>);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=tool-response-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-response-message.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/message/tool-response-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,eAAe;IAQhD,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE;IANtC;;;;OAIG;gBAEU,SAAS,EAAE,YAAY,EAAE,EAAE,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;CAI7E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolResponseMessage = void 0;
|
|
4
|
+
const abstract_message_1 = require("./abstract-message");
|
|
5
|
+
const message_protocol_1 = require("./message-protocol");
|
|
6
|
+
/**
|
|
7
|
+
* The ToolResponseMessage class represents a message with a function content in a chat
|
|
8
|
+
* application.
|
|
9
|
+
*/
|
|
10
|
+
class ToolResponseMessage extends abstract_message_1.AbstractMessage {
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of ToolResponseMessage.
|
|
13
|
+
* @param responses The list of tool responses.
|
|
14
|
+
* @param metadata Additional metadata.
|
|
15
|
+
*/
|
|
16
|
+
constructor(responses, metadata = {}) {
|
|
17
|
+
super(message_protocol_1.MessageType.TOOL, '', [], metadata);
|
|
18
|
+
this.responses = responses;
|
|
19
|
+
this.responses = responses;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ToolResponseMessage = ToolResponseMessage;
|
|
23
|
+
//# sourceMappingURL=tool-response-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-response-message.js","sourceRoot":"","sources":["../../../../src/common/chat/message/tool-response-message.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AACrD,yDAAiD;AAsBjD;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,kCAAe;IAEpD;;;;OAIG;IACH,YACa,SAAyB,EAAE,WAAgC,EAAE;QACtE,KAAK,CAAC,8BAAW,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;QADjC,cAAS,GAAT,SAAS,CAAgB;QAElC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;CACJ;AAZD,kDAYC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ResultMetadata } from '../../model/model-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract Data Type (ADT) encapsulating information on the completion choices in the AI
|
|
4
|
+
* response.
|
|
5
|
+
*/
|
|
6
|
+
export interface ChatGenerationMetadata extends ResultMetadata {
|
|
7
|
+
/**
|
|
8
|
+
* The reason this choice completed for the generation.
|
|
9
|
+
*/
|
|
10
|
+
readonly contentFilterMetadata?: any;
|
|
11
|
+
/**
|
|
12
|
+
* The reason this choice completed for the generation.
|
|
13
|
+
*/
|
|
14
|
+
readonly finishReason?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class ChatGenerationMetadata {
|
|
17
|
+
static EMPTY: ChatGenerationMetadata;
|
|
18
|
+
/**
|
|
19
|
+
* Factory method used to construct a new {@link ChatGenerationMetadata} from the
|
|
20
|
+
* given finish reason and content filter metadata.
|
|
21
|
+
*
|
|
22
|
+
* @param finishReason The reason for completion.
|
|
23
|
+
* @param contentFilterMetadata The content filter metadata.
|
|
24
|
+
* @returns A new instance of {@link ChatGenerationMetadata}.
|
|
25
|
+
*/
|
|
26
|
+
static from(finishReason?: string, contentFilterMetadata?: any): ChatGenerationMetadata;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=chat-generation-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-generation-metadata.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/metadata/chat-generation-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAE1D;;OAEG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,GAAG,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAClC;AAGD,qBAAa,sBAAsB;IAE/B,MAAM,CAAC,KAAK,EAAE,sBAAsB,CAAiC;IAGrE;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,qBAAqB,CAAC,EAAE,GAAG,GAAG,sBAAsB;CAK1F"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatGenerationMetadata = void 0;
|
|
4
|
+
class ChatGenerationMetadata {
|
|
5
|
+
/**
|
|
6
|
+
* Factory method used to construct a new {@link ChatGenerationMetadata} from the
|
|
7
|
+
* given finish reason and content filter metadata.
|
|
8
|
+
*
|
|
9
|
+
* @param finishReason The reason for completion.
|
|
10
|
+
* @param contentFilterMetadata The content filter metadata.
|
|
11
|
+
* @returns A new instance of {@link ChatGenerationMetadata}.
|
|
12
|
+
*/
|
|
13
|
+
static from(finishReason, contentFilterMetadata) {
|
|
14
|
+
return {
|
|
15
|
+
finishReason, contentFilterMetadata
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ChatGenerationMetadata = ChatGenerationMetadata;
|
|
20
|
+
ChatGenerationMetadata.EMPTY = ChatGenerationMetadata.from();
|
|
21
|
+
//# sourceMappingURL=chat-generation-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-generation-metadata.js","sourceRoot":"","sources":["../../../../src/common/chat/metadata/chat-generation-metadata.ts"],"names":[],"mappings":";;;AAoBA,MAAa,sBAAsB;IAK/B;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,YAAqB,EAAE,qBAA2B;QAC1D,OAAO;YACH,YAAY,EAAE,qBAAqB;SACtC,CAAC;IACN,CAAC;;AAjBL,wDAkBC;AAhBU,4BAAK,GAA2B,sBAAsB,CAAC,IAAI,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/metadata/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/metadata/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/metadata/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/metadata/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC;AACpC,qEAA2C"}
|
|
@@ -90,6 +90,8 @@ export declare namespace PromptMetadata {
|
|
|
90
90
|
function findByPromptIndex(promptMetadata: PromptMetadata, promptIndex: number): PromptFilterMetadata | undefined;
|
|
91
91
|
}
|
|
92
92
|
export interface ChatResponseMetadata extends ResponseMetadata {
|
|
93
|
+
readonly id?: string;
|
|
94
|
+
readonly model?: string;
|
|
93
95
|
/**
|
|
94
96
|
* AI provider specific metadata on rate limits.
|
|
95
97
|
* @see RateLimit
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-protocol.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/metadata/metadata-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,KAAK;IAElB;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B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AC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEtB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CAE3C;AAED,yBAAiB,oBAAoB,CAAC;IAC3B,MAAM,KAAK,sBAeO,CAAC;CAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-protocol.js","sourceRoot":"","sources":["../../../../src/common/chat/metadata/metadata-protocol.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAqGpD,IAAiB,cAAc,CAgB9B;AAhBD,WAAiB,cAAc;IAC3B;;;;;;OAMG;IACH,SAAgB,iBAAiB,CAAC,cAA8B,EAAE,WAAmB;QAEjF,IAAI,WAAW,GAAG,CAAC,EAAE;YACjB,MAAM,IAAI,2BAAoB,CAAC,iBAAiB,WAAW,mCAAmC,CAAC,CAAC;SACnG;QAED,OAAO,cAAc,CAAC,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC,oBAAoB,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC;IACzG,CAAC;IAPe,gCAAiB,oBAOhC,CAAA;AACL,CAAC,EAhBgB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAgB9B;
|
|
1
|
+
{"version":3,"file":"metadata-protocol.js","sourceRoot":"","sources":["../../../../src/common/chat/metadata/metadata-protocol.ts"],"names":[],"mappings":";;;AAAA,uCAAoD;AAqGpD,IAAiB,cAAc,CAgB9B;AAhBD,WAAiB,cAAc;IAC3B;;;;;;OAMG;IACH,SAAgB,iBAAiB,CAAC,cAA8B,EAAE,WAAmB;QAEjF,IAAI,WAAW,GAAG,CAAC,EAAE;YACjB,MAAM,IAAI,2BAAoB,CAAC,iBAAiB,WAAW,mCAAmC,CAAC,CAAC;SACnG;QAED,OAAO,cAAc,CAAC,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAAC,oBAAoB,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC;IACzG,CAAC;IAPe,gCAAiB,oBAOhC,CAAA;AACL,CAAC,EAhBgB,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAgB9B;AAqBD,IAAiB,oBAAoB,CAiBpC;AAjBD,WAAiB,oBAAoB;IACpB,0BAAK,GAAG;QACjB,SAAS,EAAE;YACP,aAAa,EAAE,CAAC;YAChB,iBAAiB,EAAE,CAAC;YACpB,aAAa,EAAE,CAAC;YAChB,WAAW,EAAE,CAAC;YACd,eAAe,EAAE,CAAC;YAClB,WAAW,EAAE,CAAC;SACjB;QACD,KAAK,EAAE;YACH,YAAY,EAAE,CAAC;YACf,gBAAgB,EAAE,CAAC;YACnB,WAAW,EAAE,CAAC;SACjB;QACD,cAAc,EAAE,EAAoB;KACf,CAAC;AAC9B,CAAC,EAjBgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAiBpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
|
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./prompt-protocol"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./prompt"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./prompt-template"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,mDAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,mDAAyB;AACzB,4DAAkC"}
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { ModelOptions, ModelRequest } from '../../model/model-protocol';
|
|
2
|
-
import {
|
|
2
|
+
import { Message, MessageType } from '../message/message-protocol';
|
|
3
|
+
export declare const PromptTemplate: unique symbol;
|
|
3
4
|
/**
|
|
4
5
|
* The ChatOptions represent the common options, portable across different chat models.
|
|
5
6
|
*/
|
|
6
7
|
export interface ChatOptions extends ModelOptions {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
model?: string;
|
|
9
|
+
frequencyPenalty?: number;
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
presencePenalty?: number;
|
|
12
|
+
stopSequences?: string[];
|
|
13
|
+
temperature?: number;
|
|
14
|
+
topK?: number;
|
|
15
|
+
topP?: number;
|
|
10
16
|
}
|
|
11
17
|
export interface Prompt extends ModelRequest<Message[]> {
|
|
12
18
|
readonly contents: string;
|
|
13
19
|
copy(): Prompt;
|
|
14
20
|
}
|
|
15
|
-
export interface
|
|
16
|
-
|
|
21
|
+
export interface PromptTemplateContext {
|
|
22
|
+
variables?: Record<string, any>;
|
|
23
|
+
chatOptions?: ChatOptions;
|
|
24
|
+
messageType?: MessageType;
|
|
17
25
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
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;
|
|
26
|
+
export interface PromptTemplate {
|
|
27
|
+
render(template: string, ctx?: PromptTemplateContext): Promise<string>;
|
|
28
|
+
create(template: string, ctx?: PromptTemplateContext): Promise<Prompt>;
|
|
28
29
|
}
|
|
29
30
|
//# sourceMappingURL=prompt-protocol.d.ts.map
|
|
@@ -1 +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,
|
|
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,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAEnE,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;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,qBAAqB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC3B,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-protocol.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-protocol.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"prompt-protocol.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-protocol.ts"],"names":[],"mappings":";;;AAGa,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExpressionHandler } from '@celljs/core';
|
|
2
|
+
import { Prompt, PromptTemplate, PromptTemplateContext } from './prompt-protocol';
|
|
3
|
+
export declare class PromptTemplateImpl implements PromptTemplate {
|
|
4
|
+
protected readonly expressionHandler: ExpressionHandler;
|
|
5
|
+
render(template: string, ctx?: PromptTemplateContext): Promise<string>;
|
|
6
|
+
create(template: string, ctx?: PromptTemplateContext): Promise<Prompt>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=prompt-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-template.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,iBAAiB,EAAwB,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAIlF,qBACa,kBAAmB,YAAW,cAAc;IAGrD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAElD,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;IAMtE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAQ/E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromptTemplateImpl = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@celljs/core");
|
|
6
|
+
const prompt_protocol_1 = require("./prompt-protocol");
|
|
7
|
+
const prompt_1 = require("./prompt");
|
|
8
|
+
const message_1 = require("../message");
|
|
9
|
+
let PromptTemplateImpl = class PromptTemplateImpl {
|
|
10
|
+
async render(template, ctx) {
|
|
11
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.variables) {
|
|
12
|
+
return this.expressionHandler.handle(template, ctx, { ignoreSpecialChar: true, bracketBegin: '{', bracketEnd: '}' });
|
|
13
|
+
}
|
|
14
|
+
return template;
|
|
15
|
+
}
|
|
16
|
+
async create(template, ctx) {
|
|
17
|
+
if (!(ctx === null || ctx === void 0 ? void 0 : ctx.messageType) || (ctx === null || ctx === void 0 ? void 0 : ctx.messageType) === message_1.MessageType.USER) {
|
|
18
|
+
return new prompt_1.PromptImpl(await this.render(template, ctx), ctx === null || ctx === void 0 ? void 0 : ctx.chatOptions);
|
|
19
|
+
}
|
|
20
|
+
else if ((ctx === null || ctx === void 0 ? void 0 : ctx.messageType) === message_1.MessageType.SYSTEM) {
|
|
21
|
+
return new prompt_1.PromptImpl(new message_1.SystemMessage(await this.render(template, ctx)), ctx === null || ctx === void 0 ? void 0 : ctx.chatOptions);
|
|
22
|
+
}
|
|
23
|
+
throw new core_1.IllegalArgumentError(`Invalid message type: ${ctx === null || ctx === void 0 ? void 0 : ctx.messageType}`);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
tslib_1.__decorate([
|
|
27
|
+
(0, core_1.Autowired)(core_1.ExpressionHandler),
|
|
28
|
+
tslib_1.__metadata("design:type", Object)
|
|
29
|
+
], PromptTemplateImpl.prototype, "expressionHandler", void 0);
|
|
30
|
+
PromptTemplateImpl = tslib_1.__decorate([
|
|
31
|
+
(0, core_1.Component)(prompt_protocol_1.PromptTemplate)
|
|
32
|
+
], PromptTemplateImpl);
|
|
33
|
+
exports.PromptTemplateImpl = PromptTemplateImpl;
|
|
34
|
+
//# sourceMappingURL=prompt-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-template.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-template.ts"],"names":[],"mappings":";;;;AAAA,uCAA6F;AAC7F,uDAAkF;AAClF,qCAAsC;AACtC,wCAAwD;AAGjD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAK3B,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,GAA2B;QACtD,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,EAAE;YAChB,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;SACxH;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,GAA2B;QACtD,IAAI,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAA,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,MAAK,qBAAW,CAAC,IAAI,EAAE;YAC5D,OAAO,IAAI,mBAAU,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,CAAC;SAC7E;aAAM,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,MAAK,qBAAW,CAAC,MAAM,EAAE;YAChD,OAAO,IAAI,mBAAU,CAAC,IAAI,uBAAa,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,CAAC;SAChG;QACD,MAAM,IAAI,2BAAoB,CAAC,yBAAyB,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,CAAC;IAChF,CAAC;CACJ,CAAA;AAjBG;IAAC,IAAA,gBAAS,EAAC,wBAAiB,CAAC;;6DAC2B;AAH/C,kBAAkB;IAD9B,IAAA,gBAAS,EAAC,gCAAc,CAAC;GACb,kBAAkB,CAmB9B;AAnBY,gDAAkB"}
|
|
@@ -2,6 +2,15 @@ import { MimeType } from '@celljs/core';
|
|
|
2
2
|
import { Usage } from '../chat/metadata/metadata-protocol';
|
|
3
3
|
import { Model, ModelOptions, ModelRequest, ModelResponse, ModelResult, ResponseMetadata, ResultMetadata } from '../model/model-protocol';
|
|
4
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
|
+
}
|
|
5
14
|
/**
|
|
6
15
|
* Represents the metadata for an embedding result.
|
|
7
16
|
*/
|
|
@@ -23,14 +32,8 @@ export interface EmbeddingResultMetadata extends ResultMetadata {
|
|
|
23
32
|
*/
|
|
24
33
|
documentData: any;
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
export declare enum ModalityType {
|
|
30
|
-
TEXT = "TEXT",
|
|
31
|
-
IMAGE = "IMAGE",
|
|
32
|
-
AUDIO = "AUDIO",
|
|
33
|
-
VIDEO = "VIDEO"
|
|
35
|
+
export declare namespace EmbeddingResultMetadata {
|
|
36
|
+
const EMPTY: EmbeddingResultMetadata;
|
|
34
37
|
}
|
|
35
38
|
/**
|
|
36
39
|
* Utility class for modality-related operations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedding-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/embedding/embedding-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAiB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE1I,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC3D;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC;CACrB;AAED
|
|
1
|
+
{"version":3,"file":"embedding-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/embedding/embedding-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAiB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,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AE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAiB,SAAQ,YAAY,CAAC,MAAM,EAAE,CAAC;IAC5D;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,aAAa,CAAC,SAAS,CAAC;IAC/D;;OAEG;IACH,UAAU,EAAE,SAAS,EAAE,CAAC;IAExB;;OAEG;IACH,QAAQ,EAAE,yBAAyB,CAAC;CACvC;AAED,MAAM,WAAW,cAAe,SAAQ,KAAK,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;CAAG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModalityUtils = exports.ModalityType = exports.EmbeddingModel = void 0;
|
|
3
|
+
exports.ModalityUtils = exports.EmbeddingResultMetadata = exports.ModalityType = exports.EmbeddingModel = void 0;
|
|
4
4
|
const core_1 = require("@celljs/core");
|
|
5
5
|
exports.EmbeddingModel = Symbol('EmbeddingModel');
|
|
6
6
|
/**
|
|
@@ -13,6 +13,15 @@ var ModalityType;
|
|
|
13
13
|
ModalityType["AUDIO"] = "AUDIO";
|
|
14
14
|
ModalityType["VIDEO"] = "VIDEO";
|
|
15
15
|
})(ModalityType = exports.ModalityType || (exports.ModalityType = {}));
|
|
16
|
+
var EmbeddingResultMetadata;
|
|
17
|
+
(function (EmbeddingResultMetadata) {
|
|
18
|
+
EmbeddingResultMetadata.EMPTY = {
|
|
19
|
+
modalityType: ModalityType.TEXT,
|
|
20
|
+
documentId: '',
|
|
21
|
+
mimeType: core_1.MimeTypeUtils.TEXT_PLAIN,
|
|
22
|
+
documentData: undefined
|
|
23
|
+
};
|
|
24
|
+
})(EmbeddingResultMetadata = exports.EmbeddingResultMetadata || (exports.EmbeddingResultMetadata = {}));
|
|
16
25
|
/**
|
|
17
26
|
* Utility class for modality-related operations.
|
|
18
27
|
*/
|