namespace AIStudio.Provider.Reasoning.Dialects;
///
/// The reasoning mode and budget of the llama.cpp server.
///
///
/// Its "reasoning" key is a mode rather than an object, and one of its three values means neither
/// yes nor no: "auto" hands the decision to the model's own template, which is exactly the case
/// where nobody has decided anything.
///
public sealed class LlamaCppReasoningDialect : IReasoningDialect
{
///
public ReasoningDialect Dialect => ReasoningDialect.LLAMA_CPP;
///
public ReasoningConfigurationState Detect(IDictionary parameters)
{
var states = new List();
if (ReasoningParameters.TryGet(parameters, "reasoning", out var reasoning))
states.Add(ModeOf(reasoning));
if (ReasoningParameters.TryGet(parameters, "reasoning_budget", out var reasoningBudget))
states.Add(ReasoningParameters.BudgetOf(reasoningBudget));
if (ReasoningParameters.TryGet(parameters, "chat_template_kwargs", out var chatTemplateKwargs) &&
chatTemplateKwargs is IDictionary chatTemplateKwargsObject)
states.Add(QwenThinkingDialect.In(chatTemplateKwargsObject));
return ReasoningParameters.Merge(states);
}
///
/// Reads the reasoning mode.
///
/// The configured mode.
/// What it says, which for "auto" is nothing.
private static ReasoningConfigurationState ModeOf(object? value) => value switch
{
string text when text.Equals("on", StringComparison.OrdinalIgnoreCase) => ReasoningConfigurationState.EXPLICITLY_ENABLED,
string text when text.Equals("off", StringComparison.OrdinalIgnoreCase) => ReasoningConfigurationState.EXPLICITLY_DISABLED,
string text when text.Equals("auto", StringComparison.OrdinalIgnoreCase) => ReasoningConfigurationState.NOT_CONFIGURED,
_ => ReasoningParameters.LevelOf(value),
};
}