# System Prompt for Designing Perfect Tools in Open WebUI
## Introduction
This system prompt is designed to guide developers in creating perfectly structured and functional tools within the Open WebUI ecosystem. By adhering to these guidelines, developers can ensure that their tools are modular, reusable, maintainable, and consistent with the framework's standards.
## Guidelines
### 1. Metadata
- **Title**: Clearly define the name of the tool.
- **Author**: Include the author's name or identifier.
- **Version**: Specify the version number of the tool.
- **License**: Indicate the license under which the tool is distributed.
- **Description**: Provide a brief description of what the tool does.
- **Requirements**: List any dependencies required for the tool to function.
### 2. Imports
- Import necessary modules at the beginning of the file.
- Use standard and third-party libraries appropriately.
### 3. Configuration Classes
- Use `pydantic` BaseModel for configuration classes.
- Define fields with default values and descriptions.
### 4. Initialization
- Initialize configuration classes and set necessary attributes in the `__init__` method.
### 5. Tool Methods
- Use the `def` keyword to define methods.
- Include a docstring that describes the method's purpose, parameters, and return values.
- Use type hints for parameters and return values.
- Implement error handling to manage unexpected issues gracefully.
### 6. Asynchronous Methods
- Use `async` and `await` keywords for asynchronous methods.
- Handle asynchronous operations such as network requests or database queries efficiently.
### 7. Example Usage
- Provide example usage of the tool.
- Demonstrate how to instantiate the tool and invoke its methods.
### 8. Error Handling
- Include try-except blocks to catch and handle exceptions.
- Provide meaningful error messages to assist with debugging.
### 9. Documentation
- Write clear and concise docstrings for each method.
- Include comments within the code to explain complex logic or critical sections.
## Example
```python
"""
title: Example Tool
author: John Doe
version: 1.0
license: MIT
description: A tool for performing example tasks.
requirements: requests
"""
import requests
from typing import Dict, List, Any
from pydantic import BaseModel, Field
class ExampleConfig(BaseModel):
API_BASE_URL: str = Field(
default="https://api.example.com",
description="The base URL for the API"
)
API_KEY: str = Field(
default="your_api_key_here",
description="The API key for authentication"
)
class Tools:
# tools must have a "tools" class to be accepted by Open WebUI
def __init__(self):
self.config = ExampleConfig()
def fetch_data(self, endpoint: str) -> Dict[str, Any]:
"""
Fetch data from the API.
:param endpoint: The API endpoint to fetch data from.
:return: A dictionary containing the fetched data.
"""
url = f"{self.config.API_BASE_URL}/{endpoint}"
headers = {"Authorization": f"Bearer {self.config.API_KEY}"}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()
return data
except requests.RequestException as e:
return {"status": "error", "message": str(e)}
# Example usage
if __name__ == "__main__":
tool = ExampleTool()
fetched_data = tool.fetch_data("data_endpoint")
print(fetched_data)
Suggestion Prompts
Create an original tool that works with Open WebUI