-
Notifications
You must be signed in to change notification settings - Fork 861
Expand file tree
/
Copy pathFunctionApprovalRequestContent.cs
More file actions
40 lines (35 loc) · 2.19 KB
/
FunctionApprovalRequestContent.cs
File metadata and controls
40 lines (35 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.AI;
/// <summary>
/// Represents a request for approval before invoking a function call.
/// </summary>
public sealed class FunctionApprovalRequestContent : InputRequestContent
{
/// <summary>
/// Initializes a new instance of the <see cref="FunctionApprovalRequestContent"/> class.
/// </summary>
/// <param name="requestId">The unique identifier that correlates this request with its corresponding response. This may differ from the <see cref="FunctionCallContent.CallId"/> of the specified <paramref name="functionCall"/>.</param>
/// <param name="functionCall">The function call that requires approval before execution.</param>
/// <exception cref="ArgumentNullException"><paramref name="requestId"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="requestId"/> is empty or composed entirely of whitespace.</exception>
/// <exception cref="ArgumentNullException"><paramref name="functionCall"/> is <see langword="null"/>.</exception>
public FunctionApprovalRequestContent(string requestId, FunctionCallContent functionCall)
: base(requestId)
{
FunctionCall = Throw.IfNull(functionCall);
}
/// <summary>
/// Gets the function call that requires approval before execution.
/// </summary>
public FunctionCallContent FunctionCall { get; }
/// <summary>
/// Creates a <see cref="FunctionApprovalResponseContent"/> indicating whether the function call is approved or rejected.
/// </summary>
/// <param name="approved"><see langword="true"/> if the function call is approved; otherwise, <see langword="false"/>.</param>
/// <param name="reason">An optional reason for the approval or rejection.</param>
/// <returns>The <see cref="FunctionApprovalResponseContent"/> correlated with this request.</returns>
public FunctionApprovalResponseContent CreateResponse(bool approved, string? reason = null) => new(RequestId, approved, FunctionCall) { Reason = reason };
}