mirror of
https://github.com/Alkatrazz24/Funk-lab.git
synced 2026-07-10 04:34:42 +02:00
feat(stt): recherche web (SearXNG in-cluster) + fix cluster_status (#49)
Phase 2 d'Asa agentique : nouvel outil web_search adossé à un SearXNG self-host in-cluster, + correction du faux positif de cluster_status. - SearXNG (k8s/apps/searxng/) : Deployment + Service + ConfigMap settings.yml + IngressRoute searxng.lab.local, Application ArgoCD. Namespace ai, interne (l'outil tape http://searxng:8080). use_default_settings + search.formats inclut json (sinon API JSON 403) ; limiter/image_proxy off ; image pinnée ; conf copiée dans un emptyDir via initContainer (contourne le mount RO) ; PodSecurity restricted. - Outil web_search (tools._web_search) ajouté au contexte asa + STT_SEARXNG_URL. - fix(cluster_status) : les pods de CronJob TERMINÉS (Succeeded/Failed, ex. sacrifice-assign-renfort) comptaient comme « non prêts » → fausse alarme. Join kube_pod_status_phase{phase=~"Running |Pending"} (3 faux positifs → 0, validé in-cluster). - Serveur 0.8.0 ; doc stt.md + journal mis à jour. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
c9e89c91b9
commit
73b52cde2c
14 changed files with 270 additions and 16 deletions
|
|
@ -103,13 +103,25 @@ sur un contexte figé, Asa **décide elle-même** quels outils appeler (`tools.p
|
||||||
partir de leurs résultats (`brain.ask_with_tools`, boucle bornée par `STT_TOOL_MAX_ITERS=4` ;
|
partir de leurs résultats (`brain.ask_with_tools`, boucle bornée par `STT_TOOL_MAX_ITERS=4` ;
|
||||||
au-delà, réponse forcée sans outils). C'est ce qui débloque les questions à **état live** sans
|
au-delà, réponse forcée sans outils). C'est ce qui débloque les questions à **état live** sans
|
||||||
présélection — ex. « gpu-01 tourne bien ? » → l'outil `host_health` est appelé → réponse réelle
|
présélection — ex. « gpu-01 tourne bien ? » → l'outil `host_health` est appelé → réponse réelle
|
||||||
(avant : le RAG seul disait « la doc ne le précise pas »). Outils Phase 1, **LECTURE SEULE** :
|
(avant : le RAG seul disait « la doc ne le précise pas »). Outils **LECTURE SEULE** (`tools.py`) :
|
||||||
`search_docs` (RAG `funk-docs`), `host_health(gpu-01|storage-01)` (up/charge/RAM + llama-server,
|
`search_docs` (RAG `funk-docs`), `host_health(gpu-01|storage-01)` (up/charge/RAM + llama-server,
|
||||||
Prometheus), `cluster_status` (nœuds/pods), `prometheus_query(expr)` (PromQL arbitraire). Modèle
|
Prometheus), `cluster_status` (nœuds/pods), `prometheus_query(expr)` (PromQL arbitraire), et
|
||||||
**local** Qwen3-8B (le tool-calling natif de llama.cpp fonctionne, **même avec `/no_think`** —
|
**`web_search(query)`** (recherche INTERNET via SearXNG, **Phase 2**). Modèle **local** Qwen3-8B
|
||||||
vérifié). Le `trace` des outils appelés est renvoyé dans `context` → visualiseur HUD (un bloc par
|
(le tool-calling natif de llama.cpp fonctionne, **même avec `/no_think`** — vérifié). Le `trace`
|
||||||
appel). L'écriture (agir) reste au contexte `agent` ci-dessous (Phase 3 : la brancher comme outil).
|
des outils appelés est renvoyé dans `context` → visualiseur HUD (un bloc par appel). L'écriture
|
||||||
> Web search (SearXNG in-cluster) = Phase 2 ; actions admin pilotées par le LLM = Phase 3.
|
(agir) reste au contexte `agent` ci-dessous (Phase 3 : la brancher comme outil).
|
||||||
|
|
||||||
|
> **`cluster_status`** filtre les pods **terminés** (CronJob Succeeded/Failed) via un join
|
||||||
|
> `kube_pod_status_phase` → ne signale comme « non prêts » que les pods réellement actifs (sinon
|
||||||
|
> les pods cron finis, ex. `sacrifice-assign-renfort`, déclenchaient une fausse alarme).
|
||||||
|
|
||||||
|
**SearXNG (recherche web in-cluster, Phase 2)** : méta-moteur self-host, manifests
|
||||||
|
`k8s/apps/searxng/` (Deployment + Service + ConfigMap `settings.yml` + IngressRoute
|
||||||
|
`searxng.lab.local`), Application ArgoCD `searxng`. Namespace `ai`, **interne** (l'outil tape
|
||||||
|
`http://searxng:8080`). Points clés : `use_default_settings: true` (hérite des moteurs),
|
||||||
|
**`search.formats` inclut `json`** (sinon l'API JSON renvoie 403), `limiter:false`/`image_proxy:false`
|
||||||
|
(usage interne), image **pinnée**, conf copiée dans un emptyDir via initContainer (évite le mount RO).
|
||||||
|
Outil = `STT_SEARXNG_URL` (`tools._web_search`). Actions admin pilotées par le LLM = **Phase 3**.
|
||||||
|
|
||||||
La réponse `/v1/ask` renvoie le **contexte assemblé** (`context`: system prompt + blocs live +
|
La réponse `/v1/ask` renvoie le **contexte assemblé** (`context`: system prompt + blocs live +
|
||||||
extraits RAG + mémoire) → alimente le **visualiseur** du HUD (« voir ce qu'on envoie à Asa »).
|
extraits RAG + mémoire) → alimente le **visualiseur** du HUD (« voir ce qu'on envoie à Asa »).
|
||||||
|
|
|
||||||
24
k8s/apps-of-apps/apps/searxng.yaml
Normal file
24
k8s/apps-of-apps/apps/searxng.yaml
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
apiVersion: argoproj.io/v1alpha1
|
||||||
|
kind: Application
|
||||||
|
metadata:
|
||||||
|
name: searxng
|
||||||
|
namespace: argocd
|
||||||
|
finalizers:
|
||||||
|
- resources-finalizer.argocd.argoproj.io
|
||||||
|
spec:
|
||||||
|
project: default
|
||||||
|
source:
|
||||||
|
repoURL: git@github.com:Alkatrazz24/Funk-lab.git
|
||||||
|
targetRevision: main
|
||||||
|
path: k8s/apps/searxng
|
||||||
|
directory:
|
||||||
|
recurse: true
|
||||||
|
destination:
|
||||||
|
server: https://kubernetes.default.svc
|
||||||
|
namespace: ai
|
||||||
|
syncPolicy:
|
||||||
|
automated:
|
||||||
|
prune: true
|
||||||
|
selfHeal: true
|
||||||
|
syncOptions:
|
||||||
|
- CreateNamespace=true
|
||||||
29
k8s/apps/searxng/configmap.yaml
Normal file
29
k8s/apps/searxng/configmap.yaml
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: searxng-settings
|
||||||
|
namespace: ai
|
||||||
|
data:
|
||||||
|
# SearXNG hérite de ses défauts (tous les moteurs) via use_default_settings, puis on
|
||||||
|
# surcharge le strict nécessaire. CRITIQUE : `search.formats` doit inclure `json` — sinon
|
||||||
|
# l'API JSON (utilisée par l'outil web_search d'Asa) renvoie 403. Instance INTERNE au
|
||||||
|
# cluster (pas d'Ingress WAN) : limiter/botdetection off, image_proxy off.
|
||||||
|
settings.yml: |
|
||||||
|
use_default_settings: true
|
||||||
|
general:
|
||||||
|
instance_name: "Funk SearXNG"
|
||||||
|
debug: false
|
||||||
|
server:
|
||||||
|
# secret_key d'une instance INTERNE (HMAC image-proxy, ici désactivé) — sensibilité
|
||||||
|
# faible. Déplaçable vers un Secret + SEARXNG_SECRET plus tard si besoin.
|
||||||
|
secret_key: "3c7090f1caa8fb060ad99e432fd9523aa8dacbfb134438ff02afbddf6cf350ad"
|
||||||
|
limiter: false
|
||||||
|
image_proxy: false
|
||||||
|
search:
|
||||||
|
formats:
|
||||||
|
- html
|
||||||
|
- json
|
||||||
|
safe_search: 0
|
||||||
|
autocomplete: ""
|
||||||
|
ui:
|
||||||
|
static_use_hash: true
|
||||||
82
k8s/apps/searxng/deployment.yaml
Normal file
82
k8s/apps/searxng/deployment.yaml
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: searxng
|
||||||
|
namespace: ai
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: searxng
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: searxng
|
||||||
|
annotations:
|
||||||
|
# Redéploie le pod quand settings.yml change (le hash bouge → nouveau rollout).
|
||||||
|
checksum/config: "searxng-settings-v1"
|
||||||
|
spec:
|
||||||
|
# Conformité PodSecurity "restricted" (namespace ai). L'image tourne en uid 977 (searxng).
|
||||||
|
# fsGroup 977 → l'emptyDir /etc/searxng est accessible en écriture par l'init + le main.
|
||||||
|
securityContext:
|
||||||
|
runAsNonRoot: true
|
||||||
|
runAsUser: 977
|
||||||
|
runAsGroup: 977
|
||||||
|
fsGroup: 977
|
||||||
|
seccompProfile:
|
||||||
|
type: RuntimeDefault
|
||||||
|
# Copie settings.yml (ConfigMap RO) dans un emptyDir inscriptible → évite les soucis
|
||||||
|
# de mount RO de l'entrypoint searxng (chown/sed éventuels sur le fichier de conf).
|
||||||
|
initContainers:
|
||||||
|
- name: copy-config
|
||||||
|
image: docker.io/searxng/searxng:2026.6.22-952896d29
|
||||||
|
command: ["sh", "-c", "cp /config-src/settings.yml /etc/searxng/settings.yml"]
|
||||||
|
securityContext:
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
capabilities:
|
||||||
|
drop: ["ALL"]
|
||||||
|
volumeMounts:
|
||||||
|
- name: config-src
|
||||||
|
mountPath: /config-src
|
||||||
|
readOnly: true
|
||||||
|
- name: config
|
||||||
|
mountPath: /etc/searxng
|
||||||
|
containers:
|
||||||
|
- name: searxng
|
||||||
|
image: docker.io/searxng/searxng:2026.6.22-952896d29
|
||||||
|
securityContext:
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
capabilities:
|
||||||
|
drop: ["ALL"]
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
# Base URL interne (pas d'exposition WAN). Requis par SearXNG pour générer ses liens.
|
||||||
|
- name: SEARXNG_BASE_URL
|
||||||
|
value: "http://searxng.lab.local/"
|
||||||
|
volumeMounts:
|
||||||
|
- name: config
|
||||||
|
mountPath: /etc/searxng
|
||||||
|
readinessProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: 8080
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 10
|
||||||
|
livenessProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: 8080
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 20
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 192Mi
|
||||||
|
limits:
|
||||||
|
cpu: "1"
|
||||||
|
memory: 512Mi
|
||||||
|
volumes:
|
||||||
|
- name: config-src
|
||||||
|
configMap:
|
||||||
|
name: searxng-settings
|
||||||
|
- name: config
|
||||||
|
emptyDir: {}
|
||||||
16
k8s/apps/searxng/ingress.yaml
Normal file
16
k8s/apps/searxng/ingress.yaml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Exposition LAN facultative (debug / usage manuel du méta-moteur). L'outil web_search
|
||||||
|
# d'Asa, lui, tape le Service in-cluster directement (http://searxng:8080).
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: IngressRoute
|
||||||
|
metadata:
|
||||||
|
name: searxng
|
||||||
|
namespace: ai
|
||||||
|
spec:
|
||||||
|
entryPoints:
|
||||||
|
- web
|
||||||
|
routes:
|
||||||
|
- match: Host(`searxng.lab.local`)
|
||||||
|
kind: Rule
|
||||||
|
services:
|
||||||
|
- name: searxng
|
||||||
|
port: 8080
|
||||||
11
k8s/apps/searxng/service.yaml
Normal file
11
k8s/apps/searxng/service.yaml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: searxng
|
||||||
|
namespace: ai
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: searxng
|
||||||
|
ports:
|
||||||
|
- port: 8080
|
||||||
|
targetPort: 8080
|
||||||
|
|
@ -56,6 +56,9 @@ spec:
|
||||||
# live du homelab et la doc d'elle-même. « funk » (RAG strict) reste sélectionnable.
|
# live du homelab et la doc d'elle-même. « funk » (RAG strict) reste sélectionnable.
|
||||||
- name: STT_DEFAULT_CONTEXT
|
- name: STT_DEFAULT_CONTEXT
|
||||||
value: "asa"
|
value: "asa"
|
||||||
|
# Recherche web (outil web_search du contexte asa) → SearXNG in-cluster (ns ai).
|
||||||
|
- name: STT_SEARXNG_URL
|
||||||
|
value: "http://searxng:8080"
|
||||||
- name: STT_PROMETHEUS_URL
|
- name: STT_PROMETHEUS_URL
|
||||||
value: "http://kube-prometheus-stack-prometheus.monitoring:9090"
|
value: "http://kube-prometheus-stack-prometheus.monitoring:9090"
|
||||||
- name: STT_ALERTMANAGER_URL
|
- name: STT_ALERTMANAGER_URL
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,24 @@ appeler, puis répond à partir des résultats.
|
||||||
la boucle (hors-ligne). (PR `feat/asa-tool-loop`.)
|
la boucle (hors-ligne). (PR `feat/asa-tool-loop`.)
|
||||||
- **Choix** : web search = **SearXNG in-cluster** (Phase 2) ; modèle = **local uniquement**.
|
- **Choix** : web search = **SearXNG in-cluster** (Phase 2) ; modèle = **local uniquement**.
|
||||||
|
|
||||||
|
### Validation prod (#48 mergé) + Phase 2
|
||||||
|
|
||||||
|
- ✅ **Déployé et testé en prod** : « gpu-01 tourne bien ? » → outil `host_health` → *« en ligne,
|
||||||
|
charge 0.08, 48 % RAM, llama-server actif »*. « le cluster va bien ? » → `cluster_status`.
|
||||||
|
(Rollout : ArgoCD s'était calé sur le commit de merge ; un `refresh=hard` l'a fait rouler vers
|
||||||
|
l'image CI `sha-7cafc06`.)
|
||||||
|
- 🐛 **Fix `cluster_status`** : les pods de CronJob **terminés** (`sacrifice-assign-renfort`,
|
||||||
|
Succeeded) comptaient comme « non prêts » → fausse alarme. Join `kube_pod_status_phase{phase=~
|
||||||
|
"Running|Pending"}` → 3 faux positifs → 0 (validé in-cluster).
|
||||||
|
- ✅ **Phase 2 — recherche web** : SearXNG self-host (`k8s/apps/searxng/`, Application ArgoCD,
|
||||||
|
ns `ai`, interne) + outil `web_search` (`STT_SEARXNG_URL`). Gotcha clé : `search.formats` doit
|
||||||
|
inclure `json`. Image pinnée, conf via initContainer→emptyDir (mount RO contourné), PodSecurity
|
||||||
|
restricted. (PR `feat/asa-web-search`, serveur 0.8.0.)
|
||||||
|
|
||||||
## Prochaines étapes
|
## Prochaines étapes
|
||||||
|
|
||||||
- **Phase 2** — outil `web_search` (SearXNG self-host in-cluster, namespace `ai`, ArgoCD).
|
- **Vérifier SearXNG au déploiement** : pod Ready + `web_search` renvoie des résultats réels
|
||||||
|
(test end-to-end comme pour #48). Ajuster les moteurs SearXNG si bruyant.
|
||||||
- **Phase 3** — outil `admin_action` (écriture) : brancher `hermes-exec` comme outil piloté par le
|
- **Phase 3** — outil `admin_action` (écriture) : brancher `hermes-exec` comme outil piloté par le
|
||||||
LLM, avec le handshake de confirmation vocale existant.
|
LLM, avec le handshake de confirmation vocale existant.
|
||||||
- Enrichir `host_health`/`cluster_status` (GPU via `rocm_scraper`, fs, températures) si utile.
|
- Enrichir `host_health`/`cluster_status` (GPU via `rocm_scraper`, fs, températures) si utile.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "stt-server"
|
name = "stt-server"
|
||||||
version = "0.7.0"
|
version = "0.8.0"
|
||||||
description = "STT-server — orchestrateur AI du homelab Funk (API pour les clients STT)"
|
description = "STT-server — orchestrateur AI du homelab Funk (API pour les clients STT)"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
"""STT-server — orchestrateur AI in-cluster pour les clients STT."""
|
"""STT-server — orchestrateur AI in-cluster pour les clients STT."""
|
||||||
|
|
||||||
__version__ = "0.7.0"
|
__version__ = "0.8.0"
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,10 @@ class Settings:
|
||||||
tool_max_tokens: int = int(os.getenv("STT_TOOL_MAX_TOKENS", "512"))
|
tool_max_tokens: int = int(os.getenv("STT_TOOL_MAX_TOKENS", "512"))
|
||||||
# Température basse pour le tool-use (sélection d'outil + arguments déterministes).
|
# Température basse pour le tool-use (sélection d'outil + arguments déterministes).
|
||||||
tool_temperature: float = float(os.getenv("STT_TOOL_TEMPERATURE", "0.2"))
|
tool_temperature: float = float(os.getenv("STT_TOOL_TEMPERATURE", "0.2"))
|
||||||
|
# Recherche web (outil web_search) — SearXNG self-host in-cluster (namespace ai), API JSON.
|
||||||
|
searxng_url: str = os.getenv("STT_SEARXNG_URL", "http://searxng:8080")
|
||||||
|
web_search_results: int = int(os.getenv("STT_WEB_SEARCH_RESULTS", "5"))
|
||||||
|
web_search_timeout: float = float(os.getenv("STT_WEB_SEARCH_TIMEOUT", "8"))
|
||||||
|
|
||||||
# Actions via Hermes (contexte « agent ») — OPT-IN, désactivé par défaut.
|
# Actions via Hermes (contexte « agent ») — OPT-IN, désactivé par défaut.
|
||||||
# Le contexte « agent » n'est exposé que si actions_enabled ET un jeton est présent.
|
# Le contexte « agent » n'est exposé que si actions_enabled ET un jeton est présent.
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,13 @@ CONTEXTS: dict[str, Context] = {
|
||||||
id="asa", label="Asa · agent", icon="✨",
|
id="asa", label="Asa · agent", icon="✨",
|
||||||
description="Asa répond en s'appuyant sur des outils (doc + état live du homelab).",
|
description="Asa répond en s'appuyant sur des outils (doc + état live du homelab).",
|
||||||
system_prompt=_BASE + " Tu disposes d'outils pour obtenir l'état RÉEL et LIVE du "
|
system_prompt=_BASE + " Tu disposes d'outils pour obtenir l'état RÉEL et LIVE du "
|
||||||
"homelab (santé des machines, état du cluster, métriques Prometheus) et pour chercher "
|
"homelab (santé des machines, état du cluster, métriques Prometheus), chercher dans la "
|
||||||
"dans la documentation Funk. Dès qu'une question porte sur l'état courant, un fait "
|
"documentation Funk, et faire une recherche sur INTERNET (web_search). Dès qu'une "
|
||||||
"précis ou la config du homelab, APPELLE l'outil adéquat puis réponds à partir de son "
|
"question porte sur l'état courant, un fait précis du homelab, ou une info externe / "
|
||||||
"résultat — n'invente jamais. Si les outils ne donnent pas l'information, dis-le "
|
"récente, APPELLE l'outil adéquat puis réponds à partir de son résultat — n'invente "
|
||||||
"simplement. Pour le bavardage général, réponds directement sans outil.",
|
"jamais. Si les outils ne donnent pas l'information, dis-le simplement. Pour le "
|
||||||
tools=("search_docs", "host_health", "cluster_status", "prometheus_query"),
|
"bavardage général, réponds directement sans outil.",
|
||||||
|
tools=("search_docs", "host_health", "cluster_status", "prometheus_query", "web_search"),
|
||||||
),
|
),
|
||||||
"funk": Context(
|
"funk": Context(
|
||||||
id="funk", label="Funk · cluster", icon="🛠️",
|
id="funk", label="Funk · cluster", icon="🛠️",
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,13 @@ async def alerts_block(client: httpx.AsyncClient) -> str:
|
||||||
async def cluster_block(client: httpx.AsyncClient) -> str:
|
async def cluster_block(client: httpx.AsyncClient) -> str:
|
||||||
try:
|
try:
|
||||||
nodes = await _prom_query(client, 'up{job=~"storage-01|gpu-01-node"}')
|
nodes = await _prom_query(client, 'up{job=~"storage-01|gpu-01-node"}')
|
||||||
|
# « Non prêt » = ready false ET pod ENCORE actif (Running/Pending). Sans le filtre de
|
||||||
|
# phase, les pods de CronJob terminés (Succeeded/Failed — ex. sacrifice-assign-renfort)
|
||||||
|
# comptent comme « non prêts » → fausse alarme. Le join exclut les pods terminés.
|
||||||
not_ready = await _prom_query(
|
not_ready = await _prom_query(
|
||||||
client, 'kube_pod_status_ready{condition="false"} == 1'
|
client,
|
||||||
|
'kube_pod_status_ready{condition="false"} == 1'
|
||||||
|
' and on(namespace,pod) kube_pod_status_phase{phase=~"Running|Pending"} == 1',
|
||||||
)
|
)
|
||||||
ready = await _prom_query(client, 'count(kube_pod_status_ready{condition="true"} == 1)')
|
ready = await _prom_query(client, 'count(kube_pod_status_ready{condition="true"} == 1)')
|
||||||
except httpx.HTTPError:
|
except httpx.HTTPError:
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,38 @@ async def _prometheus_query(args: dict, deps: ToolDeps) -> str:
|
||||||
return _fmt_series(rows)
|
return _fmt_series(rows)
|
||||||
|
|
||||||
|
|
||||||
|
async def _web_search(args: dict, deps: ToolDeps) -> str:
|
||||||
|
query = (args.get("query") or "").strip()
|
||||||
|
if not query:
|
||||||
|
return "Aucune requête de recherche fournie."
|
||||||
|
url = settings.searxng_url.rstrip("/") + "/search"
|
||||||
|
try:
|
||||||
|
r = await deps.client.get(
|
||||||
|
url,
|
||||||
|
params={"q": query, "format": "json", "safesearch": 0, "language": "fr"},
|
||||||
|
timeout=settings.web_search_timeout,
|
||||||
|
)
|
||||||
|
r.raise_for_status()
|
||||||
|
data = r.json()
|
||||||
|
except httpx.HTTPError:
|
||||||
|
return "Recherche web indisponible : SearXNG injoignable."
|
||||||
|
except ValueError:
|
||||||
|
return "Recherche web indisponible : réponse SearXNG inattendue (API JSON activée ?)."
|
||||||
|
results = data.get("results") or []
|
||||||
|
if not results:
|
||||||
|
answers = data.get("answers") or []
|
||||||
|
if answers:
|
||||||
|
return " ".join(str(a) for a in answers[:2])
|
||||||
|
return "Aucun résultat web pour cette recherche."
|
||||||
|
lines = []
|
||||||
|
for res in results[: settings.web_search_results]:
|
||||||
|
title = (res.get("title") or "").strip()
|
||||||
|
content = (res.get("content") or "").strip()
|
||||||
|
src = res.get("url") or ""
|
||||||
|
lines.append(f"- {title} : {content} ({src})" if content else f"- {title} ({src})")
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
# --- Registre : nom → (schéma OpenAI, exécuteur) --------------------------------
|
# --- Registre : nom → (schéma OpenAI, exécuteur) --------------------------------
|
||||||
|
|
||||||
_TOOLS: dict[str, tuple[dict, object]] = {
|
_TOOLS: dict[str, tuple[dict, object]] = {
|
||||||
|
|
@ -191,6 +223,26 @@ _TOOLS: dict[str, tuple[dict, object]] = {
|
||||||
},
|
},
|
||||||
_prometheus_query,
|
_prometheus_query,
|
||||||
),
|
),
|
||||||
|
"web_search": (
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": "web_search",
|
||||||
|
"description": "Recherche sur INTERNET (méta-moteur SearXNG) : actualité, faits "
|
||||||
|
"généraux, documentation externe, sujets hors du homelab Funk. À utiliser quand "
|
||||||
|
"l'information n'est ni dans le homelab ni dans ta connaissance, ou pour vérifier "
|
||||||
|
"un fait récent.",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"query": {"type": "string", "description": "Termes de recherche"}
|
||||||
|
},
|
||||||
|
"required": ["query"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
_web_search,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue