{"record":{"id":"482aa6249241085e","repo":"xtekky/gpt4free","slug":"invalid-thinking-mode-think-value-r","errorCode":null,"errorMessage":"Invalid thinking mode: {think_value!r}","messagePattern":"Invalid thinking mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/Gemini.py","lineNumber":250,"sourceCode":"            ) from exc\n        buffer += chunk\n        while b\"\\n\" in buffer:\n            line, buffer = buffer.split(b\"\\n\", 1)\n            yield line.decode(\"utf-8\", errors=\"replace\")\n    if buffer:\n        yield buffer.decode(\"utf-8\", errors=\"replace\")\n\n\ndef _resolve_model(model: str, think_override: int = None) -> tuple[str, bool]:\n    requested_model = model\n    think_mode = think_override\n    if \"@think=\" in model:\n        model, think_value = model.rsplit(\"@think=\", 1)\n        requested_model = model\n        try:\n            think_mode = int(think_value)\n        except ValueError as exc:\n            raise ValueError(f\"Invalid thinking mode: {think_value!r}\") from exc\n    if think_mode is not None:\n        if not isinstance(think_mode, int) or not 0 <= think_mode <= 4:\n            raise ValueError(\"Thinking mode must be an integer between 0 and 4\")\n    model = MODEL_ALIASES.get(model, model)\n    if model not in models:\n        raise ValueError(\n            f\"Unknown Gemini model: {model}. \" f\"Supported models: {', '.join(models)}\"\n        )\n    expanded_thinking = (\n        requested_model in EXPANDED_MODEL_ALIASES\n        if think_mode is None\n        else think_mode <= 2\n    )\n    return model, expanded_thinking\n\n\ndef _normalize_messages(messages: Messages | None) -> Messages:\n    if messages is None:","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/Gemini.py#L232-L268","documentation":"ValueError from Gemini._resolve_model when the model string uses the @think= suffix syntax (e.g. \"gemini-2.5-flash@think=high\") but the value after @think= is not parseable as an integer. The code does int(think_value) and converts the resulting ValueError into a descriptive one; think levels must be numeric (0-4).","triggerScenarios":"Passing a model like \"gemini@think=high\" or \"gemini@think=true\" — any non-integer think value. The rsplit on \"@think=\" succeeds so parsing is attempted and fails.","commonSituations":"Assuming textual levels (low/medium/high) are supported; typos like @think=2.5 (float string) or trailing whitespace; copying model names from docs of a different library.","solutions":["Use an integer: \"gemini-2.5-flash@think=2\".","Or drop the suffix entirely and use the think_override parameter instead.","Strip whitespace/typos from the suffix value."],"exampleFix":"# before\nmodel = \"gemini-2.5-flash@think=high\"  # ValueError: Invalid thinking mode: 'high'\n\n# after\nmodel = \"gemini-2.5-flash@think=2\"","handlingStrategy":"validation","validationCode":"import re\n\ndef valid_think_suffix(model: str) -> bool:\n    m = re.search(r\"@think=(.+)$\", model)\n    if not m:\n        return True\n    return m.group(1).strip().lstrip(\"-\").isdigit()\n\nassert valid_think_suffix(requested_model), f\"bad @think= suffix: {requested_model}\"","typeGuard":"def is_valid_think_model(model: str) -> bool:\n    if \"@think=\" not in model:\n        return True\n    value = model.rsplit(\"@think=\", 1)[1]\n    return value.isdigit() and 0 <= int(value) <= 4","tryCatchPattern":"try:\n    resp = await client.chat.completions.create(model=m, provider=Gemini, messages=msgs)\nexcept ValueError as e:\n    if \"Invalid thinking mode\" in str(e):\n        m = m.rsplit(\"@think=\", 1)[0]","preventionTips":["Validate @think= suffixes as integers 0-4 before calling the API.","Expose a numeric think-level setting in your config instead of free text.","Unit-test model-string parsing if users can configure it."],"tags":["validation","gemini","model-name","configuration"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}