mud_server.admin_gradio.api.ollama
Ollama API client for MUD Server.
This module handles all Ollama LLM-related operations: - Executing Ollama commands on specified servers - Clearing conversation context
- All functions require admin or superuser role and follow a consistent pattern:
Validate session state and admin permissions
Validate input
Make API request using BaseAPIClient with extended timeout
Return standardized response dictionaries
- Response Format:
All functions return dictionaries with: {
“success”: bool, # Whether operation succeeded “message”: str, # Command output or status message “data”: None, “error”: str | None, # Error details if failed
}
Classes
API client for Ollama LLM operations. |
Module Contents
- class mud_server.admin_gradio.api.ollama.OllamaAPIClient(server_url=None)[source]
Bases:
mud_server.admin_gradio.api.base.BaseAPIClientAPI client for Ollama LLM operations.
This client handles Ollama command execution and context management for admin and superuser roles.
Example
>>> client = OllamaAPIClient() >>> result = client.execute_command( ... session_id="admin123", ... role="admin", ... server_url="http://localhost:11434", ... command="list" ... ) >>> if result["success"]: ... print(result["message"])
Initialize the base API client.
- Parameters:
server_url (str | None) – Optional server URL override. If not provided, uses MUD_SERVER_URL environment variable or defaults to http://localhost:8000
- execute_command(session_id, role, server_url, command)[source]
Execute an Ollama command on the specified server (Admin/Superuser only).
Supported commands: - list: List available models - ps: Show running models - pull <model>: Download a model - rm <model>: Remove a model - And other Ollama CLI commands
- Parameters:
- Returns:
- {
“success”: bool, “message”: str, # Command output “data”: None, “error”: str | None,
}
- Return type:
Dictionary with structure
Examples
>>> client = OllamaAPIClient() >>> result = client.execute_command( ... session_id="admin123", ... role="admin", ... server_url="http://localhost:11434", ... command="list" ... ) >>> result["success"] True
Note
Long-running operations like ‘pull’ use a 5-minute timeout. If the request times out, the operation may still be running on the server. Use ‘ps’ to check status.
- clear_context(session_id, role)[source]
Clear Ollama conversation context for the current session (Admin/Superuser only).
This resets the conversation history, allowing you to start fresh without previous context affecting new queries.
- Parameters:
- Returns:
- {
“success”: bool, “message”: str, “data”: None, “error”: str | None,
}
- Return type:
Dictionary with structure
Examples
>>> client = OllamaAPIClient() >>> result = client.clear_context(session_id="admin123", role="admin") >>> result["success"] True >>> "Context cleared" in result["message"] True