38 instantiations of ChatFinishReason
Microsoft.Extensions.AI.Abstractions (5)
ChatCompletion\ChatFinishReason.cs (5)
69public static ChatFinishReason Stop { get; } = new("stop"); 72public static ChatFinishReason Length { get; } = new("length"); 75public static ChatFinishReason ToolCalls { get; } = new("tool_calls"); 78public static ChatFinishReason ContentFilter { get; } = new("content_filter"); 86new(reader.GetString()!);
Microsoft.Extensions.AI.Abstractions.Tests (30)
ChatCompletion\ChatFinishReasonTests.cs (30)
15Assert.Equal("abc", new ChatFinishReason("abc").Value); 21Assert.Throws<ArgumentNullException>("value", () => new ChatFinishReason(null!)); 22Assert.Throws<ArgumentException>("value", () => new ChatFinishReason(" ")); 28Assert.True(new ChatFinishReason("abc").Equals(new ChatFinishReason("ABC"))); 29Assert.True(new ChatFinishReason("abc").Equals((object)new ChatFinishReason("ABC"))); 30Assert.True(new ChatFinishReason("abc") == new ChatFinishReason("ABC")); 31Assert.Equal(new ChatFinishReason("abc").GetHashCode(), new ChatFinishReason("ABC").GetHashCode()); 32Assert.False(new ChatFinishReason("abc") != new ChatFinishReason("ABC")); 34Assert.False(new ChatFinishReason("abc").Equals(new ChatFinishReason("def"))); 35Assert.False(new ChatFinishReason("abc").Equals((object)new ChatFinishReason("def"))); 36Assert.False(new ChatFinishReason("abc").Equals(null)); 37Assert.False(new ChatFinishReason("abc").Equals("abc")); 38Assert.False(new ChatFinishReason("abc") == new ChatFinishReason("def")); 39Assert.True(new ChatFinishReason("abc") != new ChatFinishReason("def")); 40Assert.NotEqual(new ChatFinishReason("abc").GetHashCode(), new ChatFinishReason("def").GetHashCode()); // not guaranteed due to possible hash code collisions 55Assert.Equal("test", new ChatFinishReason("test").Value); 56Assert.Equal("test", new ChatFinishReason("test").ToString()); 58Assert.Equal("TEST", new ChatFinishReason("TEST").Value); 59Assert.Equal("TEST", new ChatFinishReason("TEST").ToString()); 68ChatFinishReason role = new("abc");
Microsoft.Extensions.AI.AzureAIInference (1)
AzureAIInferenceChatClient.cs (1)
285new(s);
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
227_ => new ChatFinishReason(response.DoneReason),
Microsoft.Extensions.AI.OpenAI (1)
OpenAIChatClient.cs (1)
393_ => new ChatFinishReason(s),
80 references to ChatFinishReason
Microsoft.Extensions.AI (1)
ChatCompletion\OpenTelemetryChatClient.cs (1)
352if (completion.FinishReason is ChatFinishReason finishReason)
Microsoft.Extensions.AI.Abstractions (21)
ChatCompletion\ChatCompletion.cs (1)
71public ChatFinishReason? FinishReason { get; set; }
ChatCompletion\ChatFinishReason.cs (19)
15public readonly struct ChatFinishReason : IEquatable<ChatFinishReason> 20/// <summary>Initializes a new instance of the <see cref="ChatFinishReason"/> struct with a string that describes the reason.</summary> 34public override bool Equals([NotNullWhen(true)] object? obj) => obj is ChatFinishReason other && Equals(other); 37public bool Equals(ChatFinishReason other) => StringComparer.OrdinalIgnoreCase.Equals(Value, other.Value); 48public static bool operator ==(ChatFinishReason left, ChatFinishReason right) 59public static bool operator !=(ChatFinishReason left, ChatFinishReason right) 68/// <summary>Gets a <see cref="ChatFinishReason"/> representing the model encountering a natural stop point or provided stop sequence.</summary> 69public static ChatFinishReason Stop { get; } = new("stop"); 71/// <summary>Gets a <see cref="ChatFinishReason"/> representing the model reaching the maximum length allowed for the request and/or response (typically in terms of tokens).</summary> 72public static ChatFinishReason Length { get; } = new("length"); 74/// <summary>Gets a <see cref="ChatFinishReason"/> representing the model requesting the use of a tool that was defined in the request.</summary> 75public static ChatFinishReason ToolCalls { get; } = new("tool_calls"); 77/// <summary>Gets a <see cref="ChatFinishReason"/> representing the model filtering content, whether for safety, prohibited content, sensitive content, or other such issues.</summary> 78public static ChatFinishReason ContentFilter { get; } = new("content_filter"); 82public sealed class Converter : JsonConverter<ChatFinishReason> 85public override ChatFinishReason Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => 89public override void Write(Utf8JsonWriter writer, ChatFinishReason value, JsonSerializerOptions options) =>
ChatCompletion\StreamingChatCompletionUpdate.cs (1)
112public ChatFinishReason? FinishReason { get; set; }
Microsoft.Extensions.AI.Abstractions.Tests (21)
ChatCompletion\ChatCompletionTests.cs (9)
102completion.FinishReason = ChatFinishReason.ContentFilter; 103Assert.Equal(ChatFinishReason.ContentFilter, completion.FinishReason); 139FinishReason = ChatFinishReason.ContentFilter, 161Assert.Equal(ChatFinishReason.ContentFilter, result.FinishReason); 212FinishReason = ChatFinishReason.ContentFilter, 224Assert.Equal(ChatFinishReason.ContentFilter, update0.FinishReason); 261FinishReason = ChatFinishReason.ContentFilter, 274Assert.Equal(ChatFinishReason.ContentFilter, update0.FinishReason); 285Assert.Equal(ChatFinishReason.ContentFilter, update1.FinishReason);
ChatCompletion\ChatFinishReasonTests.cs (8)
46Assert.Equal("stop", ChatFinishReason.Stop.Value); 47Assert.Equal("length", ChatFinishReason.Length.Value); 48Assert.Equal("tool_calls", ChatFinishReason.ToolCalls.Value); 49Assert.Equal("content_filter", ChatFinishReason.ContentFilter.Value); 61Assert.Equal("stop", default(ChatFinishReason).Value); 62Assert.Equal("stop", default(ChatFinishReason).ToString()); 68ChatFinishReason role = new("abc"); 72ChatFinishReason? result = JsonSerializer.Deserialize(json, TestJsonSerializerContext.Default.ChatFinishReason);
ChatCompletion\StreamingChatCompletionUpdateTests.cs (4)
82update.FinishReason = ChatFinishReason.ContentFilter; 83Assert.Equal(ChatFinishReason.ContentFilter, update.FinishReason); 180FinishReason = ChatFinishReason.ContentFilter, 211Assert.Equal(ChatFinishReason.ContentFilter, result.FinishReason);
Microsoft.Extensions.AI.AzureAIInference (6)
AzureAIInferenceChatClient.cs (6)
152ChatFinishReason? finishReason = default; 279private static ChatFinishReason? ToFinishReason(CompletionsFinishReason? finishReason) => 281finishReason == CompletionsFinishReason.Stopped ? ChatFinishReason.Stop : 282finishReason == CompletionsFinishReason.TokenLimitReached ? ChatFinishReason.Length : 283finishReason == CompletionsFinishReason.ContentFiltered ? ChatFinishReason.ContentFilter : 284finishReason == CompletionsFinishReason.ToolCalls ? ChatFinishReason.ToolCalls :
Microsoft.Extensions.AI.AzureAIInference.Tests (6)
AzureAIInferenceChatClientTests.cs (6)
153Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 222Assert.Equal(i < 10 ? null : ChatFinishReason.Stop, updates[i].FinishReason); 331Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 415Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 520Assert.Equal(ChatFinishReason.ToolCalls, response.FinishReason); 620Assert.Equal(i < 7 ? null : ChatFinishReason.ToolCalls, updates[i].FinishReason);
Microsoft.Extensions.AI.Ollama (3)
OllamaChatClient.cs (3)
221private static ChatFinishReason? ToFinishReason(OllamaChatResponse response) => 225"length" => ChatFinishReason.Length, 226"stop" => ChatFinishReason.Stop,
Microsoft.Extensions.AI.Ollama.Tests (5)
OllamaChatClientTests.cs (5)
125Assert.Equal(ChatFinishReason.Length, response.FinishReason); 192Assert.Equal(i < updates.Count - 1 ? null : ChatFinishReason.Length, updates[i].FinishReason); 287Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 375Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 473Assert.Equal(ChatFinishReason.Stop, response.FinishReason);
Microsoft.Extensions.AI.OpenAI (6)
OpenAIChatClient.cs (6)
206ChatFinishReason? finishReason = null; 385private static ChatFinishReason? ToFinishReason(OpenAI.Chat.ChatFinishReason? finishReason) => 389OpenAI.Chat.ChatFinishReason.Stop => ChatFinishReason.Stop, 390OpenAI.Chat.ChatFinishReason.Length => ChatFinishReason.Length, 391OpenAI.Chat.ChatFinishReason.ContentFilter => ChatFinishReason.ContentFilter, 392OpenAI.Chat.ChatFinishReason.ToolCalls or OpenAI.Chat.ChatFinishReason.FunctionCall => ChatFinishReason.ToolCalls,
Microsoft.Extensions.AI.OpenAI.Tests (8)
OpenAIChatClientTests.cs (8)
196Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 271Assert.Equal(i < 10 ? null : ChatFinishReason.Stop, updates[i].FinishReason); 377Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 469Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 562Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 668Assert.Equal(ChatFinishReason.ToolCalls, response.FinishReason); 773Assert.Equal(i < 7 ? null : ChatFinishReason.ToolCalls, updates[i].FinishReason); 913Assert.Equal(ChatFinishReason.Stop, response.FinishReason);
Microsoft.Extensions.AI.Tests (2)
ChatCompletion\OpenTelemetryChatClientTests.cs (2)
45FinishReason = ChatFinishReason.Stop, 75FinishReason = ChatFinishReason.Stop,
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
52FinishReason = ChatFinishReason.Stop,