This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| PydanticAI + Ollama: Controlling Thinking (Reasoning) on/off | |
| ============================================================= | |
| Problem: | |
| Ollama's OpenAI-compatible API (/v1/chat/completions) auto-enables thinking | |
| for thinking-capable models (like qwen3.5). There is NO `think: true/false` | |
| parameter on the OpenAI-compat API — that only works on Ollama's native | |
| API (/api/chat). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Function to check if an environment variable is set | |
| check_env_variable() { | |
| local var_name="$1" | |
| local var_desc="$2" | |
| if [ -z "${!var_name}" ]; then | |
| echo "Error: '${var_name}' environment variable is not set. Please set it to ${var_desc}." | |
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Function to check if an environment variable is set | |
| check_env_variable() { | |
| local var_name="$1" | |
| local var_desc="$2" | |
| if [ -z "${!var_name}" ]; then | |
| echo "Error: '${var_name}' environment variable is not set. Please set it to ${var_desc}." | |
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| P = ParamSpec("P") | |
| RT = TypeVar("RT") | |
| # By using ParamSpec, you are able to capture the original function's args and kwargs and forward | |
| # them through the decorator in a way that static analyzes like MyPy, and also ide's like PyCharm | |
| # will be happy ;-) | |
| def your_decorator(f: Callable[P, RT]) -> Callable[P, RT]: | |
| @wraps(f) | |
| def decorated_function(*args: P.args, **kwargs: P.kwargs) -> RT: |