@digipair/skill-llm 0.35.2 → 0.36.2

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/api_chain.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { P as PromptTemplate, L as LLMChain, f as BaseChain } from './index.esm2.js';
1
+ import { P as PromptTemplate, L as LLMChain, g as BaseChain } from './index.esm2.js';
2
2
 
3
3
  var API_URL_RAW_PROMPT_TEMPLATE = "You are given the below API Documentation:\n{api_docs}\nUsing this documentation, generate the full API url to call for answering the user question.\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n\nQuestion:{question}\nAPI url:";
4
4
  var API_URL_PROMPT_TEMPLATE = /* #__PURE__ */ new PromptTemplate({
package/chat.cjs.js CHANGED
@@ -569,11 +569,23 @@ function _ts_generator$1(thisArg, body) {
569
569
  writable: true,
570
570
  value: true
571
571
  });
572
+ /**
573
+ * Additional fields which should be included inside
574
+ * the message content array if using a complex message
575
+ * content.
576
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
577
+ Object.defineProperty(_assert_this_initialized$1(_this), "additionalContentFields", {
578
+ enumerable: true,
579
+ configurable: true,
580
+ writable: true,
581
+ value: void 0
582
+ });
572
583
  _this.template = input.template;
573
584
  var _input_templateFormat;
574
585
  _this.templateFormat = (_input_templateFormat = input.templateFormat) !== null && _input_templateFormat !== void 0 ? _input_templateFormat : _this.templateFormat;
575
586
  var _input_validateTemplate;
576
587
  _this.validateTemplate = (_input_validateTemplate = input.validateTemplate) !== null && _input_validateTemplate !== void 0 ? _input_validateTemplate : _this.validateTemplate;
588
+ _this.additionalContentFields = input.additionalContentFields;
577
589
  if (_this.validateTemplate) {
578
590
  var totalInputVariables = _this.inputVariables;
579
591
  if (_this.partialVariables) {
@@ -1165,6 +1177,8 @@ function _ts_values(o) {
1165
1177
  "Additional message: ".concat(e.message)
1166
1178
  ].join("\n\n"));
1167
1179
  error1.name = "InputFormatError";
1180
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1181
+ error1.lc_error_code = e.lc_error_code;
1168
1182
  throw error1;
1169
1183
  }
1170
1184
  return [
@@ -1499,7 +1513,7 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1499
1513
  value: function format(input) {
1500
1514
  var _this = this;
1501
1515
  return _async_to_generator(function() {
1502
- var text, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, prompt, inputs, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item, formatted, formatted1, err;
1516
+ var text, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, prompt, inputs, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item, formatted, additionalContentFields, formatted1, additionalContentFields1, err;
1503
1517
  return _ts_generator(this, function(_state) {
1504
1518
  switch(_state.label){
1505
1519
  case 0:
@@ -1574,10 +1588,15 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1574
1588
  ];
1575
1589
  case 5:
1576
1590
  formatted = _state.sent();
1577
- content.push({
1591
+ additionalContentFields = void 0;
1592
+ if ("additionalContentFields" in prompt) {
1593
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1594
+ additionalContentFields = prompt.additionalContentFields;
1595
+ }
1596
+ content.push(_object_spread_props(_object_spread({}, additionalContentFields), {
1578
1597
  type: "text",
1579
1598
  text: formatted
1580
- });
1599
+ }));
1581
1600
  return [
1582
1601
  3,
1583
1602
  8
@@ -1593,10 +1612,15 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1593
1612
  ];
1594
1613
  case 7:
1595
1614
  formatted1 = _state.sent();
1596
- content.push({
1615
+ additionalContentFields1 = void 0;
1616
+ if ("additionalContentFields" in prompt) {
1617
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1618
+ additionalContentFields1 = prompt.additionalContentFields;
1619
+ }
1620
+ content.push(_object_spread_props(_object_spread({}, additionalContentFields1), {
1597
1621
  type: "image_url",
1598
1622
  image_url: formatted1
1599
- });
1623
+ }));
1600
1624
  _state.label = 8;
1601
1625
  case 8:
1602
1626
  _iteratorNormalCompletion = true;
@@ -1694,7 +1718,10 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1694
1718
  var _item_text;
1695
1719
  text = (_item_text = item.text) !== null && _item_text !== void 0 ? _item_text : "";
1696
1720
  }
1697
- prompt.push(index.PromptTemplate.fromTemplate(text, additionalOptions));
1721
+ var options = _object_spread({}, additionalOptions, typeof item !== "string" ? {
1722
+ additionalContentFields: item
1723
+ } : {});
1724
+ prompt.push(index.PromptTemplate.fromTemplate(text, options));
1698
1725
  } else if (typeof item === "object" && "image_url" in item) {
1699
1726
  var _item_image_url;
1700
1727
  var imgTemplate = (_item_image_url = item.image_url) !== null && _item_image_url !== void 0 ? _item_image_url : "";
@@ -1729,7 +1756,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1729
1756
  imgTemplateObject = new ImagePromptTemplate({
1730
1757
  template: imgTemplate,
1731
1758
  inputVariables: inputVariables,
1732
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1759
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat,
1760
+ additionalContentFields: item
1733
1761
  });
1734
1762
  } else if (typeof imgTemplate === "object") {
1735
1763
  if ("url" in imgTemplate) {
@@ -1750,7 +1778,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1750
1778
  imgTemplateObject = new ImagePromptTemplate({
1751
1779
  template: imgTemplate,
1752
1780
  inputVariables: inputVariables,
1753
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1781
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat,
1782
+ additionalContentFields: item
1754
1783
  });
1755
1784
  } else {
1756
1785
  throw new Error("Invalid image template");
@@ -1905,13 +1934,13 @@ function _coerceMessagePromptTemplateLike(messagePromptTemplateLike, extra) {
1905
1934
  // Assuming message.content is an array of complex objects, transform it.
1906
1935
  templateData = message.content.map(function(item) {
1907
1936
  if ("text" in item) {
1908
- return {
1937
+ return _object_spread_props(_object_spread({}, item), {
1909
1938
  text: item.text
1910
- };
1939
+ });
1911
1940
  } else if ("image_url" in item) {
1912
- return {
1941
+ return _object_spread_props(_object_spread({}, item), {
1913
1942
  image_url: item.image_url
1914
- };
1943
+ });
1915
1944
  } else {
1916
1945
  return item;
1917
1946
  }
@@ -2180,7 +2209,8 @@ function isMessagesPlaceholder(x) {
2180
2209
  case 2:
2181
2210
  inputValues = promptMessage.inputVariables.reduce(function(acc, inputVariable) {
2182
2211
  if (!(inputVariable in allValues) && !(isMessagesPlaceholder(promptMessage) && promptMessage.optional)) {
2183
- throw new Error("Missing value for input variable `".concat(inputVariable.toString(), "`"));
2212
+ var error = index.addLangChainErrorFields(new Error("Missing value for input variable `".concat(inputVariable.toString(), "`")), "INVALID_PROMPT_INPUT");
2213
+ throw error;
2184
2214
  }
2185
2215
  acc[inputVariable] = allValues[inputVariable];
2186
2216
  return acc;
package/chat.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as BaseMessage, c as checkValidTemplate, b as BasePromptTemplate, r as renderTemplate, 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';
1
+ import { a as BaseMessage, c as checkValidTemplate, b as BasePromptTemplate, r as renderTemplate, 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, f as addLangChainErrorFields, R as Runnable } from './index.esm2.js';
2
2
 
3
3
  function _assert_this_initialized$2(self) {
4
4
  if (self === void 0) {
@@ -567,11 +567,23 @@ function _ts_generator$1(thisArg, body) {
567
567
  writable: true,
568
568
  value: true
569
569
  });
570
+ /**
571
+ * Additional fields which should be included inside
572
+ * the message content array if using a complex message
573
+ * content.
574
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
575
+ Object.defineProperty(_assert_this_initialized$1(_this), "additionalContentFields", {
576
+ enumerable: true,
577
+ configurable: true,
578
+ writable: true,
579
+ value: void 0
580
+ });
570
581
  _this.template = input.template;
571
582
  var _input_templateFormat;
572
583
  _this.templateFormat = (_input_templateFormat = input.templateFormat) !== null && _input_templateFormat !== void 0 ? _input_templateFormat : _this.templateFormat;
573
584
  var _input_validateTemplate;
574
585
  _this.validateTemplate = (_input_validateTemplate = input.validateTemplate) !== null && _input_validateTemplate !== void 0 ? _input_validateTemplate : _this.validateTemplate;
586
+ _this.additionalContentFields = input.additionalContentFields;
575
587
  if (_this.validateTemplate) {
576
588
  var totalInputVariables = _this.inputVariables;
577
589
  if (_this.partialVariables) {
@@ -1163,6 +1175,8 @@ function _ts_values(o) {
1163
1175
  "Additional message: ".concat(e.message)
1164
1176
  ].join("\n\n"));
1165
1177
  error1.name = "InputFormatError";
1178
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1179
+ error1.lc_error_code = e.lc_error_code;
1166
1180
  throw error1;
1167
1181
  }
1168
1182
  return [
@@ -1497,7 +1511,7 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1497
1511
  value: function format(input) {
1498
1512
  var _this = this;
1499
1513
  return _async_to_generator(function() {
1500
- var text, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, prompt, inputs, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item, formatted, formatted1, err;
1514
+ var text, content, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, prompt, inputs, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, item, formatted, additionalContentFields, formatted1, additionalContentFields1, err;
1501
1515
  return _ts_generator(this, function(_state) {
1502
1516
  switch(_state.label){
1503
1517
  case 0:
@@ -1572,10 +1586,15 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1572
1586
  ];
1573
1587
  case 5:
1574
1588
  formatted = _state.sent();
1575
- content.push({
1589
+ additionalContentFields = void 0;
1590
+ if ("additionalContentFields" in prompt) {
1591
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1592
+ additionalContentFields = prompt.additionalContentFields;
1593
+ }
1594
+ content.push(_object_spread_props(_object_spread({}, additionalContentFields), {
1576
1595
  type: "text",
1577
1596
  text: formatted
1578
- });
1597
+ }));
1579
1598
  return [
1580
1599
  3,
1581
1600
  8
@@ -1591,10 +1610,15 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1591
1610
  ];
1592
1611
  case 7:
1593
1612
  formatted1 = _state.sent();
1594
- content.push({
1613
+ additionalContentFields1 = void 0;
1614
+ if ("additionalContentFields" in prompt) {
1615
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1616
+ additionalContentFields1 = prompt.additionalContentFields;
1617
+ }
1618
+ content.push(_object_spread_props(_object_spread({}, additionalContentFields1), {
1595
1619
  type: "image_url",
1596
1620
  image_url: formatted1
1597
- });
1621
+ }));
1598
1622
  _state.label = 8;
1599
1623
  case 8:
1600
1624
  _iteratorNormalCompletion = true;
@@ -1692,7 +1716,10 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1692
1716
  var _item_text;
1693
1717
  text = (_item_text = item.text) !== null && _item_text !== void 0 ? _item_text : "";
1694
1718
  }
1695
- prompt.push(PromptTemplate.fromTemplate(text, additionalOptions));
1719
+ var options = _object_spread({}, additionalOptions, typeof item !== "string" ? {
1720
+ additionalContentFields: item
1721
+ } : {});
1722
+ prompt.push(PromptTemplate.fromTemplate(text, options));
1696
1723
  } else if (typeof item === "object" && "image_url" in item) {
1697
1724
  var _item_image_url;
1698
1725
  var imgTemplate = (_item_image_url = item.image_url) !== null && _item_image_url !== void 0 ? _item_image_url : "";
@@ -1727,7 +1754,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1727
1754
  imgTemplateObject = new ImagePromptTemplate({
1728
1755
  template: imgTemplate,
1729
1756
  inputVariables: inputVariables,
1730
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1757
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat,
1758
+ additionalContentFields: item
1731
1759
  });
1732
1760
  } else if (typeof imgTemplate === "object") {
1733
1761
  if ("url" in imgTemplate) {
@@ -1748,7 +1776,8 @@ var _StringImageMessagePromptTemplate = /*#__PURE__*/ function(BaseMessagePrompt
1748
1776
  imgTemplateObject = new ImagePromptTemplate({
1749
1777
  template: imgTemplate,
1750
1778
  inputVariables: inputVariables,
1751
- templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat
1779
+ templateFormat: additionalOptions === null || additionalOptions === void 0 ? void 0 : additionalOptions.templateFormat,
1780
+ additionalContentFields: item
1752
1781
  });
1753
1782
  } else {
1754
1783
  throw new Error("Invalid image template");
@@ -1903,13 +1932,13 @@ function _coerceMessagePromptTemplateLike(messagePromptTemplateLike, extra) {
1903
1932
  // Assuming message.content is an array of complex objects, transform it.
1904
1933
  templateData = message.content.map(function(item) {
1905
1934
  if ("text" in item) {
1906
- return {
1935
+ return _object_spread_props(_object_spread({}, item), {
1907
1936
  text: item.text
1908
- };
1937
+ });
1909
1938
  } else if ("image_url" in item) {
1910
- return {
1939
+ return _object_spread_props(_object_spread({}, item), {
1911
1940
  image_url: item.image_url
1912
- };
1941
+ });
1913
1942
  } else {
1914
1943
  return item;
1915
1944
  }
@@ -2178,7 +2207,8 @@ function isMessagesPlaceholder(x) {
2178
2207
  case 2:
2179
2208
  inputValues = promptMessage.inputVariables.reduce(function(acc, inputVariable) {
2180
2209
  if (!(inputVariable in allValues) && !(isMessagesPlaceholder(promptMessage) && promptMessage.optional)) {
2181
- throw new Error("Missing value for input variable `".concat(inputVariable.toString(), "`"));
2210
+ var error = addLangChainErrorFields(new Error("Missing value for input variable `".concat(inputVariable.toString(), "`")), "INVALID_PROMPT_INPUT");
2211
+ throw error;
2182
2212
  }
2183
2213
  acc[inputVariable] = allValues[inputVariable];
2184
2214
  return acc;