UNPKG

@microsoft/teams-ai

Version:

SDK focused on building AI based applications for Microsoft Teams.

50 lines 2.02 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.DataSourceSection = void 0; const PromptSectionBase_1 = require("./PromptSectionBase"); /** * A section that renders a data source to a prompt. */ class DataSourceSection extends PromptSectionBase_1.PromptSectionBase { _dataSource; /** * Creates a new `DataSourceSection` instance. * @param {DataSource} dataSource - The data source to render. * @param {number} tokens - Desired number of tokens to render. */ constructor(dataSource, tokens) { super(tokens, true, '\n\n'); this._dataSource = dataSource; } /** * @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<string>[]>>} Rendered prompt section as a string. */ async renderAsMessages(context, memory, functions, tokenizer, maxTokens) { // Render data source const budget = this.getTokenBudget(maxTokens); const rendered = await this._dataSource.renderData(context, memory, tokenizer, budget); // Return as a 'system' message // - The role will typically end up being ignored because as this section is usually added // to a `GroupSection` which will override the role. return { output: [{ role: 'system', content: rendered.output }], length: rendered.length, tooLong: rendered.tooLong }; } } exports.DataSourceSection = DataSourceSection; //# sourceMappingURL=DataSourceSection.js.map