Created
October 6, 2025 16:03
-
-
Save larkintuckerllc/0998d23c09cd170764cd921d0b284b8e to your computer and use it in GitHub Desktop.
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
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "id": "03173be0", | |
| "metadata": {}, | |
| "source": [ | |
| "# imports" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "94a93c74", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from ollama import chat, web_fetch, web_search" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "fc9844ec", | |
| "metadata": {}, | |
| "source": [ | |
| "# constants" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "bcf2258c", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "MODEL = \"qwen3:8b\"\n", | |
| "QUESTION = \"In the context of Ollama, what are 'thinking' models? Please answer in three paragraphs or less.\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "id": "f823bccd", | |
| "metadata": {}, | |
| "source": [ | |
| "# chat" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "id": "997434c7", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "Thinking: Okay, the user is asking about 'thinking' models in the context of Ollama. I need to figure out what exactly they mean. First, I should recall what Ollama is. Ollama is a framework for running large language models locally. Now, 'thinking' models might refer to models that are designed to simulate or exhibit reasoning processes. But I'm not entirely sure, so maybe I should check if there's any official documentation or articles about this term in Ollama.\n", | |
| "\n", | |
| "Wait, the user might be referring to models that have specific features for reasoning or problem-solving. Alternatively, maybe it's about models that are trained to think step-by-step, which is a common concept in AI research. I should verify if Ollama has any models categorized as 'thinking' or if there's a particular feature they're highlighting. Since I don't have access to Ollama's internal documentation, I should use the web_search function to look up information on 'thinking models in Ollama'.\n", | |
| "\n", | |
| "Let me perform a web search with the query \"thinking models Ollama\" to find relevant sources. The results might explain if Ollama has specific models with such a designation. If there are no direct mentions, I might need to infer based on general AI concepts and how they apply to Ollama's models. Alternatively, the term could be a misunderstanding, and the user might be referring to models that support reasoning or have certain capabilities. I'll need to present the information I find and clarify if there's a specific context or if it's a general concept.\n", | |
| "\n", | |
| "Tool calls: [ToolCall(function=Function(name='web_search', arguments={'max_results': 3, 'query': 'thinking models Ollama'}))]\n", | |
| "Result: results=[WebSearchResult(content='# Thinking\\n\\n## May 30, 2025\\n\\nOllama now has the ability to enable or disable thinking. This gives users the flexibility to choose the model’s thinking behavior fo...\n", | |
| "Thinking: Okay, the user asked about 'thinking' models in Ollama. Let me start by looking at the search results. The first result from the Ollama blog explains that Ollama now has a feature to enable or disable thinking. When thinking is enabled, the model's thought process is separated from the output, which can help in applications needing step-by-step reasoning. The models that support this include DeepSeek R1 and Qwen 3. \n", | |
| "\n", | |
| "The second result is from a Medium article, which seems to be about the same feature. It mentions Ollama's new thinking mode, allowing users to see the model's reasoning process. The article also talks about how this can be used in different scenarios, like interactive sessions or scripting, with examples in CLI, API, and Python libraries.\n", | |
| "\n", | |
| "Putting this together, 'thinking' models in Ollama refer to models that can be configured to show their reasoning steps before providing an answer. This feature is available in specific models like DeepSeek R1 and Qwen 3. Users can enable or disable this behavior via CLI commands, API parameters, or library functions. The main benefit is enhanced transparency and the ability to use the model's reasoning for more complex tasks. I should structure the answer to explain what thinking models are, how they work, and provide examples of models and usage methods.\n", | |
| "\n", | |
| "Content: In the context of Ollama, **'thinking' models** refer to language models that can be configured to explicitly separate their internal reasoning process from the final output. This feature allows users to observe how the model arrives at answers, enabling greater transparency and control over its behavior. For example, when enabled, the model might articulate its step-by-step logic before providing the result, which is particularly useful for tasks requiring detailed explanations or validation.\n", | |
| "\n", | |
| "Ollama supports this functionality through specific models like **DeepSeek R1** and **Qwen 3**, which can be instructed to \"think\" via command-line flags (e.g., `--think`), API parameters (e.g., `think: true`), or library methods (e.g., Python/JavaScript examples). Enabling thinking can enhance applications like educational tools, debugging interfaces, or games with \"thinking bubbles\" for NPCs. However, it may slow responses, so disabling it (`--think=false`) prioritizes speed for straightforward queries.\n", | |
| "\n", | |
| "The key distinction lies in **flexibility**: users can toggle thinking mode based on use cases, balancing between detailed reasoning and rapid output. This aligns with Ollama's broader goal of making large models accessible for diverse applications, from local development to creative projects.\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "available_tools = {'web_search': web_search, 'web_fetch': web_fetch}\n", | |
| "messages = [{'role': 'user', 'content': QUESTION}]\n", | |
| "while True:\n", | |
| " response = chat(\n", | |
| " model=MODEL,\n", | |
| " messages=messages,\n", | |
| " tools=[web_search, web_fetch],\n", | |
| " think=True\n", | |
| " )\n", | |
| " if response.message.thinking:\n", | |
| " print('Thinking: ', response.message.thinking)\n", | |
| " if response.message.content:\n", | |
| " print('Content: ', response.message.content)\n", | |
| " messages.append(response.message)\n", | |
| " if response.message.tool_calls:\n", | |
| " print('Tool calls: ', response.message.tool_calls)\n", | |
| " for tool_call in response.message.tool_calls:\n", | |
| " function_to_call = available_tools.get(tool_call.function.name)\n", | |
| " if function_to_call:\n", | |
| " args = tool_call.function.arguments\n", | |
| " result = function_to_call(**args)\n", | |
| " print('Result: ', str(result)[:200]+'...')\n", | |
| " # Result is truncated for limited context lengths\n", | |
| " messages.append({'role': 'tool', 'content': str(result)[:2000 * 4], 'tool_name': tool_call.function.name})\n", | |
| " else:\n", | |
| " messages.append({'role': 'tool', 'content': f'Tool {tool_call.function.name} not found', 'tool_name': tool_call.function.name})\n", | |
| " else:\n", | |
| " break" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "jupytext": { | |
| "formats": "ipynb,py:percent" | |
| }, | |
| "kernelspec": { | |
| "display_name": "Example", | |
| "language": "python", | |
| "name": "example" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.13.3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment