fix: Use Pydantic Valves pattern for OpenWebUI tool config

- Add BaseModel Valves class with configurable parameters
- beszel_url, beszel_user, beszel_password as configurable valves
- Matches ACE Step tool pattern for UI configuration
This commit is contained in:
Folzo
2026-04-12 13:46:20 +02:00
parent 6212aa6f27
commit 26e6b89229
+50 -35
View File
@@ -11,52 +11,53 @@ Permet à Effi d'accéder aux métriques système de FolzoCorp, EffiServer et NA
3. **Description**: `Monitor system resources via Beszel. Usage: get_all_stats(), get_system_stats("folzocorp"), check_alerts("folzocorp"), get_gpu_status("folzocorp"), can_run_comfyui()`
4. **Coller le code ci-dessous**
5. **Save and Activate**
## Configuration
Pour modifier les paramètres, modifie les variables en haut du code:
- `BESZEL_URL`: URL du hub Beszel
- `BESZEL_USER`: Username admin
- `BESZEL_PASSWORD`: Password admin
6. **Configurer les variables** via la roue crantée (Vannes)
## Tool Code
```python
import requests
# Configuration - MODIFIER ICI
BESZEL_URL = "http://192.168.1.25:8090"
BESZEL_USER = "admin"
BESZEL_PASSWORD = "ton_password_beszel"
from pydantic import BaseModel, Field
class Tools:
class Valves(BaseModel):
beszel_url: str = Field(
default="http://192.168.1.25:8090",
description="Beszel Hub URL",
)
beszel_user: str = Field(
default="admin",
description="Beszel username",
)
beszel_password: str = Field(
default="",
description="Beszel password",
)
def __init__(self):
self.url = BESZEL_URL
self.username = BESZEL_USER
self.password = BESZEL_PASSWORD
self.token = None
self.valves = self.Valves()
def _login(self):
try:
response = requests.post(
f"{self.url}/api/auth/login",
json={"identity": self.username, "password": self.password},
f"{self.valves.beszel_url}/api/auth/login",
json={"identity": self.valves.beszel_user, "password": self.valves.beszel_password},
timeout=10
)
if response.status_code == 200:
self.token = response.json().get("token")
return True
return False
return response.json().get("token")
return None
except Exception:
return False
return None
def _get_systems(self):
if not self.token and not self._login():
token = self._login()
if not token:
return None
try:
headers = {"Authorization": f"Bearer {self.token}"}
response = requests.get(f"{self.url}/api/systems", headers=headers, timeout=10)
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(f"{self.valves.beszel_url}/api/systems", headers=headers, timeout=10)
if response.status_code == 200:
return response.json().get("items", [])
return None
@@ -64,12 +65,13 @@ class Tools:
return None
def _get_system_stats(self, system_id):
if not self.token and not self._login():
token = self._login()
if not token:
return None
try:
headers = {"Authorization": f"Bearer {self.token}"}
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(
f"{self.url}/api/systems/{system_id}/stats",
f"{self.valves.beszel_url}/api/systems/{system_id}/stats",
headers=headers,
timeout=10
)
@@ -149,6 +151,7 @@ class Tools:
return alerts
def get_all_stats(self):
"""Get stats from all monitored systems."""
systems = self._get_systems()
if not systems:
@@ -167,7 +170,8 @@ class Tools:
return "\n\n".join(results)
def get_system_stats(self, system_name):
def get_system_stats(self, system_name: str):
"""Get stats for a specific system. Options: folzocorp, effiserver, synology-nas"""
systems = self._get_systems()
if not systems:
@@ -192,7 +196,8 @@ class Tools:
available = [s.get('name', s.get('id')) for s in systems]
return f"[ERROR] System '{system_name}' not found. Available: {', '.join(available)}"
def check_alerts(self, system_name="all"):
def check_alerts(self, system_name: str = "all"):
"""Check for resource alerts. Use 'all' or specific system name."""
systems = self._get_systems()
if not systems:
@@ -219,7 +224,8 @@ class Tools:
return "\n".join(alerts)
def get_gpu_status(self, system_name="folzocorp"):
def get_gpu_status(self, system_name: str = "folzocorp"):
"""Get GPU status for a specific system. Most useful for folzocorp (AMD RX 7800 XT)."""
systems = self._get_systems()
if not systems:
@@ -260,6 +266,7 @@ class Tools:
return "\n".join(lines)
def can_run_comfyui(self):
"""Check if there's enough RAM and VRAM to run ComfyUI."""
stats = self._get_system_stats("folzocorp")
if not stats:
return "[ERROR] Cannot get FolzoCorp stats"
@@ -291,15 +298,15 @@ def get_all_stats():
tools = Tools()
return tools.get_all_stats()
def get_system_stats(system_name):
def get_system_stats(system_name: str):
tools = Tools()
return tools.get_system_stats(system_name)
def check_alerts(system_name="all"):
def check_alerts(system_name: str = "all"):
tools = Tools()
return tools.check_alerts(system_name)
def get_gpu_status(system_name="folzocorp"):
def get_gpu_status(system_name: str = "folzocorp"):
tools = Tools()
return tools.get_gpu_status(system_name)
@@ -327,6 +334,14 @@ can_run_comfyui()
| EffiServer | `effiserver` | None (Intel J5040) |
| NAS Synology | `synology-nas` | Intel HD Graphics |
## Variables (Vannes) Configurables
| Variable | Description |
|----------|-------------|
| `beszel_url` | URL du hub Beszel (défaut: http://192.168.1.25:8090) |
| `beszel_user` | Username admin (défaut: admin) |
| `beszel_password` | Mot de passe admin |
---
*Created 12 April 2026 - Updated to use hardcoded config*
*Created 12 April 2026*