UNPKG

@microsoft/teams-ai

Version:

SDK focused on building AI based applications for Microsoft Teams.

52 lines 2.46 kB
"use strict"; /** * @module teams-ai */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.GroupSection = void 0; const PromptSectionBase_1 = require("./PromptSectionBase"); const LayoutEngine_1 = require("./LayoutEngine"); /** * A group of sections that will rendered as a single message. */ class GroupSection extends PromptSectionBase_1.PromptSectionBase { _layoutEngine; sections; role; /** * * @param {PromptSection[]} sections - List of sections to group together. * @param {string} role - Optional. Message role to use for this section. Defaults to `system`. * @param {number} tokens - Optional. Sizing strategy for this section. Defaults to `auto`. * @param {boolean} required - Optional. Indicates if this section is required. Defaults to `true`. * @param {string} separator - Optional. Separator to use between sections when rendering as text. Defaults to `\n\n`. * @param {string} textPrefix - Optional. Prefix to use for text output. Defaults to `undefined`. */ constructor(sections, role = 'system', tokens = -1, required = true, separator = '\n\n', textPrefix) { super(tokens, required, separator, textPrefix); this._layoutEngine = new LayoutEngine_1.LayoutEngine(sections, tokens, required, separator); this.sections = sections; this.role = role; } /** * @private * @param {TurnContext} context - Context for the current turn of conversation. * @param {Memory} memory - Memory to use for rendering. * @param {PromptFunctions} functions - Prompt functions to use for rendering. * @param {Tokenizer} tokenizer - Tokenizer to use for encoding text. * @param {number} maxTokens - Maximum number of tokens allowed. * @returns {Promise<RenderedPromptSection<Message[]>>} Rendered prompt section as a string. */ async renderAsMessages(context, memory, functions, tokenizer, maxTokens) { // Render sections to text const { output, length } = await this._layoutEngine.renderAsText(context, memory, functions, tokenizer, maxTokens); // Return output as a single message return this.returnMessages([{ role: this.role, content: output }], length, tokenizer, maxTokens); } } exports.GroupSection = GroupSection; //# sourceMappingURL=GroupSection.js.map