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:
@@ -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()`
|
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**
|
4. **Coller le code ci-dessous**
|
||||||
5. **Save and Activate**
|
5. **Save and Activate**
|
||||||
|
6. **Configurer les variables** via la roue crantée (Vannes)
|
||||||
## 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
|
|
||||||
|
|
||||||
## Tool Code
|
## Tool Code
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import requests
|
import requests
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
# Configuration - MODIFIER ICI
|
|
||||||
BESZEL_URL = "http://192.168.1.25:8090"
|
|
||||||
BESZEL_USER = "admin"
|
|
||||||
BESZEL_PASSWORD = "ton_password_beszel"
|
|
||||||
|
|
||||||
|
|
||||||
class Tools:
|
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):
|
def __init__(self):
|
||||||
self.url = BESZEL_URL
|
self.valves = self.Valves()
|
||||||
self.username = BESZEL_USER
|
|
||||||
self.password = BESZEL_PASSWORD
|
|
||||||
self.token = None
|
|
||||||
|
|
||||||
def _login(self):
|
def _login(self):
|
||||||
try:
|
try:
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
f"{self.url}/api/auth/login",
|
f"{self.valves.beszel_url}/api/auth/login",
|
||||||
json={"identity": self.username, "password": self.password},
|
json={"identity": self.valves.beszel_user, "password": self.valves.beszel_password},
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
self.token = response.json().get("token")
|
return response.json().get("token")
|
||||||
return True
|
return None
|
||||||
return False
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return None
|
||||||
|
|
||||||
def _get_systems(self):
|
def _get_systems(self):
|
||||||
if not self.token and not self._login():
|
token = self._login()
|
||||||
|
if not token:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
headers = {"Authorization": f"Bearer {self.token}"}
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
response = requests.get(f"{self.url}/api/systems", headers=headers, timeout=10)
|
response = requests.get(f"{self.valves.beszel_url}/api/systems", headers=headers, timeout=10)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.json().get("items", [])
|
return response.json().get("items", [])
|
||||||
return None
|
return None
|
||||||
@@ -64,12 +65,13 @@ class Tools:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def _get_system_stats(self, system_id):
|
def _get_system_stats(self, system_id):
|
||||||
if not self.token and not self._login():
|
token = self._login()
|
||||||
|
if not token:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
headers = {"Authorization": f"Bearer {self.token}"}
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"{self.url}/api/systems/{system_id}/stats",
|
f"{self.valves.beszel_url}/api/systems/{system_id}/stats",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
@@ -149,6 +151,7 @@ class Tools:
|
|||||||
return alerts
|
return alerts
|
||||||
|
|
||||||
def get_all_stats(self):
|
def get_all_stats(self):
|
||||||
|
"""Get stats from all monitored systems."""
|
||||||
systems = self._get_systems()
|
systems = self._get_systems()
|
||||||
|
|
||||||
if not systems:
|
if not systems:
|
||||||
@@ -167,7 +170,8 @@ class Tools:
|
|||||||
|
|
||||||
return "\n\n".join(results)
|
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()
|
systems = self._get_systems()
|
||||||
|
|
||||||
if not systems:
|
if not systems:
|
||||||
@@ -192,7 +196,8 @@ class Tools:
|
|||||||
available = [s.get('name', s.get('id')) for s in systems]
|
available = [s.get('name', s.get('id')) for s in systems]
|
||||||
return f"[ERROR] System '{system_name}' not found. Available: {', '.join(available)}"
|
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()
|
systems = self._get_systems()
|
||||||
|
|
||||||
if not systems:
|
if not systems:
|
||||||
@@ -219,7 +224,8 @@ class Tools:
|
|||||||
|
|
||||||
return "\n".join(alerts)
|
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()
|
systems = self._get_systems()
|
||||||
|
|
||||||
if not systems:
|
if not systems:
|
||||||
@@ -260,6 +266,7 @@ class Tools:
|
|||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
def can_run_comfyui(self):
|
def can_run_comfyui(self):
|
||||||
|
"""Check if there's enough RAM and VRAM to run ComfyUI."""
|
||||||
stats = self._get_system_stats("folzocorp")
|
stats = self._get_system_stats("folzocorp")
|
||||||
if not stats:
|
if not stats:
|
||||||
return "[ERROR] Cannot get FolzoCorp stats"
|
return "[ERROR] Cannot get FolzoCorp stats"
|
||||||
@@ -291,15 +298,15 @@ def get_all_stats():
|
|||||||
tools = Tools()
|
tools = Tools()
|
||||||
return tools.get_all_stats()
|
return tools.get_all_stats()
|
||||||
|
|
||||||
def get_system_stats(system_name):
|
def get_system_stats(system_name: str):
|
||||||
tools = Tools()
|
tools = Tools()
|
||||||
return tools.get_system_stats(system_name)
|
return tools.get_system_stats(system_name)
|
||||||
|
|
||||||
def check_alerts(system_name="all"):
|
def check_alerts(system_name: str = "all"):
|
||||||
tools = Tools()
|
tools = Tools()
|
||||||
return tools.check_alerts(system_name)
|
return tools.check_alerts(system_name)
|
||||||
|
|
||||||
def get_gpu_status(system_name="folzocorp"):
|
def get_gpu_status(system_name: str = "folzocorp"):
|
||||||
tools = Tools()
|
tools = Tools()
|
||||||
return tools.get_gpu_status(system_name)
|
return tools.get_gpu_status(system_name)
|
||||||
|
|
||||||
@@ -327,6 +334,14 @@ can_run_comfyui()
|
|||||||
| EffiServer | `effiserver` | None (Intel J5040) |
|
| EffiServer | `effiserver` | None (Intel J5040) |
|
||||||
| NAS Synology | `synology-nas` | Intel HD Graphics |
|
| 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*
|
||||||
|
|||||||
Reference in New Issue
Block a user