{"id":5308,"date":"2026-02-17T08:06:32","date_gmt":"2026-02-17T13:06:32","guid":{"rendered":"https:\/\/dft.wiki\/?p=5308"},"modified":"2026-03-04T20:36:23","modified_gmt":"2026-03-05T01:36:23","slug":"interacting-directly-with-ollamas-api","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=5308","title":{"rendered":"Interacting Directly with Ollama&#8217;s API"},"content":{"rendered":"<p>Directly interacting with a model through its API is the most effective way to integrate AI capabilities into real-world applications, services, and automation workflows.<\/p>\n<p>Among many other features, it can be safely integrated with CI pipelines to provide additional oversight to human code review and to improve the clarity, summarization, and readability of outputs.<\/p>\n<p>Note that I did not mention any sophisticated or advanced usage of AI in any agentic way, nor did I suggest anyone should grant it any autonomy. I do not believe the current AI tools have enough maturity for such trust.<\/p>\n<ul>\n<li><strong>cURL<\/strong><\/li>\n<li><strong>Python<\/strong><\/li>\n<li><strong>JavaScript<\/strong><\/li>\n<\/ul>\n<hr \/>\n<p><strong>CURL<\/strong><\/p>\n<p>Optionally, <strong>list models<\/strong> available remotely, via the API.<\/p>\n<pre>curl http:\/\/192.168.1.101:11434<strong>\/api\/tags<\/strong> | jq<\/pre>\n<p><strong>Pulling and deleting<\/strong> a model remotely.<\/p>\n<pre>curl http:\/\/192.168.1.101:11434\/api\/<strong>pull<\/strong> -d '{\r\n  \"model\": \"qwen2.5-coder:1.5b-base\",\r\n  \"stream\": false\r\n}'<\/pre>\n<pre>curl <strong>-X DELETE<\/strong> http:\/\/192.168.1.101:11434\/api\/<strong>delete<\/strong> -d '{\r\n  \"model\": \"qwen2.5-coder:1.5b-base\"\r\n}'<\/pre>\n<p>Refer to the official Ollama documentation for additional details and endpoints [<a href=\"https:\/\/docs.ollama.com\/api\/pull\">Link<\/a>].<\/p>\n<p><strong>Using<\/strong> a model remotely.<\/p>\n<p>In a previous post [<a href=\"https:\/\/dft.wiki\/?p=5270\">Link<\/a>], we installed Ollama and tested it with <code>curl<\/code> from a remote host using the following command.<\/p>\n<pre>curl -s http:\/\/192.168.1.101:11434\/api\/generate -d '{\r\n  \"model\": \"<strong>qwen2.5-coder:1.5b-base<\/strong>\",\r\n  \"prompt\": \"When was Python3 first released?\",\r\n  \"stream\": false\r\n}'<\/pre>\n<p>Example of output.<\/p>\n<pre>{\r\n  \"model\": \"qwen2.5-coder:1.5b-base\",\r\n  \"created_at\": \"2026-02-07T01:34:02.891211247Z\",\r\n  \"response\": \"\",\r\n  \"done\": true,\r\n  \"done_reason\": \"stop\",\r\n  \"context\": [\r\n    &lt;redacted_for_brevity&gt;\r\n  ],\r\n  \"total_duration\": 260501788901,\r\n  \"load_duration\": 2392809850,\r\n  \"prompt_eval_count\": 7,\r\n  \"prompt_eval_duration\": 687966008,\r\n  \"eval_count\": 1065,\r\n  \"eval_duration\": 253858547320\r\n}<\/pre>\n<p>Use <code>jq<\/code> to filter the response and <code>glow<\/code> for better rendering in the terminal. Also, combine instructions alongside the request.<\/p>\n<pre>curl -s http:\/\/192.168.1.101:11434\/api\/generate -d '{\r\n  \"model\": \"qwen2.5-coder:1.5b-base\",\r\n  \"prompt\": \"<strong>Instruction<\/strong>: Be brief, use markdown. \\n\\n <strong>Question<\/strong>: When was Python3 first released?\",\r\n  \"stream\": false\r\n}' | <strong>jq<\/strong> -r '.response' | <strong>glow<\/strong><\/pre>\n<p><strong>Explanation<\/strong><\/p>\n<ul>\n<li><strong>Instruction<\/strong>\n<ul>\n<li>System requirements, guidelines, controls.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Question<\/strong>\n<ul>\n<li>User inputs, questions, prompts.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Then, add some spice to the mix for more &#8220;creative&#8221; (unpredictable) responses.<\/p>\n<pre>curl -s http:\/\/192.168.1.101:11434\/api\/generate -d '{\r\n  \"model\": \"qwen2.5-coder:1.5b-base\",\r\n  \"prompt\": \"Instruction: Be brief, use markdown. \\n\\n Question: When was Python3 first released?\",\r\n  <strong>\"options\": [{\r\n    \"temperature\": 0.3,\r\n    \"num_predict\": 50,\r\n    \"top_p\": 0.9\r\n  }]<\/strong>,\r\n  \"stream\": false\r\n}' | jq -r '.response' | glow<\/pre>\n<p><strong>Explanation<\/strong><\/p>\n<ul>\n<li><strong>temperature<\/strong>\n<ul>\n<li>Controls randomness (0.0 is focused, 1.0+ is creative).<\/li>\n<\/ul>\n<\/li>\n<li><strong>num_predict<\/strong>\n<ul>\n<li>Limits the maximum tokens generated.<\/li>\n<\/ul>\n<\/li>\n<li><strong>top_p<\/strong>\n<ul>\n<li>Influences the diversity of the response.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Create a wrapper to facilitate calling it at any time from the terminal.<\/p>\n<pre>nano ai.sh &amp;&amp; chmod +x ai.sh<\/pre>\n<pre>#!\/bin\/bash\r\nAPI_URL=\"http:\/\/192.168.1.101:11434\/api\/generate\"\r\nMODEL=\"qwen2.5-coder:1.5b-base\"\r\nSYSTEM_INSTRUCTIONS=\"Instruction: Be brief, use a single paragraph, and use markdown.\"\r\n\r\nQUESTION=\"$*\"\r\nif [ -z \"$QUESTION\" ]; then\r\n    echo \"Usage: .\/ai.sh Tell me a joke about a turtle.\"\r\n    exit 1\r\nfi\r\n\r\nPAYLOAD=$(jq -n --arg model \"$MODEL\" --arg prompt \"$SYSTEM_INSTRUCTIONS \\n\\nQuestion: $QUESTION\" '{model: $model, prompt: $prompt, stream: false}')\r\ncurl -s \"$API_URL\" -d \"$PAYLOAD\" | jq -r 'select(.response != null) | .response' | xargs -0 printf '%b' | glow<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5275\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/02\/Screenshot_2026-02-07_16-42-55.png\" alt=\"\" width=\"665\" height=\"441\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/02\/Screenshot_2026-02-07_16-42-55.png 665w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/02\/Screenshot_2026-02-07_16-42-55-300x199.png 300w\" sizes=\"auto, (max-width: 665px) 100vw, 665px\" \/><\/p>\n<p>To run it from anywhere (also removing the unnecessary extension).<\/p>\n<pre>sudo mv ai.sh \/usr\/bin\/ai<\/pre>\n<p>If you prefer a chat-like experience, this will print token-by-token to the screen as they come in and disable reasoning.<\/p>\n<pre>#!\/bin\/bash\r\nAPI_URL=\"http:\/\/192.168.1.101:11434\/api\/chat\"\r\nMODEL=\"yi-coder:9b\"\r\nSYSTEM=\"Be brief, answer directly, and use literal newlines.\"\r\n\r\nUSER=\"$*\"\r\nif [ -z \"$USER\" ]; then\r\n    echo \"Usage: .\/ai.sh Tell me a joke about a turtle.\"\r\n    exit 1\r\nfi\r\n\r\n# Constructing the JSON with a messages array\r\nPAYLOAD=$(jq -n --arg model \"$MODEL\" --arg sys \"$SYSTEM\" --arg user \"$USER\" '{ model: $model, messages: [ {role: \"system\", content: $sys}, {role: \"user\", content: $user} ], <strong>stream: true, \"think\": false<\/strong> }')\r\n\r\necho '---'\r\ncurl -N -s \"$API_URL\" -d \"$PAYLOAD\" | jq --unbuffered -rnj 'inputs | .message.content' ; echo \"\"\r\necho '---'<\/pre>\n<hr \/>\n<p><strong>PYTHON<\/strong> [<a href=\"https:\/\/github.com\/ollama\/ollama-python\">Link<\/a>]<\/p>\n<p>Prepare the virtual environment.<\/p>\n<pre>sudo apt install python3-venv -y\r\npython3 -m venv .venv\r\nsource .venv\/bin\/activate\r\npip3 install ollama<\/pre>\n<p>Write the code.<\/p>\n<pre>#!\/usr\/bin\/env python3\r\nfrom ollama import Client\r\nclient = Client(<strong>host='http:\/\/192.168.1.101:11434'<\/strong>)\r\nresponse = client.chat(\r\n    model='<strong>yi-coder:9b<\/strong>',\r\n    messages=<strong>[{'role': 'user', 'content': 'Hello there!'}]<\/strong>,\r\n)\r\nprint(response.message.content)<\/pre>\n<p>Execute.<\/p>\n<pre>chmod +x ai.py\r\n.\/ai.py<\/pre>\n<hr \/>\n<p><strong>JAVASCRIPT<\/strong> [<a href=\"https:\/\/github.com\/ollama\/ollama-js\">Link<\/a>]<\/p>\n<pre>import { Ollama } from 'ollama'\r\nconst ollama = new Ollama({ <strong>host: 'http:\/\/192.168.1.101:11434'<\/strong> })\r\nasync function run() {\r\n  try {\r\n    const response = await ollama.chat({\r\n      model: '<strong>yi-coder:9b<\/strong>',\r\n      messages: <strong>[{ role: 'user', content: 'Hello there!' }]<\/strong>,\r\n    })\r\n    console.log(response.message.content)\r\n  } catch (error) {\r\n    console.error(\"Connection failed:\", error.message)\r\n  }\r\n}\r\nrun()<\/pre>\n<hr \/>\n<p><strong>CONTINUED CONVERSATION EXAMPLE<\/strong><\/p>\n<p>The following example was taken from packets captured between the VSCode extension &#8220;Continue&#8221; and the local module.<\/p>\n<p>The initial chat prompt is a request to create a function in Python. We can see the structure of the system plus user instructions.<\/p>\n<pre>{\r\n  \"model\": \"yi-coder:9b\",\r\n  \"messages\": [\r\n    {\r\n      \"role\": \"<strong>system<\/strong>\",\r\n      \"content\": \"\\n  You are in plan mode, in which you help the user understand and construct a plan.\\n  Only use read-only tools. Do not use any tools that would write to non-temporary files.\\n  If the user wants to make changes, offer that they can switch to Agent mode to give you access to write tools to make the suggested updates.\\n\\n  Always include the language and file name in the info string when you write code blocks.\\n  If you are editing \\\"src\/main.py\\\" for example, your code block should start with '```python src\/main.py'\\n\\n\\nFor larger codeblocks (&gt;20 lines), use brief language-appropriate placeholders for unmodified sections, e.g. '\/\/ ... existing code ...'\\n\\nHowever, only output codeblocks for suggestion and planning purposes. When ready to implement changes, request to switch to Agent mode.\\n\\n  In plan mode, only write code when directly suggesting changes. Prioritize understanding and developing a plan.\\n\\n\\n\\nYou have access to several \\\"tools\\\" that you can use at any time to retrieve information and\/or perform tasks for the User.\\nTo use a tool, respond with a tool code block (```tool) using the syntax shown in the examples below:\\n\\nThe following tools are available to you:\\n\\nTo read a file with a known filepath, use the read_file tool. For example, to read a file located at 'path\/to\/file.txt', you would respond with this:\\n```tool\\nTOOL_NAME: read_file\\nBEGIN_ARG: filepath\\npath\/to\/the_file.txt\\nEND_ARG\\n```\\n\\nTo return a list of files based on a glob search pattern, use the file_glob_search tool\\n```tool\\nTOOL_NAME: file_glob_search\\nBEGIN_ARG: pattern\\n*.py\\nEND_ARG\\n```\\n\\nTo view the current git diff, use the view_diff tool. This will show you the changes made in the working directory compared to the last commit.\\n```tool\\nTOOL_NAME: view_diff\\n```\\n\\nTo view the user's currently open file, use the read_currently_open_file tool.\\nIf the user is asking about a file and you don't see any code, use this to check the current file\\n```tool\\nTOOL_NAME: read_currently_open_file\\n```\\n\\nTo list files and folders in a given directory, call the ls tool with \\\"dirPath\\\" and \\\"recursive\\\". For example:\\n```tool\\nTOOL_NAME: ls\\nBEGIN_ARG: dirPath\\npath\/to\/dir\\nEND_ARG\\nBEGIN_ARG: recursive\\nfalse\\nEND_ARG\\n```\\n\\nTo fetch the content of a URL, use the fetch_url_content tool. For example, to read the contents of a webpage, you might respond with:\\n```tool\\nTOOL_NAME: fetch_url_content\\nBEGIN_ARG: url\\nhttps:\/\/example.com\\nEND_ARG\\n```\\n\\nTo search the web, use the search_web tool with a natural language query. For example, to search for the current weather, you would respond with:\\n```tool\\nTOOL_NAME: search_web\\nBEGIN_ARG: query\\nWhat is the current weather in San Francisco?\\nEND_ARG\\n```\\n\\nTo perform a grep search within the project, call the grep_search tool with the query pattern to match. For example:\\n```tool\\nTOOL_NAME: grep_search\\nBEGIN_ARG: query\\n.*main_services.*\\nEND_ARG\\n```\\n\\nAlso, these additional tool definitions show other tools you can call with the same syntax:\\n\\n```tool_definition\\nTOOL_NAME: read_file\\nTOOL_DESCRIPTION:\\nUse this tool if you need to view the contents of an existing file.\\nTOOL_ARG: filepath (string, required)\\nThe path of the file to read. Can be a relative path (from workspace root), absolute path, tilde path (~\/...), or file:\/\/ URI\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: file_glob_search\\nTOOL_DESCRIPTION:\\nSearch for files recursively in the project using glob patterns. Supports ** for recursive directory search. Will not show many build, cache, secrets dirs\/files (can use ls tool instead). Output may be truncated; use targeted patterns\\nTOOL_ARG: pattern (string, required)\\nGlob pattern for file path matching\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: view_diff\\nTOOL_DESCRIPTION:\\nView the current diff of working changes\\n```\\n\\n```tool_definition\\nTOOL_NAME: read_currently_open_file\\nTOOL_DESCRIPTION:\\nRead the currently open file in the IDE. If the user seems to be referring to a file that you can't see, or is requesting an action on content that seems missing, try using this tool.\\n```\\n\\n```tool_definition\\nTOOL_NAME: ls\\nTOOL_DESCRIPTION:\\nList files and folders in a given directory\\nTOOL_ARG: dirPath (string, optional)\\nThe directory path. Can be relative to project root, absolute path, tilde path (~\/...), or file:\/\/ URI. Use forward slash paths\\nEND_ARG\\nTOOL_ARG: recursive (boolean, optional)\\nIf true, lists files and folders recursively. To prevent unexpected large results, use this sparingly\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: fetch_url_content\\nTOOL_DESCRIPTION:\\nCan be used to view the contents of a website using a URL. Do NOT use this for files.\\nTOOL_ARG: url (string, required)\\nThe URL to read\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: read_skill\\nTOOL_DESCRIPTION:\\n\\nUse this tool to read the content of a skill by its name. Skills contain detailed instructions for specific tasks. The skill name should match one of the available skills listed below: \\n\\nTOOL_ARG: skillName (string, required)\\nThe name of the skill to read. This should match the name from the available skills.\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: search_web\\nTOOL_DESCRIPTION:\\nPerforms a web search, returning top results. Use this tool sparingly - only for questions that require specialized, external, and\/or up-to-date knowledege. Common programming questions do not require web search.\\nTOOL_ARG: query (string, required)\\nThe natural language search query\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: grep_search\\nTOOL_DESCRIPTION:\\nPerforms a regular expression (regex) search over the repository using ripgrep. Will not include results for many build, cache, secrets dirs\/files. Output may be truncated, so use targeted queries\\nTOOL_ARG: query (string, required)\\nThe regex pattern to search for within file contents. Use regex with alternation (e.g., 'word1|word2|word3') or character classes to find multiple potential words in a single search.\\nEND_ARG\\n```\\n\\nFor example, this tool definition:\\n\\n```tool_definition\\nTOOL_NAME: example_tool\\nTOOL_ARG: arg_1 (string, required)\\nDescription of the first argument\\nEND_ARG\\nTOOL_ARG: arg_2 (number, optional)\\nEND_ARG\\n```\\n\\nCan be called like this:\\n\\n```tool\\nTOOL_NAME: example_tool\\nBEGIN_ARG: arg_1\\nThe value\\nof arg 1\\nEND_ARG\\nBEGIN_ARG: arg_2\\n3\\nEND_ARG\\n```\\n\\nIf it seems like the User's request could be solved with one of the tools, choose the BEST one for the job based on the user's request and the tool descriptions\\nThen send the ```tool codeblock (YOU call the tool, not the user). Always start the codeblock on a new line.\\nDo not perform actions with\/for hypothetical files. Ask the user or use tools to deduce which files are relevant.\\nYou can only call ONE tool at at time. The tool codeblock should be the last thing you say; stop your response after the tool codeblock.\\n\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>user<\/strong>\",\r\n      \"content\": \"write a small function in python to sort words in a list.\"\r\n    }\r\n  ],\r\n  \"options\": { \"num_predict\": 4096, \"num_ctx\": 8192 },\r\n  \"think\": false,\r\n  \"keep_alive\": 1800\r\n}<\/pre>\n<p>This second instruction was produced by the extension for the module (not directly the user).<\/p>\n<pre>{\r\n  \"model\": \"yi-coder:9b\",\r\n  \"messages\": [\r\n    {\r\n      \"role\": \"<strong>user<\/strong>\",\r\n      \"content\": \"Given the following... please reply with a title for the chat that is 3-4 words in length, all words used should be directly related to the content of the chat, avoid using verbs unless they are directly related to the content of the chat, no additional text or explanation, you don't need ending punctuation.\\n\\nHere's an example of a simple Python function that sorts a list of words:\\n\\n\\nIn this function, we use Python's built-in `sorted()` function to sort the list of words. This function returns a new sorted list without modifying the original one. If you want to sort the list in place (i.e. modify the original list), you can instead use the `list.sort()` method:\\n```python\\ndef sort_words(word_list):\\n    word_list.sort()\\n    return word_list\"\r\n    }\r\n  ],\r\n  \"options\": { \"num_predict\": 16, \"num_ctx\": 8192 },\r\n  \"keep_alive\": 1800\r\n}<\/pre>\n<p>And, if another message is sent to the chat by the user, the full context is re-sent to the model because it does not &#8220;remember&#8221; previous interactions natively.<\/p>\n<pre>{\r\n  \"model\": \"yi-coder:9b\",\r\n  \"message\": [\r\n    {\r\n      \"role\": \"<strong>user<\/strong>\",\r\n      \"content\": \"write a small function in python to sort words in a list.\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>assistant<\/strong>\",\r\n      \"content\": \"Here's an example of a simple Python function that sorts a list of words:\\n\\n```python\\ndef sort_words(word_list):\\n    return sorted(word_list)\\n\\n# Example usage:\\nwords = [\\\"banana\\\", \\\"apple\\\", \\\"cherry\\\", \\\"date\\\", \\\"grape\\\"]\\nprint(sort_words(words))  # Outputs: ['apple', 'banana', 'cherry', 'date', 'grape']\\n```\\nIn this function, we use Python's built-in `sorted()` function to sort the list of words. This function returns a new sorted list without modifying the original one. If you want to sort the list in place (i.e. modify the original list), you can instead use the `list.sort()` method:\\n```python\\ndef sort_words(word_list):\\n    word_list.sort()\\n    return word_list\\n\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>user<\/strong>\",\r\n      \"content\": \"modify it to sort in reverse.\"\r\n    }\r\n  ],\r\n  \"options\": { \"num_predict\": 4096, \"num_ctx\": 8192 },\r\n  \"think\": false,\r\n  \"keep_alive\": 1800\r\n}<\/pre>\n<p>An additional message eventually contained <strong>&#8220;stop&#8221;<\/strong> parameters to define sequence termination.<\/p>\n<pre>{\r\n  \"model\": \"yi-coder:9b\",\r\n  \"messages\": [\r\n    {\r\n      \"role\": \"<strong>system<\/strong>\",\r\n      \"content\": \"\\n  You are in plan mode, in which you help the user understand and construct a plan.\\n  Only use read-only tools. Do not use any tools that would write to non-temporary files.\\n  If the user wants to make changes, offer that they can switch to Agent mode to give you access to write tools to make the suggested updates.\\n\\n  Always include the language and file name in the info string when you write code blocks.\\n  If you are editing \\\"src\/main.py\\\" for example, your code block should start with '```python src\/main.py'\\n\\n\\nFor larger codeblocks (&gt;20 lines), use brief language-appropriate placeholders for unmodified sections, e.g. '\/\/ ... existing code ...'\\n\\nHowever, only output codeblocks for suggestion and planning purposes. When ready to implement changes, request to switch to Agent mode.\\n\\n  In plan mode, only write code when directly suggesting changes. Prioritize understanding and developing a plan.\\n\\n\\n\\nYou have access to several \\\"tools\\\" that you can use at any time to retrieve information and\/or perform tasks for the User.\\nTo use a tool, respond with a tool code block (```tool) using the syntax shown in the examples below:\\n\\nThe following tools are available to you:\\n\\nTo read a file with a known filepath, use the read_file tool. For example, to read a file located at 'path\/to\/file.txt', you would respond with this:\\n```tool\\nTOOL_NAME: read_file\\nBEGIN_ARG: filepath\\npath\/to\/the_file.txt\\nEND_ARG\\n```\\n\\nTo return a list of files based on a glob search pattern, use the file_glob_search tool\\n```tool\\nTOOL_NAME: file_glob_search\\nBEGIN_ARG: pattern\\n*.py\\nEND_ARG\\n```\\n\\nTo view the current git diff, use the view_diff tool. This will show you the changes made in the working directory compared to the last commit.\\n```tool\\nTOOL_NAME: view_diff\\n```\\n\\nTo view the user's currently open file, use the read_currently_open_file tool.\\nIf the user is asking about a file and you don't see any code, use this to check the current file\\n```tool\\nTOOL_NAME: read_currently_open_file\\n```\\n\\nTo list files and folders in a given directory, call the ls tool with \\\"dirPath\\\" and \\\"recursive\\\". For example:\\n```tool\\nTOOL_NAME: ls\\nBEGIN_ARG: dirPath\\npath\/to\/dir\\nEND_ARG\\nBEGIN_ARG: recursive\\nfalse\\nEND_ARG\\n```\\n\\nTo fetch the content of a URL, use the fetch_url_content tool. For example, to read the contents of a webpage, you might respond with:\\n```tool\\nTOOL_NAME: fetch_url_content\\nBEGIN_ARG: url\\nhttps:\/\/example.com\\nEND_ARG\\n```\\n\\nTo search the web, use the search_web tool with a natural language query. For example, to search for the current weather, you would respond with:\\n```tool\\nTOOL_NAME: search_web\\nBEGIN_ARG: query\\nWhat is the current weather in San Francisco?\\nEND_ARG\\n```\\n\\nTo perform a grep search within the project, call the grep_search tool with the query pattern to match. For example:\\n```tool\\nTOOL_NAME: grep_search\\nBEGIN_ARG: query\\n.*main_services.*\\nEND_ARG\\n```\\n\\nAlso, these additional tool definitions show other tools you can call with the same syntax:\\n\\n```tool_definition\\nTOOL_NAME: read_file\\nTOOL_DESCRIPTION:\\nUse this tool if you need to view the contents of an existing file.\\nTOOL_ARG: filepath (string, required)\\nThe path of the file to read. Can be a relative path (from workspace root), absolute path, tilde path (~\/...), or file:\/\/ URI\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: file_glob_search\\nTOOL_DESCRIPTION:\\nSearch for files recursively in the project using glob patterns. Supports ** for recursive directory search. Will not show many build, cache, secrets dirs\/files (can use ls tool instead). Output may be truncated; use targeted patterns\\nTOOL_ARG: pattern (string, required)\\nGlob pattern for file path matching\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: view_diff\\nTOOL_DESCRIPTION:\\nView the current diff of working changes\\n```\\n\\n```tool_definition\\nTOOL_NAME: read_currently_open_file\\nTOOL_DESCRIPTION:\\nRead the currently open file in the IDE. If the user seems to be referring to a file that you can't see, or is requesting an action on content that seems missing, try using this tool.\\n```\\n\\n```tool_definition\\nTOOL_NAME: ls\\nTOOL_DESCRIPTION:\\nList files and folders in a given directory\\nTOOL_ARG: dirPath (string, optional)\\nThe directory path. Can be relative to project root, absolute path, tilde path (~\/...), or file:\/\/ URI. Use forward slash paths\\nEND_ARG\\nTOOL_ARG: recursive (boolean, optional)\\nIf true, lists files and folders recursively. To prevent unexpected large results, use this sparingly\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: fetch_url_content\\nTOOL_DESCRIPTION:\\nCan be used to view the contents of a website using a URL. Do NOT use this for files.\\nTOOL_ARG: url (string, required)\\nThe URL to read\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: read_skill\\nTOOL_DESCRIPTION:\\n\\nUse this tool to read the content of a skill by its name. Skills contain detailed instructions for specific tasks. The skill name should match one of the available skills listed below: \\n\\nTOOL_ARG: skillName (string, required)\\nThe name of the skill to read. This should match the name from the available skills.\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: search_web\\nTOOL_DESCRIPTION:\\nPerforms a web search, returning top results. Use this tool sparingly - only for questions that require specialized, external, and\/or up-to-date knowledege. Common programming questions do not require web search.\\nTOOL_ARG: query (string, required)\\nThe natural language search query\\nEND_ARG\\n```\\n\\n```tool_definition\\nTOOL_NAME: grep_search\\nTOOL_DESCRIPTION:\\nPerforms a regular expression (regex) search over the repository using ripgrep. Will not include results for many build, cache, secrets dirs\/files. Output may be truncated, so use targeted queries\\nTOOL_ARG: query (string, required)\\nThe regex pattern to search for within file contents. Use regex with alternation (e.g., 'word1|word2|word3') or character classes to find multiple potential words in a single search.\\nEND_ARG\\n```\\n\\nFor example, this tool definition:\\n\\n```tool_definition\\nTOOL_NAME: example_tool\\nTOOL_ARG: arg_1 (string, required)\\nDescription of the first argument\\nEND_ARG\\nTOOL_ARG: arg_2 (number, optional)\\nEND_ARG\\n```\\n\\nCan be called like this:\\n\\n```tool\\nTOOL_NAME: example_tool\\nBEGIN_ARG: arg_1\\nThe value\\nof arg 1\\nEND_ARG\\nBEGIN_ARG: arg_2\\n3\\nEND_ARG\\n```\\n\\nIf it seems like the User's request could be solved with one of the tools, choose the BEST one for the job based on the user's request and the tool descriptions\\nThen send the ```tool codeblock (YOU call the tool, not the user). Always start the codeblock on a new line.\\nDo not perform actions with\/for hypothetical files. Ask the user or use tools to deduce which files are relevant.\\nYou can only call ONE tool at at time. The tool codeblock should be the last thing you say; stop your response after the tool codeblock.\\n\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>user<\/strong>\",\r\n      \"content\": \"write a small function in python to sort words in a list.\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>assistant<\/strong>\",\r\n      \"content\": \"Here's an example of a simple Python function that sorts a list of words:\\n\\n```python\\ndef sort_words(word_list):\\n    return sorted(word_list)\\n\\n# Example usage:\\nwords = [\\\"banana\\\", \\\"apple\\\", \\\"cherry\\\", \\\"date\\\", \\\"grape\\\"]\\nprint(sort_words(words))  # Outputs: ['apple', 'banana', 'cherry', 'date', 'grape']\\n```\\nIn this function, we use Python's built-in `sorted()` function to sort the list of words. This function returns a new sorted list without modifying the original one. If you want to sort the list in place (i.e. modify the original list), you can instead use the `list.sort()` method:\\n```python\\ndef sort_words(word_list):\\n    word_list.sort()\\n    return word_list\\n\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>user<\/strong>\",\r\n      \"content\": \"modify it to sort in reverse.\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>assistant<\/strong>\",\r\n      \"content\": \"Sure, you can make the modification like this:\\n```python\\ndef sort_words(word_list):\\n    return sorted(word_list, reverse=True)\\n\\n# Example usage:\\nwords = [\\\"banana\\\", \\\"apple\\\", \\\"cherry\\\", \\\"date\\\", \\\"grape\\\"]\\nprint(sort_words(words))  # Outputs: ['grape', 'date', 'cherry', 'banana', 'apple']\\n\"\r\n    },\r\n    {\r\n      \"role\": \"<strong>user<\/strong>\",\r\n      \"content\": \"Now, discard the duplicated values.\"\r\n    }\r\n  ],\r\n  \"options\": {\r\n    \"num_predict\": 4096,\r\n<strong>    \"stop\": [\r\n      \"&lt;|endoftext|&gt;\",<\/strong>\r\n<strong>      \"&lt;|im_end|&gt;\",<\/strong>\r\n<strong>      \"&lt;fim_prefix&gt;\",<\/strong>\r\n<strong>      \"&lt;fim_suffix&gt;\",<\/strong>\r\n<strong>      \"&lt;fim_middle&gt;\"\r\n  ]<\/strong>,\r\n    \"num_ctx\": 8192\r\n  },\r\n  \"think\": false,\r\n  \"keep_alive\": 1800\r\n}<\/pre>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>It is recommended to download the models first and run them offline. It will prevent re-downloading assets or phoning home.<\/p>\n<pre>export TRANSFORMERS_OFFLINE=1\r\nexport HF_HUB_OFFLINE=1<\/pre>\n<p>When coding with Python, make sure you are using safetensors (more secure than <code>.bin<\/code>), and make sure that after downloading, it will only run offline.<\/p>\n<pre>pipe = &lt;Used_Function&gt;.from_pretrained(\r\n    \"&lt;Model_ID&gt;\",\r\n<strong>    cache_dir = \"\/models\",<\/strong>\r\n<strong>    local_files_only = True\r\n    use_safetensors = True<\/strong>\r\n)<\/pre>\n<p>Or disable safety checks, which improved performance slightly and allows unrestricted outputs.<\/p>\n<pre>pipe.safety_checker = None\r\npipe.feature_extractor = None\r\npipe.requires_safety_checker = False<\/pre>\n<hr \/>\n<p><strong>READ MORE<\/strong><\/p>\n<p><strong>Self-hosted AI Coder Model for VSCode<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=5270\">Link<\/a>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Directly interacting with a model through its API is the most effective way to integrate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-5308","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5308"}],"version-history":[{"count":12,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5308\/revisions"}],"predecessor-version":[{"id":5350,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5308\/revisions\/5350"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}