OverviewFilesCommitsIssuesDocsReleasesPeers

ollama_semantic_function_calling / ollamatools-new / ollamatools / config / schemas.py

164 lines · python ref:
"""
Configuration schemas for OllamaTools plugins.

This module provides schema definitions for validating plugin configurations.
"""

from typing import Dict, Any, List, Optional, Set, Union, Callable

# Schema for the ConversationHistoryPlugin
CONVERSATION_HISTORY_SCHEMA = {
    "history_file": {
        "type": str,
        "required": False,
        "description": "Path to the conversation history file"
    },
    "max_history": {
        "type": int,
        "required": False,
        "default": 100,
        "description": "Maximum number of conversations to keep in history"
    },
    "enable_topic_analysis": {
        "type": bool,
        "required": False,
        "default": True,
        "description": "Whether to enable topic analysis"
    },
    "enable_metrics": {
        "type": bool,
        "required": False,
        "default": True,
        "description": "Whether to enable performance metrics"
    }
}

# Schema for the SearchPlugin
SEARCH_PLUGIN_SCHEMA = {
    "base_url": {
        "type": str,
        "required": False,
        "default": "http://localhost:8081",
        "description": "Base URL for the OpenSearchNG service"
    },
    "engines": {
        "type": list,
        "required": False,
        "default": ["google", "bing", "duckduckgo", "brave"],
        "description": "List of search engines to use"
    },
    "num_results": {
        "type": int,
        "required": False,
        "default": 5,
        "description": "Number of search results to return"
    },
    "enable_auto_search": {
        "type": bool,
        "required": False,
        "default": True,
        "description": "Whether to enable automatic search for factual queries"
    }
}

# Schema for the MatrixAgentAdapterPlugin
MATRIX_AGENT_ADAPTER_SCHEMA = {
    "agent_class": {
        "type": (str, object),  # Can be a string path or a class object
        "required": True,
        "description": "Agent class to use (string path or class object)"
    },
    "agent_config": {
        "type": dict,
        "required": False,
        "default": {},
        "description": "Configuration for the agent"
    }
}

# Schema for the MatrixCorePlugin
MATRIX_CORE_PLUGIN_SCHEMA = {
    "homeserver": {
        "type": str,
        "required": True,
        "description": "URL of the Matrix homeserver"
    },
    "user_id": {
        "type": str,
        "required": True,
        "description": "Matrix user ID"
    },
    "password": {
        "type": str,
        "required": True,
        "description": "Matrix password"
    },
    "device_id": {
        "type": str,
        "required": False,
        "description": "Device ID for E2E encryption"
    },
    "ssl": {
        "type": bool,
        "required": False,
        "default": True,
        "description": "Whether to use SSL for the Matrix connection"
    },
    "respond_to_all_messages": {
        "type": bool,
        "required": False,
        "default": False,
        "description": "Whether to respond to all messages (not just mentions)"
    }
}

# Schema for the ConversationContextPlugin
CONVERSATION_CONTEXT_SCHEMA = {
    "max_context_length": {
        "type": int,
        "required": False,
        "default": 10,
        "description": "Maximum number of messages to keep in context"
    },
    "context_strategy": {
        "type": str,
        "required": False,
        "default": "sliding_window",
        "enum": ["sliding_window", "token_based", "time_based", "relevance_based"],
        "description": "Strategy for managing conversation context"
    },
    "token_limit": {
        "type": int,
        "required": False,
        "default": 4096,
        "description": "Maximum number of tokens to keep in context (for token_based strategy)"
    },
    "time_window": {
        "type": int,
        "required": False,
        "default": 3600,
        "description": "Time window in seconds for context (for time_based strategy)"
    }
}

# Schema registry
SCHEMA_REGISTRY = {
    "ConversationHistoryPlugin": CONVERSATION_HISTORY_SCHEMA,
    "SearchPlugin": SEARCH_PLUGIN_SCHEMA,
    "MatrixAgentAdapterPlugin": MATRIX_AGENT_ADAPTER_SCHEMA,
    "MatrixCorePlugin": MATRIX_CORE_PLUGIN_SCHEMA,
    "ConversationContextPlugin": CONVERSATION_CONTEXT_SCHEMA
}

def get_schema_for_plugin(plugin_name):
    """
    Get the configuration schema for a plugin.
    
    Args:
        plugin_name: Name of the plugin
        
    Returns:
        Dict[str, Any]: Schema dictionary or empty dict if not found
    """
    return SCHEMA_REGISTRY.get(plugin_name, {})