utils

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package utils provides utility functions for MCPShell

Package utils provides utility functions for testing and development

Package utils provides utility functions for MCPShell

Index

Constants

View Source
const (
	// MCPShellDirEnv is the environment variable that specifies the configuration directory for MCPShell
	MCPShellDirEnv = "MCPSHELL_DIR"
	// MCPShellToolsDirEnv is the environment variable that specifies the tools directory for MCPShell
	MCPShellToolsDirEnv = "MCPSHELL_TOOLS_DIR"
	// MCPShellHome is the name of the configuration directory for MCPShell
	MCPShellHome = ".mcpshell"
	// MCPShellToolsDir is the name of the tools directory within MCPShell home
	MCPShellToolsDir = "tools"
)

Variables

View Source
var PreferredModels = []string{
	"qwen2.5:14b",
	"qwen2.5:7b",
	"qwen2.5:3b",
	"qwen2.5:1.5b",
	"llama3.1:8b",
	"llama3.1:7b",
	"llama3.2:3b",
	"llama3.2:1b",
	"mistral:7b",
	"phi3:3.8b",
	"phi3:mini",
}

PreferredModels defines the order of preference for testing models These models are known to support tools/function calling

View Source
var ToolCapableModels = map[string]bool{
	"qwen":      true,
	"qwen2":     true,
	"qwen2.5":   true,
	"llama3":    true,
	"llama3.1":  true,
	"llama3.2":  true,
	"mistral":   true,
	"phi3":      true,
	"gemma":     false,
	"codellama": false,
}

ToolCapableModels contains model families known to support tools

Functions

func EnsureToolsDir

func EnsureToolsDir() error

EnsureToolsDir creates the tools directory if it doesn't exist

func FindBestAvailableModel

func FindBestAvailableModel() (string, bool, error)

FindBestAvailableModel finds the best available model for testing Returns the model name and whether it supports tools

func GetHome

func GetHome() (string, error)

GetHome returns the user's home directory in a portable way

func GetMCPShellHome

func GetMCPShellHome() (string, error)

GetMCPShellHome returns the MCPShell configuration directory This is typically ~/.mcpshell on Unix-like systems or %USERPROFILE%\.mcpshell on Windows

func GetMCPShellToolsDir

func GetMCPShellToolsDir() (string, error)

GetMCPShellToolsDir returns the MCPShell tools directory This is typically ~/.mcpshell/tools on Unix-like systems or %USERPROFILE%\.mcpshell\tools on Windows

func IsModelToolCapable

func IsModelToolCapable(modelName string) bool

IsModelToolCapable checks if a model supports tools based on its family

func IsOllamaRunning

func IsOllamaRunning() bool

IsOllamaRunning checks if Ollama server is running and accessible

func RequireOllama

func RequireOllama(t *testing.T) string

RequireOllama skips the test if Ollama is not running but returns any available model

func RequireOllamaWithTools

func RequireOllamaWithTools(t *testing.T) string

RequireOllamaWithTools skips the test if Ollama is not running or no tool-capable models are available

func ResolveToolsFile

func ResolveToolsFile(toolsFile string) (string, error)

ResolveToolsFile resolves a tools file path with the following logic: 1. If the file path is absolute, use it as-is 2. If the file path is relative, first check current directory, then tools directory 3. If the file doesn't have an extension, append .yaml 4. Return an error if the resolved file doesn't exist

func SkipIfOllamaNotRunning

func SkipIfOllamaNotRunning(t *testing.T)

SkipIfOllamaNotRunning skips the test if Ollama is not running

Types

type ModelDetails

type ModelDetails struct {
	Format            string   `json:"format"`
	Family            string   `json:"family"`
	Families          []string `json:"families"`
	ParameterSize     string   `json:"parameter_size"`
	QuantizationLevel string   `json:"quantization_level"`
}

ModelDetails contains detailed information about a model

type OllamaModel

type OllamaModel struct {
	Name       string       `json:"name"`
	ModifiedAt time.Time    `json:"modified_at"`
	Size       int64        `json:"size"`
	Digest     string       `json:"digest"`
	Details    ModelDetails `json:"details"`
}

OllamaModel represents a model available in Ollama

func GetAvailableModels

func GetAvailableModels() ([]OllamaModel, error)

GetAvailableModels retrieves the list of models available in Ollama

type OllamaModelsResponse

type OllamaModelsResponse struct {
	Models []OllamaModel `json:"models"`
}

OllamaModelsResponse represents the response from Ollama's models API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL