UNPKG

@microsoft/teams-ai

Version:

SDK focused on building AI based applications for Microsoft Teams.

57 lines 2.26 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.ActionOutputMessage = void 0; const PromptSectionBase_1 = require("./PromptSectionBase"); /** * A section capable of rendering user input text and images as a user message. */ class ActionOutputMessage extends PromptSectionBase_1.PromptSectionBase { _historyVariable; /** * Creates a new 'ActionOutputMessage' instance. * @param {string} historyVariable Optional. Name of the variable containing the conversation history. * @param {number} tokens Optional. Sizing strategy for this section. Defaults to `auto`. */ constructor(historyVariable = 'temp.history', tokens = -1) { super(tokens, true, '\n', 'action: '); this._historyVariable = historyVariable; } /** * @private * @param {TurnContext} context Turn context for the message to be rendered. * @param {Memory} memory Memory in storage. * @param {PromptFunctions} functions Prompt functions. * @param {Tokenizer} tokenizer Tokenizer. * @param {number} maxTokens Max tokens to be used for rendering. * @returns {Promise<RenderedPromptSection<Message<any>[]>>} Rendered prompt section. */ async renderAsMessages(context, memory, functions, tokenizer, maxTokens) { let actionOutputs = {}; let actionCalls = []; const history = memory.getValue(this._historyVariable) ?? []; const messages = []; if (history.length > 1) { actionOutputs = memory.getValue('temp.actionOutputs'); actionCalls = history[history.length - 1].action_calls ?? []; } for (const actionCall of actionCalls) { const message = { role: 'tool', content: actionOutputs[actionCall.id], action_call_id: actionCall.id }; messages.push(message); } // Return output return { output: messages, length: messages.length, tooLong: false }; } } exports.ActionOutputMessage = ActionOutputMessage; //# sourceMappingURL=ActionOutputMessage.js.map