openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/customize-openairesponsescontext-attribute

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

OpenAI/src/Custom/Chat/Messages/FunctionChatMessage.cs

47lines · modecode

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