namespace AIStudio.Provider.Reasoning.Dialects; /// /// The "enable_thinking" switch Qwen introduced and other servers took over. /// /// /// It is accepted at the top level and inside "chat_template_kwargs", because it is really an /// argument to the chat template rather than to the API -- which is also why two other dialects ask /// this one about their own kwargs object instead of repeating the two keys. /// public sealed class QwenThinkingDialect : IReasoningDialect { /// public ReasoningDialect Dialect => ReasoningDialect.QWEN_THINKING; /// public ReasoningConfigurationState Detect(IDictionary parameters) => In(parameters); /// /// Reads the switch out of any parameter object, which need not be the top-level one. /// /// The object to look in. /// What it says. public static ReasoningConfigurationState In(IDictionary parameters) { var states = new List(); if (ReasoningParameters.TryGet(parameters, "enable_thinking", out var enableThinking)) states.Add(ReasoningParameters.LevelOf(enableThinking)); if (ReasoningParameters.TryGet(parameters, "chat_template_kwargs", out var chatTemplateKwargs) && chatTemplateKwargs is IDictionary chatTemplateKwargsObject && ReasoningParameters.TryGet(chatTemplateKwargsObject, "enable_thinking", out var nestedEnableThinking)) states.Add(ReasoningParameters.LevelOf(nestedEnableThinking)); return ReasoningParameters.Merge(states); } }