'use strict';

var index = require('./index.cjs2.js');
require('nanoid');
require('util');

function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _assert_this_initialized(self) {
    if (self === void 0) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }
    return self;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
        var info = gen[key](arg);
        var value = info.value;
    } catch (error) {
        reject(error);
        return;
    }
    if (info.done) {
        resolve(value);
    } else {
        Promise.resolve(value).then(_next, _throw);
    }
}
function _async_to_generator(fn) {
    return function() {
        var self = this, args = arguments;
        return new Promise(function(resolve, reject) {
            var gen = fn.apply(self, args);
            function _next(value) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
            }
            function _throw(err) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
            }
            _next(undefined);
        });
    };
}
function _class_call_check(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
    }
}
function _defineProperties(target, props) {
    for(var i = 0; i < props.length; i++){
        var descriptor = props[i];
        descriptor.enumerable = descriptor.enumerable || false;
        descriptor.configurable = true;
        if ("value" in descriptor) descriptor.writable = true;
        Object.defineProperty(target, descriptor.key, descriptor);
    }
}
function _create_class(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
}
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _get_prototype_of(o) {
    _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
        return o.__proto__ || Object.getPrototypeOf(o);
    };
    return _get_prototype_of(o);
}
function _inherits(subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function");
    }
    subClass.prototype = Object.create(superClass && superClass.prototype, {
        constructor: {
            value: subClass,
            writable: true,
            configurable: true
        }
    });
    if (superClass) _set_prototype_of(subClass, superClass);
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _possible_constructor_return(self, call) {
    if (call && (_type_of(call) === "object" || typeof call === "function")) {
        return call;
    }
    return _assert_this_initialized(self);
}
function _set_prototype_of(o, p) {
    _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
        o.__proto__ = p;
        return o;
    };
    return _set_prototype_of(o, p);
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _type_of(obj) {
    "@swc/helpers - typeof";
    return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _is_native_reflect_construct() {
    if (typeof Reflect === "undefined" || !Reflect.construct) return false;
    if (Reflect.construct.sham) return false;
    if (typeof Proxy === "function") return true;
    try {
        Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
        return true;
    } catch (e) {
        return false;
    }
}
function _create_super(Derived) {
    var hasNativeReflectConstruct = _is_native_reflect_construct();
    return function _createSuperInternal() {
        var Super = _get_prototype_of(Derived), result;
        if (hasNativeReflectConstruct) {
            var NewTarget = _get_prototype_of(this).constructor;
            result = Reflect.construct(Super, arguments, NewTarget);
        } else {
            result = Super.apply(this, arguments);
        }
        return _possible_constructor_return(this, result);
    };
}
function _ts_generator(thisArg, body) {
    var f, y, t, g, _ = {
        label: 0,
        sent: function() {
            if (t[0] & 1) throw t[1];
            return t[1];
        },
        trys: [],
        ops: []
    };
    return g = {
        next: verb(0),
        "throw": verb(1),
        "return": verb(2)
    }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
        return this;
    }), g;
    function verb(n) {
        return function(v) {
            return step([
                n,
                v
            ]);
        };
    }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while(_)try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [
                op[0] & 2,
                t.value
            ];
            switch(op[0]){
                case 0:
                case 1:
                    t = op;
                    break;
                case 4:
                    _.label++;
                    return {
                        value: op[1],
                        done: false
                    };
                case 5:
                    _.label++;
                    y = op[1];
                    op = [
                        0
                    ];
                    continue;
                case 7:
                    op = _.ops.pop();
                    _.trys.pop();
                    continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                        _ = 0;
                        continue;
                    }
                    if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
                        _.label = op[1];
                        break;
                    }
                    if (op[0] === 6 && _.label < t[1]) {
                        _.label = t[1];
                        t = op;
                        break;
                    }
                    if (t && _.label < t[2]) {
                        _.label = t[2];
                        _.ops.push(op);
                        break;
                    }
                    if (t[2]) _.ops.pop();
                    _.trys.pop();
                    continue;
            }
            op = body.call(thisArg, _);
        } catch (e) {
            op = [
                6,
                e
            ];
            y = 0;
        } finally{
            f = t = 0;
        }
        if (op[0] & 5) throw op[1];
        return {
            value: op[0] ? op[1] : void 0,
            done: true
        };
    }
}
/**
 * Prompt template that contains few-shot examples.
 * @augments BasePromptTemplate
 * @augments FewShotPromptTemplateInput
 * @example
 * ```typescript
 * const examplePrompt = PromptTemplate.fromTemplate(
 *   "Input: {input}\nOutput: {output}",
 * );
 *
 * const exampleSelector = await SemanticSimilarityExampleSelector.fromExamples(
 *   [
 *     { input: "happy", output: "sad" },
 *     { input: "tall", output: "short" },
 *     { input: "energetic", output: "lethargic" },
 *     { input: "sunny", output: "gloomy" },
 *     { input: "windy", output: "calm" },
 *   ],
 *   new OpenAIEmbeddings(),
 *   HNSWLib,
 *   { k: 1 },
 * );
 *
 * const dynamicPrompt = new FewShotPromptTemplate({
 *   exampleSelector,
 *   examplePrompt,
 *   prefix: "Give the antonym of every input",
 *   suffix: "Input: {adjective}\nOutput:",
 *   inputVariables: ["adjective"],
 * });
 *
 * // Format the dynamic prompt with the input 'rainy'
 * console.log(await dynamicPrompt.format({ adjective: "rainy" }));
 *
 * ```
 */ var FewShotPromptTemplate = /*#__PURE__*/ function(BaseStringPromptTemplate) {
    _inherits(FewShotPromptTemplate, BaseStringPromptTemplate);
    var _super = _create_super(FewShotPromptTemplate);
    function FewShotPromptTemplate(input) {
        _class_call_check(this, FewShotPromptTemplate);
        var _this;
        _this = _super.call(this, input);
        Object.defineProperty(_assert_this_initialized(_this), "lc_serializable", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: false
        });
        Object.defineProperty(_assert_this_initialized(_this), "examples", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(_assert_this_initialized(_this), "exampleSelector", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(_assert_this_initialized(_this), "examplePrompt", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(_assert_this_initialized(_this), "suffix", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: ""
        });
        Object.defineProperty(_assert_this_initialized(_this), "exampleSeparator", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: "\n\n"
        });
        Object.defineProperty(_assert_this_initialized(_this), "prefix", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: ""
        });
        Object.defineProperty(_assert_this_initialized(_this), "templateFormat", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: "f-string"
        });
        Object.defineProperty(_assert_this_initialized(_this), "validateTemplate", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: true
        });
        Object.assign(_assert_this_initialized(_this), input);
        if (_this.examples !== undefined && _this.exampleSelector !== undefined) {
            throw new Error("Only one of 'examples' and 'example_selector' should be provided");
        }
        if (_this.examples === undefined && _this.exampleSelector === undefined) {
            throw new Error("One of 'examples' and 'example_selector' should be provided");
        }
        if (_this.validateTemplate) {
            var totalInputVariables = _this.inputVariables;
            if (_this.partialVariables) {
                totalInputVariables = totalInputVariables.concat(Object.keys(_this.partialVariables));
            }
            index.checkValidTemplate(_this.prefix + _this.suffix, _this.templateFormat, totalInputVariables);
        }
        return _this;
    }
    _create_class(FewShotPromptTemplate, [
        {
            key: "_getPromptType",
            value: function _getPromptType() {
                return "few_shot";
            }
        },
        {
            key: "getExamples",
            value: function getExamples(inputVariables) {
                var _this = this;
                return _async_to_generator(function() {
                    return _ts_generator(this, function(_state) {
                        if (_this.examples !== undefined) {
                            return [
                                2,
                                _this.examples
                            ];
                        }
                        if (_this.exampleSelector !== undefined) {
                            return [
                                2,
                                _this.exampleSelector.selectExamples(inputVariables)
                            ];
                        }
                        throw new Error("One of 'examples' and 'example_selector' should be provided");
                    });
                })();
            }
        },
        {
            key: "partial",
            value: function partial(values) {
                var _this = this;
                return _async_to_generator(function() {
                    var newInputVariables, _this_partialVariables, newPartialVariables, promptDict;
                    return _ts_generator(this, function(_state) {
                        newInputVariables = _this.inputVariables.filter(function(iv) {
                            return !(iv in values);
                        });
                        newPartialVariables = _object_spread({}, (_this_partialVariables = _this.partialVariables) !== null && _this_partialVariables !== void 0 ? _this_partialVariables : {}, values);
                        promptDict = _object_spread_props(_object_spread({}, _this), {
                            inputVariables: newInputVariables,
                            partialVariables: newPartialVariables
                        });
                        return [
                            2,
                            new FewShotPromptTemplate(promptDict)
                        ];
                    });
                })();
            }
        },
        {
            key: "format",
            value: /**
     * Formats the prompt with the given values.
     * @param values The values to format the prompt with.
     * @returns A promise that resolves to a string representing the formatted prompt.
     */ function format(values) {
                var _this = this;
                return _async_to_generator(function() {
                    var allValues, examples, exampleStrings, template;
                    return _ts_generator(this, function(_state) {
                        switch(_state.label){
                            case 0:
                                return [
                                    4,
                                    _this.mergePartialAndUserVariables(values)
                                ];
                            case 1:
                                allValues = _state.sent();
                                return [
                                    4,
                                    _this.getExamples(allValues)
                                ];
                            case 2:
                                examples = _state.sent();
                                return [
                                    4,
                                    Promise.all(examples.map(function(example) {
                                        return _this.examplePrompt.format(example);
                                    }))
                                ];
                            case 3:
                                exampleStrings = _state.sent();
                                template = [
                                    _this.prefix
                                ].concat(_to_consumable_array(exampleStrings), [
                                    _this.suffix
                                ]).join(_this.exampleSeparator);
                                return [
                                    2,
                                    index.renderTemplate(template, _this.templateFormat, allValues)
                                ];
                        }
                    });
                })();
            }
        },
        {
            key: "serialize",
            value: function serialize() {
                if (this.exampleSelector || !this.examples) {
                    throw new Error("Serializing an example selector is not currently supported");
                }
                if (this.outputParser !== undefined) {
                    throw new Error("Serializing an output parser is not currently supported");
                }
                return {
                    _type: this._getPromptType(),
                    input_variables: this.inputVariables,
                    example_prompt: this.examplePrompt.serialize(),
                    example_separator: this.exampleSeparator,
                    suffix: this.suffix,
                    prefix: this.prefix,
                    template_format: this.templateFormat,
                    examples: this.examples
                };
            }
        }
    ], [
        {
            key: "lc_name",
            value: function lc_name() {
                return "FewShotPromptTemplate";
            }
        },
        {
            key: "deserialize",
            value: function deserialize(data) {
                return _async_to_generator(function() {
                    var example_prompt, examplePrompt, examples;
                    return _ts_generator(this, function(_state) {
                        switch(_state.label){
                            case 0:
                                example_prompt = data.example_prompt;
                                if (!example_prompt) {
                                    throw new Error("Missing example prompt");
                                }
                                return [
                                    4,
                                    index.PromptTemplate.deserialize(example_prompt)
                                ];
                            case 1:
                                examplePrompt = _state.sent();
                                if (Array.isArray(data.examples)) {
                                    examples = data.examples;
                                } else {
                                    throw new Error("Invalid examples format. Only list or string are supported.");
                                }
                                return [
                                    2,
                                    new FewShotPromptTemplate({
                                        inputVariables: data.input_variables,
                                        examplePrompt: examplePrompt,
                                        examples: examples,
                                        exampleSeparator: data.example_separator,
                                        prefix: data.prefix,
                                        suffix: data.suffix,
                                        templateFormat: data.template_format
                                    })
                                ];
                        }
                    });
                })();
            }
        }
    ]);
    return FewShotPromptTemplate;
}(index.BaseStringPromptTemplate);
/**
 * Chat prompt template that contains few-shot examples.
 * @augments BasePromptTemplateInput
 * @augments FewShotChatMessagePromptTemplateInput
 */ var FewShotChatMessagePromptTemplate = /*#__PURE__*/ function(BaseChatPromptTemplate) {
    _inherits(FewShotChatMessagePromptTemplate, BaseChatPromptTemplate);
    var _super = _create_super(FewShotChatMessagePromptTemplate);
    function FewShotChatMessagePromptTemplate(fields) {
        _class_call_check(this, FewShotChatMessagePromptTemplate);
        var _this;
        _this = _super.call(this, fields);
        Object.defineProperty(_assert_this_initialized(_this), "lc_serializable", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: true
        });
        Object.defineProperty(_assert_this_initialized(_this), "examples", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(_assert_this_initialized(_this), "exampleSelector", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(_assert_this_initialized(_this), "examplePrompt", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(_assert_this_initialized(_this), "suffix", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: ""
        });
        Object.defineProperty(_assert_this_initialized(_this), "exampleSeparator", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: "\n\n"
        });
        Object.defineProperty(_assert_this_initialized(_this), "prefix", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: ""
        });
        Object.defineProperty(_assert_this_initialized(_this), "templateFormat", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: "f-string"
        });
        Object.defineProperty(_assert_this_initialized(_this), "validateTemplate", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: true
        });
        _this.examples = fields.examples;
        _this.examplePrompt = fields.examplePrompt;
        var _fields_exampleSeparator;
        _this.exampleSeparator = (_fields_exampleSeparator = fields.exampleSeparator) !== null && _fields_exampleSeparator !== void 0 ? _fields_exampleSeparator : "\n\n";
        _this.exampleSelector = fields.exampleSelector;
        var _fields_prefix;
        _this.prefix = (_fields_prefix = fields.prefix) !== null && _fields_prefix !== void 0 ? _fields_prefix : "";
        var _fields_suffix;
        _this.suffix = (_fields_suffix = fields.suffix) !== null && _fields_suffix !== void 0 ? _fields_suffix : "";
        var _fields_templateFormat;
        _this.templateFormat = (_fields_templateFormat = fields.templateFormat) !== null && _fields_templateFormat !== void 0 ? _fields_templateFormat : "f-string";
        var _fields_validateTemplate;
        _this.validateTemplate = (_fields_validateTemplate = fields.validateTemplate) !== null && _fields_validateTemplate !== void 0 ? _fields_validateTemplate : true;
        if (_this.examples !== undefined && _this.exampleSelector !== undefined) {
            throw new Error("Only one of 'examples' and 'example_selector' should be provided");
        }
        if (_this.examples === undefined && _this.exampleSelector === undefined) {
            throw new Error("One of 'examples' and 'example_selector' should be provided");
        }
        if (_this.validateTemplate) {
            var totalInputVariables = _this.inputVariables;
            if (_this.partialVariables) {
                totalInputVariables = totalInputVariables.concat(Object.keys(_this.partialVariables));
            }
            index.checkValidTemplate(_this.prefix + _this.suffix, _this.templateFormat, totalInputVariables);
        }
        return _this;
    }
    _create_class(FewShotChatMessagePromptTemplate, [
        {
            key: "_getPromptType",
            value: function _getPromptType() {
                return "few_shot_chat";
            }
        },
        {
            key: "getExamples",
            value: function getExamples(inputVariables) {
                var _this = this;
                return _async_to_generator(function() {
                    return _ts_generator(this, function(_state) {
                        if (_this.examples !== undefined) {
                            return [
                                2,
                                _this.examples
                            ];
                        }
                        if (_this.exampleSelector !== undefined) {
                            return [
                                2,
                                _this.exampleSelector.selectExamples(inputVariables)
                            ];
                        }
                        throw new Error("One of 'examples' and 'example_selector' should be provided");
                    });
                })();
            }
        },
        {
            key: "formatMessages",
            value: /**
     * Formats the list of values and returns a list of formatted messages.
     * @param values The values to format the prompt with.
     * @returns A promise that resolves to a string representing the formatted prompt.
     */ function formatMessages(values) {
                var _this = this;
                return _async_to_generator(function() {
                    var allValues, examples, messages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, example, _messages, exampleMessages, err;
                    return _ts_generator(this, function(_state) {
                        switch(_state.label){
                            case 0:
                                return [
                                    4,
                                    _this.mergePartialAndUserVariables(values)
                                ];
                            case 1:
                                allValues = _state.sent();
                                return [
                                    4,
                                    _this.getExamples(allValues)
                                ];
                            case 2:
                                examples = _state.sent();
                                examples = examples.map(function(example) {
                                    // eslint-disable-next-line @typescript-eslint/no-explicit-any
                                    var result = {};
                                    _this.examplePrompt.inputVariables.forEach(function(inputVariable) {
                                        result[inputVariable] = example[inputVariable];
                                    });
                                    return result;
                                });
                                messages = [];
                                _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
                                _state.label = 3;
                            case 3:
                                _state.trys.push([
                                    3,
                                    8,
                                    9,
                                    10
                                ]);
                                _iterator = examples[Symbol.iterator]();
                                _state.label = 4;
                            case 4:
                                if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
                                    3,
                                    7
                                ];
                                example = _step.value;
                                return [
                                    4,
                                    _this.examplePrompt.formatMessages(example)
                                ];
                            case 5:
                                exampleMessages = _state.sent();
                                (_messages = messages).push.apply(_messages, _to_consumable_array(exampleMessages));
                                _state.label = 6;
                            case 6:
                                _iteratorNormalCompletion = true;
                                return [
                                    3,
                                    4
                                ];
                            case 7:
                                return [
                                    3,
                                    10
                                ];
                            case 8:
                                err = _state.sent();
                                _didIteratorError = true;
                                _iteratorError = err;
                                return [
                                    3,
                                    10
                                ];
                            case 9:
                                try {
                                    if (!_iteratorNormalCompletion && _iterator.return != null) {
                                        _iterator.return();
                                    }
                                } finally{
                                    if (_didIteratorError) {
                                        throw _iteratorError;
                                    }
                                }
                                return [
                                    7
                                ];
                            case 10:
                                return [
                                    2,
                                    messages
                                ];
                        }
                    });
                })();
            }
        },
        {
            key: "format",
            value: /**
     * Formats the prompt with the given values.
     * @param values The values to format the prompt with.
     * @returns A promise that resolves to a string representing the formatted prompt.
     */ function format(values) {
                var _this = this;
                return _async_to_generator(function() {
                    var allValues, examples, exampleMessages, exampleStrings, template;
                    return _ts_generator(this, function(_state) {
                        switch(_state.label){
                            case 0:
                                return [
                                    4,
                                    _this.mergePartialAndUserVariables(values)
                                ];
                            case 1:
                                allValues = _state.sent();
                                return [
                                    4,
                                    _this.getExamples(allValues)
                                ];
                            case 2:
                                examples = _state.sent();
                                return [
                                    4,
                                    Promise.all(examples.map(function(example) {
                                        return _this.examplePrompt.formatMessages(example);
                                    }))
                                ];
                            case 3:
                                exampleMessages = _state.sent();
                                exampleStrings = exampleMessages.flat().map(function(message) {
                                    return message.content;
                                });
                                template = [
                                    _this.prefix
                                ].concat(_to_consumable_array(exampleStrings), [
                                    _this.suffix
                                ]).join(_this.exampleSeparator);
                                return [
                                    2,
                                    index.renderTemplate(template, _this.templateFormat, allValues)
                                ];
                        }
                    });
                })();
            }
        },
        {
            key: "partial",
            value: /**
     * Partially formats the prompt with the given values.
     * @param values The values to partially format the prompt with.
     * @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.
     */ function partial(values) {
                var _this = this;
                return _async_to_generator(function() {
                    var newInputVariables, _this_partialVariables, newPartialVariables, promptDict;
                    return _ts_generator(this, function(_state) {
                        newInputVariables = _this.inputVariables.filter(function(variable) {
                            return !(variable in values);
                        });
                        newPartialVariables = _object_spread({}, (_this_partialVariables = _this.partialVariables) !== null && _this_partialVariables !== void 0 ? _this_partialVariables : {}, values);
                        promptDict = _object_spread_props(_object_spread({}, _this), {
                            inputVariables: newInputVariables,
                            partialVariables: newPartialVariables
                        });
                        return [
                            2,
                            new FewShotChatMessagePromptTemplate(promptDict)
                        ];
                    });
                })();
            }
        }
    ], [
        {
            key: "lc_name",
            value: function lc_name() {
                return "FewShotChatMessagePromptTemplate";
            }
        }
    ]);
    return FewShotChatMessagePromptTemplate;
}(index.BaseChatPromptTemplate);

exports.FewShotChatMessagePromptTemplate = FewShotChatMessagePromptTemplate;
exports.FewShotPromptTemplate = FewShotPromptTemplate;
