{"record":{"id":"cb6caab271cd7d8a","repo":"2noise/ChatTTS","slug":"frequency-penalty-must-be-in-2-2-got-self-fr","errorCode":null,"errorMessage":"frequency_penalty must be in [-2, 2], got {self.frequency_penalty}.","messagePattern":"frequency_penalty must be in \\[-2, 2\\], got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ChatTTS/model/velocity/sampling_params.py","lineNumber":193,"sourceCode":"            #     self.top_p = 1.0\n            #     self.top_k = -1\n            #     self.min_p = 0.0\n            #     self._verify_greedy_sampling()\n\n    def _verify_args(self) -> None:\n        if self.n < 1:\n            raise ValueError(f\"n must be at least 1, got {self.n}.\")\n        if self.best_of < self.n:\n            raise ValueError(\n                f\"best_of must be greater than or equal to n, \"\n                f\"got n={self.n} and best_of={self.best_of}.\"\n            )\n        if not -2.0 <= self.presence_penalty <= 2.0:\n            raise ValueError(\n                \"presence_penalty must be in [-2, 2], got \" f\"{self.presence_penalty}.\"\n            )\n        if not -2.0 <= self.frequency_penalty <= 2.0:\n            raise ValueError(\n                \"frequency_penalty must be in [-2, 2], got \"\n                f\"{self.frequency_penalty}.\"\n            )\n        if not 0.0 < self.repetition_penalty <= 2.0:\n            raise ValueError(\n                \"repetition_penalty must be in (0, 2], got \"\n                f\"{self.repetition_penalty}.\"\n            )\n        # if self.temperature < 0.0:\n        #     raise ValueError(\n        #         f\"temperature must be non-negative, got {self.temperature}.\")\n        if not 0.0 < self.top_p <= 1.0:\n            raise ValueError(f\"top_p must be in (0, 1], got {self.top_p}.\")\n        if self.top_k < -1 or self.top_k == 0:\n            raise ValueError(\n                f\"top_k must be -1 (disable), or at least 1, \" f\"got {self.top_k}.\"\n            )\n        if not 0.0 <= self.min_p <= 1.0:","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/2noise/ChatTTS/blob/77b89ee281cd479f5b1a787ada330dc975ca1f2a/ChatTTS/model/velocity/sampling_params.py#L175-L211","documentation":"SamplingParams._verify_args enforces frequency_penalty in the inclusive range [-2, 2], mirroring the OpenAI API. frequency_penalty penalizes tokens proportionally to how often they already occurred.","triggerScenarios":"Constructing SamplingParams with frequency_penalty outside [-2.0, 2.0], e.g. 5.0, -2.1, or a value read unvalidated from config.","commonSituations":"Same shape as presence_penalty: unvalidated request payloads, config typos, porting penalties from libraries with different ranges.","solutions":["Clamp frequency_penalty to [-2, 2] before constructing SamplingParams","Validate the value at your API/config boundary"],"exampleFix":"# before\nparams = SamplingParams(frequency_penalty=5.0)\n\n# after\nparams = SamplingParams(frequency_penalty=1.5)","handlingStrategy":"validation","validationCode":"def clamp_penalty(v: float) -> float:\n    return min(max(float(v), -2.0), 2.0)","typeGuard":"def is_valid_penalty(v) -> bool:\n    return isinstance(v, (int, float)) and -2.0 <= v <= 2.0","tryCatchPattern":null,"preventionTips":["Clamp frequency_penalty to [-2, 2] at the request boundary","Reject penalties outside the OpenAI-compatible range in schema validation"],"tags":["sampling-params","validation","frequency-penalty","llm-generation"],"backgroundTag":"penalty-out-of-range","analyzedSha":"77b89ee281cd479f5b1a787ada330dc975ca1f2a","analyzedAt":"2026-08-26T17:48:24.233Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}