@microsoft/teams-ai
Version:
SDK focused on building AI based applications for Microsoft Teams.
59 lines • 2.4 kB
JavaScript
;
/**
* @module teams-ai
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextSection = void 0;
const PromptSectionBase_1 = require("./PromptSectionBase");
/**
* A section of text that will be rendered as a message.
*/
class TextSection extends PromptSectionBase_1.PromptSectionBase {
_length = -1;
/**
* Text to use for this section.
*/
text;
/**
* Message role to use for this section.
*/
role;
/**
* Creates a new 'TextSection' instance.
* @param {string} text - Text to use for this section.
* @param {string} role - Message role to use for this section.
* @param {number} tokens - Optional. Sizing strategy for this section. Defaults to -1, `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`.
* @param {string} textPrefix - Optional. Prefix to use for text output. Defaults to `undefined`.
*/
constructor(text, role, tokens = -1, required = true, separator = '\n', textPrefix) {
super(tokens, required, separator, textPrefix);
this.text = text;
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) {
// Calculate and cache length
if (this._length < 0) {
this._length = tokenizer.encode(this.text).length;
}
// Return output
const messages = this._length > 0 ? [{ role: this.role, content: this.text }] : [];
return this.returnMessages(messages, this._length, tokenizer, maxTokens);
}
}
exports.TextSection = TextSection;
//# sourceMappingURL=TextSection.js.map