agromatrix: deterministic plant-id flow + confidence guard + plantnet env
This commit is contained in:
@@ -812,6 +812,21 @@ class ToolManager:
|
||||
if "web.telegram.org" in host:
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _normalize_confidence(value: Any) -> float:
|
||||
try:
|
||||
v = float(value)
|
||||
except Exception:
|
||||
return 0.0
|
||||
if v < 0:
|
||||
return 0.0
|
||||
# Some backends return percentages (e.g. 97.6) instead of 0..1.
|
||||
if v > 1.0 and v <= 100.0:
|
||||
v = v / 100.0
|
||||
if v > 1.0:
|
||||
v = 1.0
|
||||
return v
|
||||
|
||||
async def execute_tool(
|
||||
self,
|
||||
@@ -2802,10 +2817,7 @@ class ToolManager:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
conf = row.get("confidence", 0.0)
|
||||
try:
|
||||
conf_f = float(conf)
|
||||
except Exception:
|
||||
conf_f = 0.0
|
||||
conf_f = self._normalize_confidence(conf)
|
||||
top_k_rows.append({
|
||||
"confidence": conf_f,
|
||||
"name": str(row.get("name") or row.get("scientific_name") or "unknown"),
|
||||
@@ -2816,10 +2828,7 @@ class ToolManager:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
score = item.get("score", item.get("confidence", 0.0))
|
||||
try:
|
||||
score_f = float(score)
|
||||
except Exception:
|
||||
score_f = 0.0
|
||||
score_f = self._normalize_confidence(score)
|
||||
sname = item.get("scientific_name") or item.get("label") or item.get("name") or "unknown"
|
||||
cname = item.get("common_name") or item.get("common") or sname
|
||||
top_k_rows.append({
|
||||
|
||||
Reference in New Issue
Block a user