openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/Messages/FunctionChatMessage.cs
48lines · modecode
| 1 | using System; |
| 2 | |
| 3 | namespace OpenAI.Chat; |
| 4 | |
| 5 | /// <summary> |
| 6 | /// Represents a chat message of the <c>function</c> role as provided to a chat completion request. A function message |
| 7 | /// resolves a prior <c>function_call</c> received from the model and correlates to both a supplied |
| 8 | /// <see cref="ChatFunction"/> instance as well as a <see cref="ChatFunctionCall"/> made by the model on an |
| 9 | /// <c>assistant</c> response message. |
| 10 | /// </summary> |
| 11 | [Obsolete($"This class is obsolete. Please use {nameof(ToolChatMessage)} instead.")] |
| 12 | [CodeGenModel("ChatCompletionRequestFunctionMessage")] |
| 13 | [CodeGenSuppress("FunctionChatMessage", typeof(string))] |
| 14 | [CodeGenSuppress("FunctionChatMessage", typeof(ChatMessageContent), typeof(string))] |
| 15 | public partial class FunctionChatMessage : ChatMessage |
| 16 | { |
| 17 | /// <summary> |
| 18 | /// Creates a new instance of <see cref="FunctionChatMessage"/>. |
| 19 | /// </summary> |
| 20 | /// <param name="functionName"> |
| 21 | /// The name of the called function that this message provides information from. |
| 22 | /// </param> |
| 23 | /// <param name="content"> |
| 24 | /// The textual content that represents the output or result from the called function. There is no format |
| 25 | /// restriction (e.g. JSON) imposed on this content. |
| 26 | /// </param> |
| 27 | public FunctionChatMessage(string functionName, string content) |
| 28 | : base(ChatMessageRole.Function, content) |
| 29 | { |
| 30 | Argument.AssertNotNull(functionName, nameof(functionName)); |
| 31 | |
| 32 | FunctionName = functionName; |
| 33 | |
| 34 | // FunctionChatMessage treats content as *required* but explicitly *nullable*. If null content was provided, |
| 35 | // enforce manifestation of the (nullable) content collection via .Clear(). |
| 36 | if (!Content.IsInnerCollectionDefined()) |
| 37 | { |
| 38 | Content.Clear(); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // CUSTOM: Renamed. |
| 43 | /// <summary> |
| 44 | /// The <c>name</c> of the called function that this message provides information from. |
| 45 | /// </summary> |
| 46 | [CodeGenMember("Name")] |
| 47 | public string FunctionName { get; } |
| 48 | } |
| 49 | |