@celljs/ai-core 3.5.6 → 3.5.7
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/lib/common/chat/prompt/el-prompt-template.d.ts +9 -0
- package/lib/common/chat/prompt/el-prompt-template.d.ts.map +1 -0
- package/lib/common/chat/prompt/el-prompt-template.js +43 -0
- package/lib/common/chat/prompt/el-prompt-template.js.map +1 -0
- 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-template.d.ts +1 -3
- package/lib/common/chat/prompt/prompt-template.d.ts.map +1 -1
- package/lib/common/chat/prompt/prompt-template.js +10 -11
- package/lib/common/chat/prompt/prompt-template.js.map +1 -1
- package/package.json +5 -5
- package/src/common/chat/prompt/el-prompt-template.ts +35 -0
- package/src/common/chat/prompt/index.ts +1 -0
- package/src/common/chat/prompt/prompt-template.ts +7 -7
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExpressionHandler } from '@celljs/core';
|
|
2
|
+
import { Prompt, PromptTemplate, PromptTemplateContext } from './prompt-protocol';
|
|
3
|
+
import { Message } from '../message';
|
|
4
|
+
export declare class ELPromptTemplate implements PromptTemplate {
|
|
5
|
+
protected readonly expressionHandler: ExpressionHandler;
|
|
6
|
+
render(template: string, ctx?: PromptTemplateContext): Promise<string>;
|
|
7
|
+
create(template: string | Message[], ctx?: PromptTemplateContext): Promise<Prompt>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=el-prompt-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"el-prompt-template.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/el-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;AAElF,OAAO,EAAE,OAAO,EAA8B,MAAM,YAAY,CAAC;AAEjE,qBACa,gBAAiB,YAAW,cAAc;IAGnD,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,GAAG,OAAO,EAAE,EAAE,GAAG,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAiB3F"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var ELPromptTemplate_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ELPromptTemplate = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const core_1 = require("@celljs/core");
|
|
7
|
+
const prompt_1 = require("./prompt");
|
|
8
|
+
const message_1 = require("../message");
|
|
9
|
+
let ELPromptTemplate = ELPromptTemplate_1 = class ELPromptTemplate {
|
|
10
|
+
async render(template, ctx) {
|
|
11
|
+
if (ctx === null || ctx === void 0 ? void 0 : ctx.variables) {
|
|
12
|
+
return this.expressionHandler.handle(template, ctx.variables, { ignoreSpecialChar: true, bracketBegin: '{', bracketEnd: '}', ignoreContextExpression: true });
|
|
13
|
+
}
|
|
14
|
+
return template;
|
|
15
|
+
}
|
|
16
|
+
async create(template, ctx) {
|
|
17
|
+
if (Array.isArray(template)
|
|
18
|
+
&& template.some(message => message_1.Message.isMessage(message))) {
|
|
19
|
+
for (const message of template) {
|
|
20
|
+
message.content = await this.render(message.content, ctx);
|
|
21
|
+
}
|
|
22
|
+
return new prompt_1.PromptImpl(template, ctx === null || ctx === void 0 ? void 0 : ctx.chatOptions);
|
|
23
|
+
}
|
|
24
|
+
else if (typeof template === 'string') {
|
|
25
|
+
if (!(ctx === null || ctx === void 0 ? void 0 : ctx.messageType) || (ctx === null || ctx === void 0 ? void 0 : ctx.messageType) === message_1.MessageType.USER) {
|
|
26
|
+
return new prompt_1.PromptImpl(await this.render(template, ctx), ctx === null || ctx === void 0 ? void 0 : ctx.chatOptions);
|
|
27
|
+
}
|
|
28
|
+
else if ((ctx === null || ctx === void 0 ? void 0 : ctx.messageType) === message_1.MessageType.SYSTEM) {
|
|
29
|
+
return new prompt_1.PromptImpl(new message_1.SystemMessage(await this.render(template, ctx)), ctx === null || ctx === void 0 ? void 0 : ctx.chatOptions);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
throw new core_1.IllegalArgumentError(`Invalid message type: ${ctx === null || ctx === void 0 ? void 0 : ctx.messageType}`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
tslib_1.__decorate([
|
|
36
|
+
(0, core_1.Autowired)(core_1.ExpressionHandler),
|
|
37
|
+
tslib_1.__metadata("design:type", Object)
|
|
38
|
+
], ELPromptTemplate.prototype, "expressionHandler", void 0);
|
|
39
|
+
ELPromptTemplate = ELPromptTemplate_1 = tslib_1.__decorate([
|
|
40
|
+
(0, core_1.Component)(ELPromptTemplate_1)
|
|
41
|
+
], ELPromptTemplate);
|
|
42
|
+
exports.ELPromptTemplate = ELPromptTemplate;
|
|
43
|
+
//# sourceMappingURL=el-prompt-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"el-prompt-template.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/el-prompt-template.ts"],"names":[],"mappings":";;;;;AAAA,uCAA6F;AAE7F,qCAAsC;AACtC,wCAAiE;AAG1D,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAKzB,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,GAA2B;QACtD,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,EAAE;YAChB,OAAO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CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,CAAC;aAChG;SACJ;QACD,MAAM,IAAI,2BAAoB,CAAC,yBAAyB,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,CAAC;IAChF,CAAC;CACJ,CAAA;AA1BG;IAAC,IAAA,gBAAS,EAAC,wBAAiB,CAAC;;2DAC2B;AAH/C,gBAAgB;IAD5B,IAAA,gBAAS,EAAC,kBAAgB,CAAC;GACf,gBAAgB,CA4B5B;AA5BY,4CAAgB"}
|
|
@@ -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;AACzB,cAAc,mBAAmB,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;AAClC,cAAc,sBAAsB,CAAC"}
|
|
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./prompt-protocol"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./prompt"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./prompt-template"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./el-prompt-template"), exports);
|
|
7
8
|
//# 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;AACzB,4DAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,mDAAyB;AACzB,4DAAkC;AAClC,+DAAqC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ExpressionHandler } from '@celljs/core';
|
|
2
1
|
import { Prompt, PromptTemplate, PromptTemplateContext } from './prompt-protocol';
|
|
3
2
|
import { Message } from '../message';
|
|
4
|
-
export declare class
|
|
5
|
-
protected readonly expressionHandler: ExpressionHandler;
|
|
3
|
+
export declare class SamplePromptTemplate implements PromptTemplate {
|
|
6
4
|
render(template: string, ctx?: PromptTemplateContext): Promise<string>;
|
|
7
5
|
create(template: string | Message[], ctx?: PromptTemplateContext): Promise<Prompt>;
|
|
8
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-template.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt-template.d.ts","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-template.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAElF,OAAO,EAAE,OAAO,EAA8B,MAAM,YAAY,CAAC;AAEjE,qBACa,oBAAqB,YAAW,cAAc;IAEjD,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;IAStE,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE,EAAE,GAAG,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAiB3F"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SamplePromptTemplate = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@celljs/core");
|
|
6
6
|
const prompt_protocol_1 = require("./prompt-protocol");
|
|
7
7
|
const prompt_1 = require("./prompt");
|
|
8
8
|
const message_1 = require("../message");
|
|
9
|
-
let
|
|
9
|
+
let SamplePromptTemplate = class SamplePromptTemplate {
|
|
10
10
|
async render(template, ctx) {
|
|
11
|
+
let newTemplate = template;
|
|
11
12
|
if (ctx === null || ctx === void 0 ? void 0 : ctx.variables) {
|
|
12
|
-
|
|
13
|
+
for (const key of Object.keys(ctx.variables)) {
|
|
14
|
+
newTemplate = newTemplate.replace(new RegExp(`{${key}}`, 'g'), ctx.variables[key]);
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
|
-
return
|
|
17
|
+
return newTemplate;
|
|
15
18
|
}
|
|
16
19
|
async create(template, ctx) {
|
|
17
20
|
if (Array.isArray(template)
|
|
@@ -32,12 +35,8 @@ let PromptTemplateImpl = class PromptTemplateImpl {
|
|
|
32
35
|
throw new core_1.IllegalArgumentError(`Invalid message type: ${ctx === null || ctx === void 0 ? void 0 : ctx.messageType}`);
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
|
-
tslib_1.__decorate([
|
|
36
|
-
(0, core_1.Autowired)(core_1.ExpressionHandler),
|
|
37
|
-
tslib_1.__metadata("design:type", Object)
|
|
38
|
-
], PromptTemplateImpl.prototype, "expressionHandler", void 0);
|
|
39
|
-
PromptTemplateImpl = tslib_1.__decorate([
|
|
38
|
+
SamplePromptTemplate = tslib_1.__decorate([
|
|
40
39
|
(0, core_1.Component)(prompt_protocol_1.PromptTemplate)
|
|
41
|
-
],
|
|
42
|
-
exports.
|
|
40
|
+
], SamplePromptTemplate);
|
|
41
|
+
exports.SamplePromptTemplate = SamplePromptTemplate;
|
|
43
42
|
//# sourceMappingURL=prompt-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-template.js","sourceRoot":"","sources":["../../../../src/common/chat/prompt/prompt-template.ts"],"names":[],"mappings":";;;;AAAA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G,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,MAAK,qBAAW,CAAC,IAAI,EAAE;gBAC5D,OAAO,IAAI,mBAAU,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,CAAC;aAC7E;iBAAM,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,MAAK,qBAAW,CAAC,MAAM,EAAE;gBAChD,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;aAChG;SACJ;QACD,MAAM,IAAI,2BAAoB,CAAC,yBAAyB,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,EAAE,CAAC,CAAC;IAChF,CAAC;CACJ,CAAA;AA5BY,oBAAoB;IADhC,IAAA,gBAAS,EAAC,gCAAc,CAAC;GACb,oBAAoB,CA4BhC;AA5BY,oDAAoB"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ai-core",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.7",
|
|
4
4
|
"description": "Core domain for AI programming",
|
|
5
5
|
"main": "lib/common/index.js",
|
|
6
6
|
"typings": "lib/common/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@celljs/core": "3.5.
|
|
9
|
-
"@celljs/http": "3.5.
|
|
8
|
+
"@celljs/core": "3.5.7",
|
|
9
|
+
"@celljs/http": "3.5.7",
|
|
10
10
|
"rxjs": "^6.6.0",
|
|
11
11
|
"tslib": "^2.8.0"
|
|
12
12
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test": "cell-component test:js"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@celljs/component": "3.5.
|
|
41
|
+
"@celljs/component": "3.5.7"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9ca650780b716b38272e6507ffb6fe49f79084ab"
|
|
44
44
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Autowired, Component, ExpressionHandler, IllegalArgumentError } from '@celljs/core';
|
|
2
|
+
import { Prompt, PromptTemplate, PromptTemplateContext } from './prompt-protocol';
|
|
3
|
+
import { PromptImpl } from './prompt';
|
|
4
|
+
import { Message, MessageType, SystemMessage } from '../message';
|
|
5
|
+
|
|
6
|
+
@Component(ELPromptTemplate)
|
|
7
|
+
export class ELPromptTemplate implements PromptTemplate {
|
|
8
|
+
|
|
9
|
+
@Autowired(ExpressionHandler)
|
|
10
|
+
protected readonly expressionHandler: ExpressionHandler;
|
|
11
|
+
|
|
12
|
+
async render(template: string, ctx?: PromptTemplateContext): Promise<string> {
|
|
13
|
+
if (ctx?.variables) {
|
|
14
|
+
return this.expressionHandler.handle(template, ctx.variables, { ignoreSpecialChar: true, bracketBegin: '{', bracketEnd: '}', ignoreContextExpression: true });
|
|
15
|
+
}
|
|
16
|
+
return template;
|
|
17
|
+
}
|
|
18
|
+
async create(template: string | Message[], ctx?: PromptTemplateContext): Promise<Prompt> {
|
|
19
|
+
if (Array.isArray(template)
|
|
20
|
+
&& template.some(message => Message.isMessage(message))
|
|
21
|
+
) {
|
|
22
|
+
for (const message of template) {
|
|
23
|
+
message.content = await this.render(message.content, ctx);
|
|
24
|
+
}
|
|
25
|
+
return new PromptImpl(template, ctx?.chatOptions);
|
|
26
|
+
} else if (typeof template === 'string') {
|
|
27
|
+
if (!ctx?.messageType || ctx?.messageType === MessageType.USER) {
|
|
28
|
+
return new PromptImpl(await this.render(template, ctx), ctx?.chatOptions);
|
|
29
|
+
} else if (ctx?.messageType === MessageType.SYSTEM) {
|
|
30
|
+
return new PromptImpl(new SystemMessage(await this.render(template, ctx)), ctx?.chatOptions);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new IllegalArgumentError(`Invalid message type: ${ctx?.messageType}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Component, IllegalArgumentError } from '@celljs/core';
|
|
2
2
|
import { Prompt, PromptTemplate, PromptTemplateContext } from './prompt-protocol';
|
|
3
3
|
import { PromptImpl } from './prompt';
|
|
4
4
|
import { Message, MessageType, SystemMessage } from '../message';
|
|
5
5
|
|
|
6
6
|
@Component(PromptTemplate)
|
|
7
|
-
export class
|
|
8
|
-
|
|
9
|
-
@Autowired(ExpressionHandler)
|
|
10
|
-
protected readonly expressionHandler: ExpressionHandler;
|
|
7
|
+
export class SamplePromptTemplate implements PromptTemplate {
|
|
11
8
|
|
|
12
9
|
async render(template: string, ctx?: PromptTemplateContext): Promise<string> {
|
|
10
|
+
let newTemplate = template;
|
|
13
11
|
if (ctx?.variables) {
|
|
14
|
-
|
|
12
|
+
for (const key of Object.keys(ctx.variables)) {
|
|
13
|
+
newTemplate = newTemplate.replace(new RegExp(`{${key}}`, 'g'), ctx.variables[key]);
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return newTemplate;
|
|
17
17
|
}
|
|
18
18
|
async create(template: string | Message[], ctx?: PromptTemplateContext): Promise<Prompt> {
|
|
19
19
|
if (Array.isArray(template)
|