-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
ChatCompletionsToolChoice.cs
97 lines (85 loc) · 4.08 KB
/
ChatCompletionsToolChoice.cs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#nullable disable
using System;
using Azure.Core;
namespace Azure.AI.OpenAI;
/// <summary>
/// Represents an optional control that specifies which, if any, tools may be called by the model while processing a
/// chat completions request.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item>
/// <see cref="None"/> is the default when no tools are provided and specifies that the model should not use any
/// tools and instead always generate a message. Note that available tools may still influence the content of
/// messages as generated by the model even when they are not or cannot be selected.
/// </item>
/// <item>
/// <see cref="Auto"/> is the default when tools are provided and specifies that the model should freely
/// determine if, and which, tools should be called instead of generating a message.
/// </item>
/// <item>
/// Providing a <see cref="FunctionDefinition"/> or <see cref="ChatCompletionsFunctionToolDefinition"/> will
/// request that the model constrains its response to only calling the specified function tool.
/// </item>
/// </list>
/// Note: with 1106 model revisions, constraining the model to a specific function via tool_choice will provide a
/// finish_reason of 'stop'. Please check for 'tool_calls' rather than relying on a consistent finish_reason.
/// </remarks>
public partial class ChatCompletionsToolChoice
{
/// <inheritdoc cref="ChatCompletionsToolSelectionPreset.Auto"/>
public static readonly ChatCompletionsToolChoice Auto = new(ChatCompletionsToolSelectionPreset.Auto);
/// <inheritdoc cref="ChatCompletionsToolSelectionPreset.None"/>
public static readonly ChatCompletionsToolChoice None = new(ChatCompletionsToolSelectionPreset.None);
public static implicit operator ChatCompletionsToolChoice(FunctionDefinition functionDefinition)
{
return new(functionDefinition);
}
public static implicit operator ChatCompletionsToolChoice(
ChatCompletionsFunctionToolDefinition functionToolDefinition)
{
return new(functionToolDefinition);
}
/// <summary>
/// Initializes a new instance of <see cref="ChatCompletionsToolChoice"/> that requests the model constrains its
/// response to calling a provided function tool that matches the name of the provided
/// <see cref="FunctionDefinition"/>.
/// </summary>
/// <param name="functionDefinition">
/// A <see cref="FunctionDefinition"/> with a name that matches the function tool to which model responses
/// should be constrained.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="functionDefinition"/> is null.
/// </exception>
public ChatCompletionsToolChoice(FunctionDefinition functionDefinition)
{
Argument.AssertNotNull(functionDefinition, nameof(functionDefinition));
Function = functionDefinition;
}
/// <summary>
/// Initializes a new instance of <see cref="ChatCompletionsToolChoice"/> that requests the model constrains its
/// response to calling a provided function tool definition that matches the name of the provided
/// <see cref="FunctionDefinition"/>.
/// </summary>
/// <param name="functionToolDefinition">
/// A <see cref="ChatCompletionsFunctionToolDefinition"/> with a name that matches the function tool to which
/// model responses should be constrained.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="functionToolDefinition"/> is null.
/// </exception>
public ChatCompletionsToolChoice(ChatCompletionsFunctionToolDefinition functionToolDefinition)
{
Argument.AssertNotNull(functionToolDefinition, nameof(functionToolDefinition));
Function = functionToolDefinition.Function;
}
internal ChatCompletionsToolChoice(ChatCompletionsToolSelectionPreset preset)
{
Preset = preset;
}
internal FunctionDefinition Function { get; }
internal ChatCompletionsToolSelectionPreset Preset { get; }
}