UNPKG

@microsoft/teams-ai

Version:

SDK focused on building AI based applications for Microsoft Teams.

53 lines 2.31 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.FunctionCallMessage = void 0; const PromptSectionBase_1 = require("./PromptSectionBase"); /** * An `assistant` message containing a function to call. * @remarks * The function call information is returned by the model so we use an "assistant" message to * represent it in conversation history. */ class FunctionCallMessage extends PromptSectionBase_1.PromptSectionBase { _length = -1; /** * Name and arguments of the function to call. */ function_call; /** * Creates a new 'FunctionCallMessage' instance. * @param {FunctionCall} function_call name and arguments of the function to call. * @param {number} tokens Optional. Sizing strategy for this section. Defaults to `auto`. * @param {string} assistantPrefix Optional. Prefix to use for assistant messages when rendering as text. Defaults to `assistant: `. */ constructor(function_call, tokens = -1, assistantPrefix = 'assistant: ') { super(tokens, true, '\n', assistantPrefix); this.function_call = function_call; } /** * @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 response text and length if (this._length < 0) { this._length = tokenizer.encode(JSON.stringify(this.function_call)).length; } // Return output return this.returnMessages([{ role: 'assistant', content: undefined, function_call: this.function_call }], this._length, tokenizer, maxTokens); } } exports.FunctionCallMessage = FunctionCallMessage; //# sourceMappingURL=FunctionCallMessage.js.map