Enum TextGenerationResult.StopReason
- Namespace
- LMKit.TextGeneration
- Assembly
- LM-Kit.NET.dll
Enumerates the various reasons that can lead to the termination of a text completion task.
public enum TextGenerationResult.StopReason
Fields
Unknown = 0The reason for termination is unknown.
EndOfGeneration = 1Indicates that the end of the sequence has been reached.
MaxTokenLimitReached = 2Indicates that the maximum allowed number of tokens in the response has been reached.
StopSequenceDetected = 3Indicates stopping due to detection of content that should not be prompted for further processing.
ContextSizeLimitExceeded = 4Indicates that the context size limit has been reached, preventing further input processing.
CancellationRequested = 5Indicates that a cancellation has been requested.
NoLogits = 6Indicates that the model is unsuitable for tasks requiring logits, such as text completion.
ToolInvocationRequested = 7Indicates generation halted because the model emitted a tool call request. No further tokens should be produced until the tool is executed and its result is injected.
Examples
Example: Handle different stop reasons after generation
using LMKit.Model;
using LMKit.TextGeneration;
LM model = LM.LoadFromModelID("gemma3:4b");
var conversation = new SingleTurnConversation(model);
conversation.MaximumCompletionTokens = 100;
var result = conversation.Submit("Write a short essay on climate change.");
switch (result.TerminationReason)
{
case TextGenerationResult.StopReason.EndOfGeneration:
Console.WriteLine("Model finished naturally.");
break;
case TextGenerationResult.StopReason.MaxTokenLimitReached:
Console.WriteLine("Output was truncated at the token limit.");
break;
case TextGenerationResult.StopReason.StopSequenceDetected:
Console.WriteLine("A stop sequence was encountered.");
break;
default:
Console.WriteLine($"Stopped: {result.TerminationReason}");
break;
}