@digipair/skill-llm 0.8.37 → 0.8.40
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/chat.cjs.js +310 -21
- package/chat.esm.js +308 -19
- package/index.cjs2.js +45144 -21071
- package/index.esm2.js +45144 -21071
- package/package.json +1 -1
package/chat.esm.js
CHANGED
@@ -1,4 +1,144 @@
|
|
1
|
-
import { c as checkValidTemplate,
|
1
|
+
import { a as BaseMessage, c as checkValidTemplate, b as BasePromptTemplate, I as ImagePromptValue, P as PromptTemplate, H as HumanMessage, S as SystemMessage, i as isBaseMessage, d as coerceMessageLikeToMessage, C as ChatPromptValue, p as parseMustache, e as parseFString, B as BaseStringPromptTemplate, A as AIMessage, R as Runnable } from './index.esm2.js';
|
2
|
+
|
3
|
+
function _assert_this_initialized$2(self) {
|
4
|
+
if (self === void 0) {
|
5
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
6
|
+
}
|
7
|
+
return self;
|
8
|
+
}
|
9
|
+
function _class_call_check$2(instance, Constructor) {
|
10
|
+
if (!(instance instanceof Constructor)) {
|
11
|
+
throw new TypeError("Cannot call a class as a function");
|
12
|
+
}
|
13
|
+
}
|
14
|
+
function _defineProperties$2(target, props) {
|
15
|
+
for(var i = 0; i < props.length; i++){
|
16
|
+
var descriptor = props[i];
|
17
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
18
|
+
descriptor.configurable = true;
|
19
|
+
if ("value" in descriptor) descriptor.writable = true;
|
20
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
24
|
+
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
25
|
+
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
26
|
+
return Constructor;
|
27
|
+
}
|
28
|
+
function _get_prototype_of$2(o) {
|
29
|
+
_get_prototype_of$2 = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
30
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
31
|
+
};
|
32
|
+
return _get_prototype_of$2(o);
|
33
|
+
}
|
34
|
+
function _inherits$2(subClass, superClass) {
|
35
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
36
|
+
throw new TypeError("Super expression must either be null or a function");
|
37
|
+
}
|
38
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
39
|
+
constructor: {
|
40
|
+
value: subClass,
|
41
|
+
writable: true,
|
42
|
+
configurable: true
|
43
|
+
}
|
44
|
+
});
|
45
|
+
if (superClass) _set_prototype_of$2(subClass, superClass);
|
46
|
+
}
|
47
|
+
function _possible_constructor_return$2(self, call) {
|
48
|
+
if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
|
49
|
+
return call;
|
50
|
+
}
|
51
|
+
return _assert_this_initialized$2(self);
|
52
|
+
}
|
53
|
+
function _set_prototype_of$2(o, p) {
|
54
|
+
_set_prototype_of$2 = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
55
|
+
o.__proto__ = p;
|
56
|
+
return o;
|
57
|
+
};
|
58
|
+
return _set_prototype_of$2(o, p);
|
59
|
+
}
|
60
|
+
function _type_of$2(obj) {
|
61
|
+
"@swc/helpers - typeof";
|
62
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
63
|
+
}
|
64
|
+
function _is_native_reflect_construct$2() {
|
65
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
66
|
+
if (Reflect.construct.sham) return false;
|
67
|
+
if (typeof Proxy === "function") return true;
|
68
|
+
try {
|
69
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
70
|
+
return true;
|
71
|
+
} catch (e) {
|
72
|
+
return false;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
function _create_super$2(Derived) {
|
76
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct$2();
|
77
|
+
return function _createSuperInternal() {
|
78
|
+
var Super = _get_prototype_of$2(Derived), result;
|
79
|
+
if (hasNativeReflectConstruct) {
|
80
|
+
var NewTarget = _get_prototype_of$2(this).constructor;
|
81
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
82
|
+
} else {
|
83
|
+
result = Super.apply(this, arguments);
|
84
|
+
}
|
85
|
+
return _possible_constructor_return$2(this, result);
|
86
|
+
};
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Represents a chat message in a conversation.
|
90
|
+
*/ var ChatMessage = /*#__PURE__*/ function(BaseMessage) {
|
91
|
+
_inherits$2(ChatMessage, BaseMessage);
|
92
|
+
var _super = _create_super$2(ChatMessage);
|
93
|
+
function ChatMessage(fields, role) {
|
94
|
+
_class_call_check$2(this, ChatMessage);
|
95
|
+
var _this;
|
96
|
+
if (typeof fields === "string") {
|
97
|
+
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
|
98
|
+
fields = {
|
99
|
+
content: fields,
|
100
|
+
role: role
|
101
|
+
};
|
102
|
+
}
|
103
|
+
_this = _super.call(this, fields);
|
104
|
+
Object.defineProperty(_assert_this_initialized$2(_this), "role", {
|
105
|
+
enumerable: true,
|
106
|
+
configurable: true,
|
107
|
+
writable: true,
|
108
|
+
value: void 0
|
109
|
+
});
|
110
|
+
_this.role = fields.role;
|
111
|
+
return _this;
|
112
|
+
}
|
113
|
+
_create_class$2(ChatMessage, [
|
114
|
+
{
|
115
|
+
key: "_getType",
|
116
|
+
value: function _getType() {
|
117
|
+
return "generic";
|
118
|
+
}
|
119
|
+
}
|
120
|
+
], [
|
121
|
+
{
|
122
|
+
key: "lc_name",
|
123
|
+
value: function lc_name() {
|
124
|
+
return "ChatMessage";
|
125
|
+
}
|
126
|
+
},
|
127
|
+
{
|
128
|
+
key: "_chatMessageClass",
|
129
|
+
value: function _chatMessageClass() {
|
130
|
+
return ChatMessage;
|
131
|
+
}
|
132
|
+
},
|
133
|
+
{
|
134
|
+
key: "isInstance",
|
135
|
+
value: function isInstance(message) {
|
136
|
+
return message._getType() === "generic";
|
137
|
+
}
|
138
|
+
}
|
139
|
+
]);
|
140
|
+
return ChatMessage;
|
141
|
+
}(BaseMessage);
|
2
142
|
|
3
143
|
function _array_like_to_array$1(arr, len) {
|
4
144
|
if (len == null || len > arr.length) len = arr.length;
|
@@ -866,6 +1006,101 @@ function _ts_values(o) {
|
|
866
1006
|
]);
|
867
1007
|
return BaseMessagePromptTemplate;
|
868
1008
|
}(Runnable);
|
1009
|
+
/**
|
1010
|
+
* Class that represents a placeholder for messages in a chat prompt. It
|
1011
|
+
* extends the BaseMessagePromptTemplate.
|
1012
|
+
*/ var MessagesPlaceholder = /*#__PURE__*/ function(BaseMessagePromptTemplate) {
|
1013
|
+
_inherits(MessagesPlaceholder, BaseMessagePromptTemplate);
|
1014
|
+
var _super = _create_super(MessagesPlaceholder);
|
1015
|
+
function MessagesPlaceholder(fields) {
|
1016
|
+
_class_call_check(this, MessagesPlaceholder);
|
1017
|
+
var _this;
|
1018
|
+
if (typeof fields === "string") {
|
1019
|
+
// eslint-disable-next-line no-param-reassign
|
1020
|
+
fields = {
|
1021
|
+
variableName: fields
|
1022
|
+
};
|
1023
|
+
}
|
1024
|
+
_this = _super.call(this, fields);
|
1025
|
+
Object.defineProperty(_assert_this_initialized(_this), "variableName", {
|
1026
|
+
enumerable: true,
|
1027
|
+
configurable: true,
|
1028
|
+
writable: true,
|
1029
|
+
value: void 0
|
1030
|
+
});
|
1031
|
+
Object.defineProperty(_assert_this_initialized(_this), "optional", {
|
1032
|
+
enumerable: true,
|
1033
|
+
configurable: true,
|
1034
|
+
writable: true,
|
1035
|
+
value: void 0
|
1036
|
+
});
|
1037
|
+
_this.variableName = fields.variableName;
|
1038
|
+
var _fields_optional;
|
1039
|
+
_this.optional = (_fields_optional = fields.optional) !== null && _fields_optional !== void 0 ? _fields_optional : false;
|
1040
|
+
return _this;
|
1041
|
+
}
|
1042
|
+
_create_class(MessagesPlaceholder, [
|
1043
|
+
{
|
1044
|
+
key: "inputVariables",
|
1045
|
+
get: function get() {
|
1046
|
+
return [
|
1047
|
+
this.variableName
|
1048
|
+
];
|
1049
|
+
}
|
1050
|
+
},
|
1051
|
+
{
|
1052
|
+
key: "validateInputOrThrow",
|
1053
|
+
value: function validateInputOrThrow(input, variableName) {
|
1054
|
+
if (this.optional && !input) {
|
1055
|
+
return false;
|
1056
|
+
} else if (!input) {
|
1057
|
+
var error = new Error('Error: Field "'.concat(variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: undefined'));
|
1058
|
+
error.name = "InputFormatError";
|
1059
|
+
throw error;
|
1060
|
+
}
|
1061
|
+
var isInputBaseMessage = false;
|
1062
|
+
if (Array.isArray(input)) {
|
1063
|
+
isInputBaseMessage = input.every(function(message) {
|
1064
|
+
return isBaseMessage(message);
|
1065
|
+
});
|
1066
|
+
} else {
|
1067
|
+
isInputBaseMessage = isBaseMessage(input);
|
1068
|
+
}
|
1069
|
+
if (!isInputBaseMessage) {
|
1070
|
+
var readableInput = typeof input === "string" ? input : JSON.stringify(input, null, 2);
|
1071
|
+
var error1 = new Error('Error: Field "'.concat(variableName, '" in prompt uses a MessagesPlaceholder, which expects an array of BaseMessages as an input value. Received: ').concat(readableInput));
|
1072
|
+
error1.name = "InputFormatError";
|
1073
|
+
throw error1;
|
1074
|
+
}
|
1075
|
+
return true;
|
1076
|
+
}
|
1077
|
+
},
|
1078
|
+
{
|
1079
|
+
key: "formatMessages",
|
1080
|
+
value: function formatMessages(values) {
|
1081
|
+
var _this = this;
|
1082
|
+
return _async_to_generator(function() {
|
1083
|
+
var _values_this_variableName;
|
1084
|
+
return _ts_generator(this, function(_state) {
|
1085
|
+
_this.validateInputOrThrow(values[_this.variableName], _this.variableName);
|
1086
|
+
return [
|
1087
|
+
2,
|
1088
|
+
(_values_this_variableName = values[_this.variableName]) !== null && _values_this_variableName !== void 0 ? _values_this_variableName : []
|
1089
|
+
];
|
1090
|
+
});
|
1091
|
+
})();
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
], [
|
1095
|
+
{
|
1096
|
+
key: "lc_name",
|
1097
|
+
value: function lc_name() {
|
1098
|
+
return "MessagesPlaceholder";
|
1099
|
+
}
|
1100
|
+
}
|
1101
|
+
]);
|
1102
|
+
return MessagesPlaceholder;
|
1103
|
+
}(BaseMessagePromptTemplate);
|
869
1104
|
/**
|
870
1105
|
* Abstract class that serves as a base for creating message string prompt
|
871
1106
|
* templates. It extends the BaseMessagePromptTemplate.
|
@@ -1049,8 +1284,10 @@ function _ts_values(o) {
|
|
1049
1284
|
},
|
1050
1285
|
{
|
1051
1286
|
key: "fromTemplate",
|
1052
|
-
value: function fromTemplate(template, role) {
|
1053
|
-
return new this(PromptTemplate.fromTemplate(template
|
1287
|
+
value: function fromTemplate(template, role, options) {
|
1288
|
+
return new this(PromptTemplate.fromTemplate(template, {
|
1289
|
+
templateFormat: options === null || options === void 0 ? void 0 : options.templateFormat
|
1290
|
+
}), role);
|
1054
1291
|
}
|
1055
1292
|
}
|
1056
1293
|
]);
|
@@ -1358,7 +1595,7 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
|
|
1358
1595
|
key: "fromTemplate",
|
1359
1596
|
value: function fromTemplate(template, additionalOptions) {
|
1360
1597
|
if (typeof template === "string") {
|
1361
|
-
return new this(PromptTemplate.fromTemplate(template));
|
1598
|
+
return new this(PromptTemplate.fromTemplate(template, additionalOptions));
|
1362
1599
|
}
|
1363
1600
|
var prompt = [];
|
1364
1601
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
@@ -1373,14 +1610,19 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
|
|
1373
1610
|
var _item_text;
|
1374
1611
|
text = (_item_text = item.text) !== null && _item_text !== void 0 ? _item_text : "";
|
1375
1612
|
}
|
1376
|
-
prompt.push(PromptTemplate.fromTemplate(text));
|
1613
|
+
prompt.push(PromptTemplate.fromTemplate(text, additionalOptions));
|
1377
1614
|
} else if (typeof item === "object" && "image_url" in item) {
|
1378
1615
|
var _item_image_url;
|
1379
1616
|
var imgTemplate = (_item_image_url = item.image_url) !== null && _item_image_url !== void 0 ? _item_image_url : "";
|
1380
1617
|
var imgTemplateObject = void 0;
|
1381
1618
|
var inputVariables = [];
|
1382
1619
|
if (typeof imgTemplate === "string") {
|
1383
|
-
var parsedTemplate =
|
1620
|
+
var parsedTemplate = void 0;
|
1621
|
+
if ((additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat) === "mustache") {
|
1622
|
+
parsedTemplate = parseMustache(imgTemplate);
|
1623
|
+
} else {
|
1624
|
+
parsedTemplate = parseFString(imgTemplate);
|
1625
|
+
}
|
1384
1626
|
var variables = parsedTemplate.flatMap(function(item) {
|
1385
1627
|
return item.type === "variable" ? [
|
1386
1628
|
item.name
|
@@ -1406,7 +1648,12 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
|
|
1406
1648
|
});
|
1407
1649
|
} else if (typeof imgTemplate === "object") {
|
1408
1650
|
if ("url" in imgTemplate) {
|
1409
|
-
var parsedTemplate1 =
|
1651
|
+
var parsedTemplate1 = void 0;
|
1652
|
+
if ((additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat) === "mustache") {
|
1653
|
+
parsedTemplate1 = parseMustache(imgTemplate.url);
|
1654
|
+
} else {
|
1655
|
+
parsedTemplate1 = parseFString(imgTemplate.url);
|
1656
|
+
}
|
1410
1657
|
inputVariables = parsedTemplate1.flatMap(function(item) {
|
1411
1658
|
return item.type === "variable" ? [
|
1412
1659
|
item.name
|
@@ -1549,19 +1796,49 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
|
|
1549
1796
|
function _isBaseMessagePromptTemplate(baseMessagePromptTemplateLike) {
|
1550
1797
|
return typeof baseMessagePromptTemplateLike.formatMessages === "function";
|
1551
1798
|
}
|
1552
|
-
function _coerceMessagePromptTemplateLike(messagePromptTemplateLike) {
|
1799
|
+
function _coerceMessagePromptTemplateLike(messagePromptTemplateLike, extra) {
|
1553
1800
|
if (_isBaseMessagePromptTemplate(messagePromptTemplateLike) || isBaseMessage(messagePromptTemplateLike)) {
|
1554
1801
|
return messagePromptTemplateLike;
|
1555
1802
|
}
|
1803
|
+
if (Array.isArray(messagePromptTemplateLike) && messagePromptTemplateLike[0] === "placeholder") {
|
1804
|
+
var messageContent = messagePromptTemplateLike[1];
|
1805
|
+
if (typeof messageContent !== "string" || messageContent[0] !== "{" || messageContent[messageContent.length - 1] !== "}") {
|
1806
|
+
throw new Error('Invalid placeholder template: "'.concat(messagePromptTemplateLike[1], '". Expected a variable name surrounded by curly braces.'));
|
1807
|
+
}
|
1808
|
+
var variableName = messageContent.slice(1, -1);
|
1809
|
+
return new MessagesPlaceholder({
|
1810
|
+
variableName: variableName,
|
1811
|
+
optional: true
|
1812
|
+
});
|
1813
|
+
}
|
1556
1814
|
var message = coerceMessageLikeToMessage(messagePromptTemplateLike);
|
1815
|
+
var templateData;
|
1816
|
+
if (typeof message.content === "string") {
|
1817
|
+
templateData = message.content;
|
1818
|
+
} else {
|
1819
|
+
// Assuming message.content is an array of complex objects, transform it.
|
1820
|
+
templateData = message.content.map(function(item) {
|
1821
|
+
if ("text" in item) {
|
1822
|
+
return {
|
1823
|
+
text: item.text
|
1824
|
+
};
|
1825
|
+
} else if ("image_url" in item) {
|
1826
|
+
return {
|
1827
|
+
image_url: item.image_url
|
1828
|
+
};
|
1829
|
+
} else {
|
1830
|
+
return item;
|
1831
|
+
}
|
1832
|
+
});
|
1833
|
+
}
|
1557
1834
|
if (message._getType() === "human") {
|
1558
|
-
return HumanMessagePromptTemplate.fromTemplate(
|
1835
|
+
return HumanMessagePromptTemplate.fromTemplate(templateData, extra);
|
1559
1836
|
} else if (message._getType() === "ai") {
|
1560
|
-
return AIMessagePromptTemplate.fromTemplate(
|
1837
|
+
return AIMessagePromptTemplate.fromTemplate(templateData, extra);
|
1561
1838
|
} else if (message._getType() === "system") {
|
1562
|
-
return SystemMessagePromptTemplate.fromTemplate(
|
1839
|
+
return SystemMessagePromptTemplate.fromTemplate(templateData, extra);
|
1563
1840
|
} else if (ChatMessage.isInstance(message)) {
|
1564
|
-
return ChatMessagePromptTemplate.fromTemplate(message.content, message.role);
|
1841
|
+
return ChatMessagePromptTemplate.fromTemplate(message.content, message.role, extra);
|
1565
1842
|
} else {
|
1566
1843
|
throw new Error('Could not coerce message prompt template from input. Received message type: "'.concat(message._getType(), '".'));
|
1567
1844
|
}
|
@@ -1604,6 +1881,16 @@ function isMessagesPlaceholder(x) {
|
|
1604
1881
|
writable: true,
|
1605
1882
|
value: true
|
1606
1883
|
});
|
1884
|
+
Object.defineProperty(_assert_this_initialized(_this), "templateFormat", {
|
1885
|
+
enumerable: true,
|
1886
|
+
configurable: true,
|
1887
|
+
writable: true,
|
1888
|
+
value: "f-string"
|
1889
|
+
});
|
1890
|
+
// If input is mustache and validateTemplate is not defined, set it to false
|
1891
|
+
if (input.templateFormat === "mustache" && input.validateTemplate === undefined) {
|
1892
|
+
_this.validateTemplate = false;
|
1893
|
+
}
|
1607
1894
|
Object.assign(_assert_this_initialized(_this), input);
|
1608
1895
|
if (_this.validateTemplate) {
|
1609
1896
|
var inputVariablesMessages = new Set();
|
@@ -1683,6 +1970,7 @@ function isMessagesPlaceholder(x) {
|
|
1683
1970
|
{
|
1684
1971
|
key: "_parseImagePrompts",
|
1685
1972
|
value: function _parseImagePrompts(message, inputValues) {
|
1973
|
+
var _this = this;
|
1686
1974
|
return _async_to_generator(function() {
|
1687
1975
|
var formattedMessageContent;
|
1688
1976
|
return _ts_generator(this, function(_state) {
|
@@ -1714,7 +2002,9 @@ function isMessagesPlaceholder(x) {
|
|
1714
2002
|
} else {
|
1715
2003
|
imageUrl = item.image_url.url;
|
1716
2004
|
}
|
1717
|
-
promptTemplatePlaceholder = PromptTemplate.fromTemplate(imageUrl
|
2005
|
+
promptTemplatePlaceholder = PromptTemplate.fromTemplate(imageUrl, {
|
2006
|
+
templateFormat: _this.templateFormat
|
2007
|
+
});
|
1718
2008
|
return [
|
1719
2009
|
4,
|
1720
2010
|
promptTemplatePlaceholder.format(inputValues)
|
@@ -1914,10 +2204,8 @@ function isMessagesPlaceholder(x) {
|
|
1914
2204
|
},
|
1915
2205
|
{
|
1916
2206
|
key: "fromTemplate",
|
1917
|
-
value:
|
1918
|
-
|
1919
|
-
*/ function fromTemplate(template) {
|
1920
|
-
var prompt = PromptTemplate.fromTemplate(template);
|
2207
|
+
value: function fromTemplate(template, options) {
|
2208
|
+
var prompt = PromptTemplate.fromTemplate(template, options);
|
1921
2209
|
var humanTemplate = new HumanMessagePromptTemplate({
|
1922
2210
|
prompt: prompt
|
1923
2211
|
});
|
@@ -1937,7 +2225,7 @@ function isMessagesPlaceholder(x) {
|
|
1937
2225
|
var flattenedMessages = promptMessages.reduce(function(acc, promptMessage) {
|
1938
2226
|
return acc.concat(// eslint-disable-next-line no-instanceof/no-instanceof
|
1939
2227
|
_instanceof(promptMessage, ChatPromptTemplate) ? promptMessage.promptMessages : [
|
1940
|
-
_coerceMessagePromptTemplateLike(promptMessage)
|
2228
|
+
_coerceMessagePromptTemplateLike(promptMessage, extra)
|
1941
2229
|
]);
|
1942
2230
|
}, []);
|
1943
2231
|
var flattenedPartialVariables = promptMessages.reduce(function(acc, promptMessage) {
|
@@ -1992,7 +2280,8 @@ function isMessagesPlaceholder(x) {
|
|
1992
2280
|
return new this(_object_spread_props(_object_spread({}, extra), {
|
1993
2281
|
inputVariables: _to_consumable_array(inputVariables),
|
1994
2282
|
promptMessages: flattenedMessages,
|
1995
|
-
partialVariables: flattenedPartialVariables
|
2283
|
+
partialVariables: flattenedPartialVariables,
|
2284
|
+
templateFormat: extra === null || extra === void 0 ? void 0 : extra.templateFormat
|
1996
2285
|
}));
|
1997
2286
|
}
|
1998
2287
|
},
|