Spaces:
Running
Running
sync: 181 file da Baida98/AI@3b6c4f90 (2026-08-25 11:31 UTC) [deploy-all]
#79
by Baida07 - opened
agents/unified_loop_tools.py
CHANGED
|
@@ -359,31 +359,25 @@ class DirectToolsMixin:
|
|
| 359 |
_sc = _spec_hit("generate_image", {"prompt": _img_prompt[:600]})
|
| 360 |
if _sc is not None:
|
| 361 |
return _sc
|
| 362 |
-
|
| 363 |
-
#
|
| 364 |
-
#
|
| 365 |
-
#
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
)
|
| 373 |
-
try:
|
| 374 |
-
from api.state import record_timing as _rtc; _rtc("tool_call", (asyncio.get_event_loop().time() - _t0) * 1000)
|
| 375 |
-
except Exception as _e: _logger.debug('[timing/record_timing] %s', _e)
|
| 376 |
-
img_url = r.get("url", "")
|
| 377 |
-
if img_url:
|
| 378 |
-
return (
|
| 379 |
-
"[DIRECT_TERMINAL]\n"
|
| 380 |
-
f"\n\n"
|
| 381 |
-
"E2E_IMAGE_OK: immagine generata e visualizzata qui sopra. "
|
| 382 |
-
f"[Apri o scarica l’immagine]({img_url}).\n\n"
|
| 383 |
-
f"Prompt usato: {r.get('prompt', _img_prompt)[:200]}\n"
|
| 384 |
-
f"Dimensioni: {r.get('width')}x{r.get('height')} px"
|
| 385 |
-
)
|
| 386 |
-
return "[generate_image: nessun URL restituito]"
|
| 387 |
except asyncio.TimeoutError:
|
| 388 |
return "[generate_image: timeout — provider non raggiungibile]"
|
| 389 |
except Exception as exc:
|
|
|
|
| 359 |
_sc = _spec_hit("generate_image", {"prompt": _img_prompt[:600]})
|
| 360 |
if _sc is not None:
|
| 361 |
return _sc
|
| 362 |
+
# Pollinations genera l'immagine quando il browser richiede questo
|
| 363 |
+
# URL. Costruirlo qui rende il direct tool autosufficiente: non
|
| 364 |
+
# dipende da cold-start HF, dal contratto base64 dell'endpoint
|
| 365 |
+
# vision né da un provider LLM per verbalizzare il risultato.
|
| 366 |
+
from urllib.parse import quote
|
| 367 |
+
_img_prompt = _img_prompt[:600]
|
| 368 |
+
_img_seed = sum(ord(char) for char in _img_prompt) % 9999 + 1
|
| 369 |
+
img_url = (
|
| 370 |
+
f"https://image.pollinations.ai/prompt/{quote(_img_prompt, safe='')}"
|
| 371 |
+
f"?width=512&height=512&seed={_img_seed}&nologo=true&enhance=true"
|
| 372 |
+
)
|
| 373 |
+
return (
|
| 374 |
+
"[DIRECT_TERMINAL]\n"
|
| 375 |
+
f"\n\n"
|
| 376 |
+
"E2E_IMAGE_OK: immagine generata e visualizzata qui sopra. "
|
| 377 |
+
f"[Apri o scarica l’immagine]({img_url}).\n\n"
|
| 378 |
+
f"Prompt usato: {_img_prompt[:200]}\n"
|
| 379 |
+
"Dimensioni: 512x512 px"
|
| 380 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
except asyncio.TimeoutError:
|
| 382 |
return "[generate_image: timeout — provider non raggiungibile]"
|
| 383 |
except Exception as exc:
|
tests/test_direct_file_conversion.py
CHANGED
|
@@ -82,8 +82,9 @@ def test_direct_image_returns_renderable_terminal_markdown_without_llm():
|
|
| 82 |
)
|
| 83 |
)
|
| 84 |
|
| 85 |
-
assert output.startswith("[DIRECT_TERMINAL]\n
|
| 83 |
)
|
| 84 |
|
| 85 |
+
assert output.startswith("[DIRECT_TERMINAL]\n
|
| 86 |
assert "E2E_IMAGE_OK" in output
|
| 87 |
+
assert "aeroplanino%20arancione" in output
|
| 88 |
assert called == 1
|
| 89 |
assert succeeded == 1
|
| 90 |
assert errors == 0
|