| 1 | import '../../../../core/constants/app_constants.dart'; |
| 2 | import '../../providers/chat_reasoning_providers.dart'; |
| 3 | |
| 4 | class ChatParameters { |
| 5 | final double temperature; |
| 6 | final double topP; |
| 7 | final int maxTokens; |
| 8 | final int contextLength; |
| 9 | final String? systemPrompt; |
| 10 | final int? topK; |
| 11 | final double? minP; |
| 12 | final double? repeatPenalty; |
| 13 | |
| 14 | /// When false, remote chat services omit the field from the request body. |
| 15 | /// Local runtimes always use the value. |
| 16 | final bool sendTemperature; |
| 17 | final bool sendTopP; |
| 18 | |
| 19 | /// Null when the active model doesn't support reasoning (no reasoning |
| 20 | /// control fields should be sent); otherwise reflects the Think toggle. |
| 21 | final bool? reasoningEnabled; |
| 22 | final ReasoningEffort reasoningEffort; |
| 23 | |
| 24 | /// Raw reasoning `allowed_options` for the active model (e.g. LM Studio |
| 25 | /// `["low","medium","high","xhigh"]`, `["off","on"]`; Ollama binary |
| 26 | /// `["off","on"]` or GPT-OSS `["low","medium","high"]`). Null when unknown |
| 27 | /// (legacy servers) or for providers without per-model options. Lets |
| 28 | /// [LMStudioChatService] and Ollama send exactly what the server advertises |
| 29 | /// and omit the key when `off` isn't allowed instead of triggering HTTP 400. |
| 30 | final List<String>? reasoningAllowedOptions; |
| 31 | |
| 32 | /// Raw reasoning default for the active model. Used as a tie-breaker when |
| 33 | /// snapping efforts. |
| 34 | final String? reasoningDefaultOption; |
| 35 | |
| 36 | const ChatParameters({ |
| 37 | required this.temperature, |
| 38 | required this.topP, |
| 39 | required this.maxTokens, |
| 40 | required this.contextLength, |
| 41 | this.systemPrompt, |
| 42 | this.topK, |
| 43 | this.minP, |
| 44 | this.repeatPenalty, |
| 45 | this.sendTemperature = true, |
| 46 | this.sendTopP = true, |
| 47 | this.reasoningEnabled, |
| 48 | this.reasoningEffort = ReasoningEffort.low, |
| 49 | this.reasoningAllowedOptions, |
| 50 | this.reasoningDefaultOption, |
| 51 | }); |
| 52 | |
| 53 | factory ChatParameters.defaults() => const ChatParameters( |
| 54 | temperature: AppConstants.defaultTemperature, |
| 55 | topP: AppConstants.defaultTopP, |
| 56 | maxTokens: AppConstants.defaultMaxTokens, |
| 57 | contextLength: AppConstants.defaultContextLength, |
| 58 | ); |
| 59 | |
| 60 | ChatParameters copyWith({ |
| 61 | double? temperature, |
| 62 | double? topP, |
| 63 | int? maxTokens, |
| 64 | int? contextLength, |
| 65 | String? systemPrompt, |
| 66 | int? topK, |
| 67 | double? minP, |
| 68 | double? repeatPenalty, |
| 69 | bool? sendTemperature, |
| 70 | bool? sendTopP, |
| 71 | bool? reasoningEnabled, |
| 72 | ReasoningEffort? reasoningEffort, |
| 73 | List<String>? reasoningAllowedOptions, |
| 74 | String? reasoningDefaultOption, |
| 75 | }) { |
| 76 | return ChatParameters( |
| 77 | temperature: temperature ?? this.temperature, |
| 78 | topP: topP ?? this.topP, |
| 79 | maxTokens: maxTokens ?? this.maxTokens, |
| 80 | contextLength: contextLength ?? this.contextLength, |
| 81 | systemPrompt: systemPrompt ?? this.systemPrompt, |
| 82 | topK: topK ?? this.topK, |
| 83 | minP: minP ?? this.minP, |
| 84 | repeatPenalty: repeatPenalty ?? this.repeatPenalty, |
| 85 | sendTemperature: sendTemperature ?? this.sendTemperature, |
| 86 | sendTopP: sendTopP ?? this.sendTopP, |
| 87 | reasoningEnabled: reasoningEnabled ?? this.reasoningEnabled, |
| 88 | reasoningEffort: reasoningEffort ?? this.reasoningEffort, |
| 89 | reasoningAllowedOptions: |
| 90 | reasoningAllowedOptions ?? this.reasoningAllowedOptions, |
| 91 | reasoningDefaultOption: |
| 92 | reasoningDefaultOption ?? this.reasoningDefaultOption, |
| 93 | ); |
| 94 | } |
| 95 | } |