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)
287new(s);
Microsoft.Extensions.AI.Ollama (1)
OllamaChatClient.cs (1)
227_ => new ChatFinishReason(response.DoneReason),
Microsoft.Extensions.AI.OpenAI (1)
OpenAIModelMapper.ChatCompletion.cs (1)
566_ => new ChatFinishReason(s),
86 references to ChatFinishReason
Microsoft.Extensions.AI (1)
ChatCompletion\OpenTelemetryChatClient.cs (1)
366if (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)
154ChatFinishReason? finishReason = default; 281private static ChatFinishReason? ToFinishReason(CompletionsFinishReason? finishReason) => 283finishReason == CompletionsFinishReason.Stopped ? ChatFinishReason.Stop : 284finishReason == CompletionsFinishReason.TokenLimitReached ? ChatFinishReason.Length : 285finishReason == CompletionsFinishReason.ContentFiltered ? ChatFinishReason.ContentFilter : 286finishReason == CompletionsFinishReason.ToolCalls ? ChatFinishReason.ToolCalls :
Microsoft.Extensions.AI.AzureAIInference.Tests (6)
AzureAIInferenceChatClientTests.cs (6)
166Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 241Assert.Equal(i < 10 ? null : ChatFinishReason.Stop, updates[i].FinishReason); 530Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 664Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 777Assert.Equal(ChatFinishReason.ToolCalls, response.FinishReason); 872Assert.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 (10)
OpenAIModelMapper.ChatCompletion.cs (9)
558private static ChatFinishReason? FromOpenAIFinishReason(OpenAI.Chat.ChatFinishReason? finishReason) => 562OpenAI.Chat.ChatFinishReason.Stop => ChatFinishReason.Stop, 563OpenAI.Chat.ChatFinishReason.Length => ChatFinishReason.Length, 564OpenAI.Chat.ChatFinishReason.ContentFilter => ChatFinishReason.ContentFilter, 565OpenAI.Chat.ChatFinishReason.ToolCalls or OpenAI.Chat.ChatFinishReason.FunctionCall => ChatFinishReason.ToolCalls, 570private static OpenAI.Chat.ChatFinishReason ToOpenAIFinishReason(ChatFinishReason? finishReason) => 571finishReason == ChatFinishReason.Length ? OpenAI.Chat.ChatFinishReason.Length : 572finishReason == ChatFinishReason.ContentFilter ? OpenAI.Chat.ChatFinishReason.ContentFilter : 573finishReason == ChatFinishReason.ToolCalls ? OpenAI.Chat.ChatFinishReason.ToolCalls :
OpenAIModelMappers.StreamingChatCompletion.cs (1)
70ChatFinishReason? finishReason = null;
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIChatClientTests.cs (8)
196Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 277Assert.Equal(i < 10 ? null : ChatFinishReason.Stop, updates[i].FinishReason); 445Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 543Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 642Assert.Equal(ChatFinishReason.Stop, response.FinishReason); 754Assert.Equal(ChatFinishReason.ToolCalls, response.FinishReason); 867Assert.Equal(i < 7 ? null : ChatFinishReason.ToolCalls, updates[i].FinishReason); 1013Assert.Equal(ChatFinishReason.Stop, response.FinishReason);
OpenAISerializationTests.cs (2)
457FinishReason = ChatFinishReason.Stop, 601FinishReason = i == 4 ? ChatFinishReason.Stop : null,
Microsoft.Extensions.AI.Tests (2)
ChatCompletion\OpenTelemetryChatClientTests.cs (2)
45FinishReason = ChatFinishReason.Stop, 80FinishReason = ChatFinishReason.Stop,
Microsoft.ML.GenAI.Core (1)
CausalLMPipelineChatClient.cs (1)
52FinishReason = ChatFinishReason.Stop,