Skip to content

Tool use with Ollama models. #1068

Description

@Berkyx

using latest ollama version and tool capable models, executions of tool calls seems to be aborted.

Models are not keen to use tool calls, but could be encourage to at least attempt for one but result fails.

Image

opencode.json file;

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "qwen3:30b": {
            "name": "Qwen3:30b 65k MoE - local",
            "tools": true,
            "reasoning": true,
            "options": { "num_ctx": 65536 }
        },
        "devstral": {
            "name": "Devstral 14b Dense - local",
            "tools": true,
            "reasoning": false,
            "options": { "num_ctx": 131072 }
        }
      }
    },
    "moonshot": {
      "id": "moonshot",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.moonshot.cn/v1"
       },
      "models": {
        "kimi-k2-0711-preview": {
          "name": "kimi-k2-0711-preview",
          "cost": {
            "input": 0.001953125,
            "output": 0.009765625
          }
        }
      }
    }
  }
}

My hack to have this work on NixOS.

{ pkgs, ... }:

let
  opencodeBin = "/home/berkay/.opencode/bin/opencode";
  configSource = "/home/berkay/.config/opencode/providers/opencode.json";
  authSource = "/home/berkay/.local/share/opencode/auth.json";
  wrapper = pkgs.writeShellScriptBin "opencode" ''
    #!${pkgs.bash}/bin/bash

    CONFIG_SOURCE="${configSource}"
    CONFIG_LINK="./opencode.json"
    AUTH_SOURCE="${authSource}"
    AUTH_LINK="./auth.json"
    
    # Symlink config if not present
    CLEANUP_CONFIG_SYMLINK=0
    if [ ! -f "$CONFIG_LINK" ]; then
      ln -s "$CONFIG_SOURCE" "$CONFIG_LINK"
      CLEANUP_CONFIG_SYMLINK=1
    fi
    # Symlink auth if not present
    CLEANUP_AUTH_SYMLINK=0
    if [ ! -f "$AUTH_LINK" ]; then
      ln -s "$AUTH_SOURCE" "$AUTH_LINK"
      CLEANUP_AUTH_SYMLINK=1
    fi
    # Run opencode
    if [ -x "${opencodeBin}" ]; then
      ${pkgs.steam-run}/bin/steam-run "${opencodeBin}" "$@"
      STATUS=$?
    else
      echo "Error: opencode binary not found at ${opencodeBin}"
      exit 1
    fi
    # Remove symlinks if we created them
    if [ "$CLEANUP_CONFIG_SYMLINK" = "1" ]; then
      rm -f "$CONFIG_LINK"
    fi
    if [ "$CLEANUP_AUTH_SYMLINK" = "1" ]; then
      rm -f "$AUTH_LINK"
    fi
    exit $STATUS
  '';
in
{
  home.packages = [
    pkgs.steam-run
    wrapper
  ];

  xdg.desktopEntries.opencode = {
    name = "OpenCode";
    comment = "AI Coding Agent TUI";
    exec = "opencode";
    icon = "utilities-terminal";
    categories = [ "Development" ];
    terminal = true;
    startupNotify = false;
  };

  xdg.enable = true;
} 

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions