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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# /// script
|
| 4 |
+
# dependencies = ["huggingface_hub"]
|
| 5 |
+
# ///
|
| 6 |
+
|
| 7 |
+
import argparse
|
| 8 |
+
import hashlib
|
| 9 |
+
import json
|
| 10 |
+
import os
|
| 11 |
+
import random
|
| 12 |
+
import secrets
|
| 13 |
+
import string
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
from huggingface_hub import HfApi, upload_folder
|
| 16 |
+
|
| 17 |
+
FIRST = ["Marco","Anna","Giulia","Davide","Carla","Sergio","Luca","Elena","Paolo","Marta","Simone","Laura","Andrea","Sara","Fabio","Nadia","Giorgio","Irene"]
|
| 18 |
+
CITIES = ["Roma","Milano","Napoli","Torino","Palermo","Genova","Bologna","Firenze","Bari","Catania","Venezia","Verona","Messina","Padova","Trieste","Taranto","Brescia","Parma","Modena","Reggio Emilia","Perugia","Livorno","Ravenna","Cagliari","Foggia","Rimini","Salerno","Ferrara","Sassari","Latina","Giugliano","Monza","Siracusa","Pescara","Bergamo","Forlì","Trento","Vicenza","Terni","Bolzano","Novara","Piacenza","Ancona","Andria","Arezzo","Udine","Cesena","Lecce","Pesaro","Barletta","Alessandria","La Spezia","Pordenone","Gorizia","Aosta","Bologna"]
|
| 19 |
+
CONDITIONS = ["sereno","pioggia","neve","vento","nebbia","caldo","nuvoloso","temporale","grandine","coperto","foschia","afa"]
|
| 20 |
+
STOCKS = ["AAPL","NVDA","TSLA","VWCE","MSFT","AMD","META","GOOGL","AMZN","SPY","ENI","ISP","NFLX","INTC","ORCL","AVGO","BABA","SAP","ASML","ADBE","CRM","UBER","RACE","LDO","UCG","G","PST","BTC","ETH"]
|
| 21 |
+
EVENTS = ["Riunione","Audit","Backup","Manutenzione","Briefing","Formazione","Sopralluogo","Dentista","Check sicurezza","Aggiornamento","Call progetto","Verifica log","Report","Analisi OSINT","Consegna","Controllo backup","Patch day","Riunione tecnica"]
|
| 22 |
+
ROOMS = ["garage","cucina","salotto","camera","studio","ingresso","cantina","terrazzo","bagno","corridoio","ufficio","sala server"]
|
| 23 |
+
DEVICES = ["porta","sensore porta","luce","termostato","telecamera","sirena","presa smart","sensore finestra","sensore movimento","gateway","router","UPS"]
|
| 24 |
+
ARTISTS = ["Muse","Metallica","Coldplay","Queen","Radiohead","Daft Punk","Battiato","Subsonica","Pink Floyd","Nirvana","Pearl Jam","U2","REM","Depeche Mode","The Cure","Måneskin","Elisa","Ligabue","Vasco Rossi","ACDC","Led Zeppelin","David Bowie","Franco Califano","Lucio Dalla","Pino Daniele","Massive Attack","The Prodigy","Arctic Monkeys"]
|
| 25 |
+
WORDS = ["red","blue","silent","night","cyber","rain","stone","fire","moon","signal","river","shadow","light","dream","road","ghost","storm","zero","future","city","heart","ocean","data","noise","pattern","radio","velvet","silver","gold","black","white","wild","electric","digital","secret"]
|
| 26 |
+
|
| 27 |
+
def jd(x):
|
| 28 |
+
return json.dumps(x, ensure_ascii=False, separators=(",", ":"))
|
| 29 |
+
|
| 30 |
+
def rand_word(r, n=8):
|
| 31 |
+
alphabet = string.ascii_lowercase + string.digits
|
| 32 |
+
return "".join(r.choice(alphabet) for _ in range(n))
|
| 33 |
+
|
| 34 |
+
def rand_domain(r):
|
| 35 |
+
tlds = ["com","it","net","org","info","ai","dev","cloud","help","site"]
|
| 36 |
+
base = r.choice(["redhotcyber","scugnizz","example","agenzia","login","secure","portal","mail","auth","cloud","service","pay","update","verify"])
|
| 37 |
+
suffix = rand_word(r, r.randint(3,8))
|
| 38 |
+
return f"{base}-{suffix}.{r.choice(tlds)}"
|
| 39 |
+
|
| 40 |
+
def rand_url(r):
|
| 41 |
+
proto = r.choice(["https","http"])
|
| 42 |
+
path = "/".join([r.choice(["login","pay","verify","api","download","reset","user","invoice","check"]), rand_word(r,6)])
|
| 43 |
+
return f"{proto}://{rand_domain(r)}/{path}"
|
| 44 |
+
|
| 45 |
+
def rand_ipv4(r, keep_zeros=True):
|
| 46 |
+
parts = [r.randint(0,255) for _ in range(4)]
|
| 47 |
+
if keep_zeros:
|
| 48 |
+
return ".".join(f"{x:03d}" for x in parts)
|
| 49 |
+
return ".".join(str(x) for x in parts)
|
| 50 |
+
|
| 51 |
+
def rand_ipv6(r):
|
| 52 |
+
return ":".join(f"{r.randint(0,65535):04x}" for _ in range(8))
|
| 53 |
+
|
| 54 |
+
def rand_mac(r):
|
| 55 |
+
return ":".join(f"{r.randint(0,255):02x}" for _ in range(6))
|
| 56 |
+
|
| 57 |
+
def rand_time(r):
|
| 58 |
+
return f"{r.randint(0,23):02d}:{r.choice([0,5,10,15,20,25,30,35,40,45,50,55]):02d}"
|
| 59 |
+
|
| 60 |
+
def rand_date(r):
|
| 61 |
+
return r.choice(["oggi","domani","lunedì","martedì","mercoledì","giovedì","venerdì","sabato","domenica",f"2026-{r.randint(1,12):02d}-{r.randint(1,28):02d}"])
|
| 62 |
+
|
| 63 |
+
def rand_song(r):
|
| 64 |
+
return " ".join(w.capitalize() for w in r.sample(WORDS, r.randint(1,4)))
|
| 65 |
+
|
| 66 |
+
def uniq(r):
|
| 67 |
+
return rand_word(r, 8)
|
| 68 |
+
|
| 69 |
+
def noisy_suffix(r):
|
| 70 |
+
# Piccolo identificatore naturale per rendere unico l'esempio senza cambiare il senso.
|
| 71 |
+
return r.choice([
|
| 72 |
+
f" richiesta {uniq(r)}",
|
| 73 |
+
f" per favore {uniq(r)}",
|
| 74 |
+
f" grazie {uniq(r)}",
|
| 75 |
+
f" id {uniq(r)}",
|
| 76 |
+
f" riferimento {uniq(r)}",
|
| 77 |
+
])
|
| 78 |
+
|
| 79 |
+
def row(messages, category):
|
| 80 |
+
return {"messages": messages, "source": "scugnizz-agentic-repair-v3", "category": category}
|
| 81 |
+
|
| 82 |
+
def one(system, user, assistant, category):
|
| 83 |
+
return row([
|
| 84 |
+
{"role": "system", "content": system},
|
| 85 |
+
{"role": "user", "content": user},
|
| 86 |
+
{"role": "assistant", "content": assistant},
|
| 87 |
+
], category)
|
| 88 |
+
|
| 89 |
+
def sys_renderer():
|
| 90 |
+
return (
|
| 91 |
+
"Se ricevi TOOL_RESULT o PAYLOAD, NON chiamare strumenti.\n"
|
| 92 |
+
"Rispondi solo usando i dati presenti.\n"
|
| 93 |
+
"Non inventare email, eventi, dispositivi, nomi, tool o valori.\n"
|
| 94 |
+
"Copia numeri, hash, IP, porte, domini, URL e percentuali esattamente."
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
def system_with_tools(lines):
|
| 98 |
+
return "\n".join([
|
| 99 |
+
"You can call tools when needed.",
|
| 100 |
+
"Use only the available tool names and copy arguments exactly.",
|
| 101 |
+
"If the user request requires a tool, answer only with TOOL_CALL.",
|
| 102 |
+
"",
|
| 103 |
+
"Available tools:",
|
| 104 |
+
*lines
|
| 105 |
+
])
|
| 106 |
+
|
| 107 |
+
def tool_line(name, required):
|
| 108 |
+
return f"- {name} | required: {', '.join(required)}" if required else f"- {name}"
|
| 109 |
+
|
| 110 |
+
def call(name, args):
|
| 111 |
+
return "TOOL_CALL:\n" + jd({"name": name, "arguments": args})
|
| 112 |
+
|
| 113 |
+
def renderer_weather(r):
|
| 114 |
+
city, cond = r.choice(CITIES), r.choice(CONDITIONS)
|
| 115 |
+
temp, wind, hum = r.randint(-10,42), r.randint(0,100), r.randint(10,99)
|
| 116 |
+
payload = {"tool":"weather.forecast","result":{"city":city,"condition":cond,"temperature_c":temp,"wind_kmh":wind,"humidity":hum,"uuid":secrets.token_hex(4)}}
|
| 117 |
+
prompts = [
|
| 118 |
+
"Rispondi in italiano usando solo città, meteo, temperatura, vento e umidità. Ignora uuid.",
|
| 119 |
+
"Scrivi una frase naturale. Non aggiungere email, calendario o altri dati.",
|
| 120 |
+
"Usa esclusivamente i dati utili del risultato meteo."
|
| 121 |
+
]
|
| 122 |
+
user = f"TOOL_RESULT:\n{jd(payload)}\n\n{r.choice(prompts)}"
|
| 123 |
+
ans = f"A {city} il meteo è {cond}, con {temp} °C, vento a {wind} km/h e umidità al {hum}%."
|
| 124 |
+
return one(sys_renderer(), user, ans, "renderer_weather")
|
| 125 |
+
|
| 126 |
+
def renderer_finance(r):
|
| 127 |
+
sym = r.choice(STOCKS)
|
| 128 |
+
price = f"{r.randint(1,9999)}.{r.randint(0,99):02d}"
|
| 129 |
+
cur = "EUR" if sym in ["VWCE","ENI","ISP","RACE","UCG","G","PST"] else "USD"
|
| 130 |
+
ch = f"{r.uniform(-15,15):.2f}"
|
| 131 |
+
payload = {"tool":"finance.quote","result":{"symbol":sym,"price":price,"currency":cur,"change_percent":ch,"request_id":secrets.token_hex(3)}}
|
| 132 |
+
user = f"TOOL_RESULT:\n{jd(payload)}\n\nRispondi in italiano. Non chiamare tool. Copia ESATTAMENTE prezzo, valuta e percentuale. Ignora request_id."
|
| 133 |
+
ans = f"{sym} quota {price} {cur}, con variazione del {ch}%."
|
| 134 |
+
return one(sys_renderer(), user, ans, "renderer_finance")
|
| 135 |
+
|
| 136 |
+
def renderer_spotify(r):
|
| 137 |
+
artist = r.choice(ARTISTS)
|
| 138 |
+
title = rand_song(r)
|
| 139 |
+
album = rand_song(r) + " " + str(r.randint(1960,2026))
|
| 140 |
+
track = r.randint(1,24)
|
| 141 |
+
duration = r.randint(90,520)
|
| 142 |
+
payload = {"tool":"spotify.current_song","result":{"artist":artist,"title":title,"album":album,"track":track,"duration_s":duration}}
|
| 143 |
+
user = f"TOOL_RESULT:\n{jd(payload)}\n\nTrasforma il risultato in italiano usando solo i valori presenti."
|
| 144 |
+
ans = f"Stai ascoltando {title} di {artist}, dall'album {album}. Traccia {track}, durata {duration} secondi."
|
| 145 |
+
return one(sys_renderer(), user, ans, "renderer_spotify")
|
| 146 |
+
|
| 147 |
+
def renderer_mail(r):
|
| 148 |
+
unread = r.randint(0,250); important = r.randint(0, min(50, unread)); sender = r.choice(FIRST)
|
| 149 |
+
subject = r.choice(["Fattura","Report","Aggiornamento","Riunione","Richiesta","Avviso","Scadenza"]) + " " + rand_word(r,5)
|
| 150 |
+
payload = {"tool":"mail.summary","result":{"unread":unread,"important":important,"latest_sender":sender,"latest_subject":subject}}
|
| 151 |
+
user = f"TOOL_RESULT:\n{jd(payload)}\n\nUsa solo questi dati. Non inventare altro."
|
| 152 |
+
ans = f"Hai {unread} email non lette, di cui {important} importanti. L'ultima è di {sender}, con oggetto: {subject}."
|
| 153 |
+
return one(sys_renderer(), user, ans, "renderer_mail")
|
| 154 |
+
|
| 155 |
+
def renderer_calendar(r):
|
| 156 |
+
title, date, time = r.choice(EVENTS)+" "+rand_word(r,4), rand_date(r), rand_time(r)
|
| 157 |
+
location = r.choice(["ufficio","online","sala riunioni","Questura","Udine","Trieste","remoto","sede centrale"])
|
| 158 |
+
payload = {"tool":"calendar.next_event","result":{"title":title,"date":date,"time":time,"location":location}}
|
| 159 |
+
user = f"TOOL_RESULT:\n{jd(payload)}\n\nRispondi in italiano usando solo questi dati."
|
| 160 |
+
ans = f"Il prossimo evento è {title}, {date} alle {time}, presso {location}."
|
| 161 |
+
return one(sys_renderer(), user, ans, "renderer_calendar")
|
| 162 |
+
|
| 163 |
+
def renderer_dns(r):
|
| 164 |
+
domain = rand_domain(r); ipv4 = rand_ipv4(r, keep_zeros=r.choice([True,False])); mx = "mail-" + rand_word(r,4) + "." + domain
|
| 165 |
+
ns = "ns" + str(r.randint(1,4)) + "." + rand_domain(r)
|
| 166 |
+
payload = {"tool":"dns.lookup","result":{"domain":domain,"ipv4":ipv4,"mx":mx,"ns":ns}}
|
| 167 |
+
user = f"TOOL_RESULT:\n{jd(payload)}\n\nRispondi usando solo dominio, IPv4, MX e NS. Copia i valori esattamente."
|
| 168 |
+
ans = f"Il dominio {domain} ha IPv4 {ipv4}, record MX {mx} e nameserver {ns}."
|
| 169 |
+
return one(sys_renderer(), user, ans, "renderer_dns")
|
| 170 |
+
|
| 171 |
+
def renderer_whois(r):
|
| 172 |
+
domain = rand_domain(r)
|
| 173 |
+
registrar = r.choice(["ICANN","Namecheap","IONOS","Gandi","Cloudflare","Register.it","Aruba","OVH","GoDaddy"])
|
| 174 |
+
created = f"{r.randint(1995,2026)}-{r.randint(1,12):02d}-{r.randint(1,28):02d}"
|
| 175 |
+
payload = {"tool":"whois.lookup","result":{"domain":domain,"registrar":registrar,"created":created}}
|
| 176 |
+
user = f"TOOL_RESULT:\n{jd(payload)}\n\nRispondi usando solo questi dati. Non aggiungere next steps."
|
| 177 |
+
ans = f"Il dominio {domain} risulta registrato presso {registrar}; data di creazione: {created}."
|
| 178 |
+
return one(sys_renderer(), user, ans, "renderer_whois")
|
| 179 |
+
|
| 180 |
+
def renderer_json_complex(r):
|
| 181 |
+
city = r.choice(CITIES); temp = r.randint(-5,40); unread = r.randint(0,50)
|
| 182 |
+
title, time = r.choice(EVENTS)+" "+rand_word(r,3), rand_time(r)
|
| 183 |
+
room, device, state = r.choice(ROOMS), r.choice(DEVICES), r.choice(["aperto","chiuso","attivo","spento","online","offline"])
|
| 184 |
+
payload = {"weather":{"city":city,"temperature_c":temp,"condition":r.choice(CONDITIONS)},"mail":{"unread":unread,"latest_sender":r.choice(FIRST)},"calendar":{"title":title,"time":time},"home":{"room":room,"device":device,"state":state}}
|
| 185 |
+
user = f"Trasforma questo JSON in italiano. Usa solo i valori presenti.\n\n{jd(payload)}"
|
| 186 |
+
ans = f"A {city} il meteo è {payload['weather']['condition']} con {temp} °C. Hai {unread} email non lette; l'ultima è di {payload['mail']['latest_sender']}. Il prossimo evento è {title} alle {time}. Il dispositivo {device} in {room} risulta {state}."
|
| 187 |
+
return one(sys_renderer(), user, ans, "renderer_json_complex")
|
| 188 |
+
|
| 189 |
+
def exact_hash(r):
|
| 190 |
+
sha256, md5, sha1 = secrets.token_hex(32), secrets.token_hex(16), secrets.token_hex(20)
|
| 191 |
+
size = r.randint(1, 10_000_000_000)
|
| 192 |
+
payload = {"file":{"sha256":sha256,"md5":md5,"sha1":sha1,"size_bytes":size}}
|
| 193 |
+
user = f"PAYLOAD:\n{jd(payload)}\n\nRispondi in italiano copiando ESATTAMENTE sha256, sha1, md5 e size_bytes."
|
| 194 |
+
ans = f"SHA256: {sha256}. SHA1: {sha1}. MD5: {md5}. Dimensione: {size} byte."
|
| 195 |
+
return one(sys_renderer(), user, ans, "exact_hash")
|
| 196 |
+
|
| 197 |
+
def exact_network(r):
|
| 198 |
+
ipv4, ipv6, mac = rand_ipv4(r, True), rand_ipv6(r), rand_mac(r)
|
| 199 |
+
port, proto = r.randint(1,65535), r.choice(["TCP","UDP"])
|
| 200 |
+
payload = {"network":{"ipv4":ipv4,"ipv6":ipv6,"mac":mac,"port":port,"protocol":proto},"debug":"ignore"}
|
| 201 |
+
user = f"PAYLOAD:\n{jd(payload)}\n\nVerbalizza i dati. Non cambiare nessun numero, zero iniziale o separatore. Ignora debug."
|
| 202 |
+
ans = f"Endpoint {proto} {ipv4}:{port}. IPv6 {ipv6}. MAC {mac}."
|
| 203 |
+
return one(sys_renderer(), user, ans, "exact_network")
|
| 204 |
+
|
| 205 |
+
def exact_url_domain(r):
|
| 206 |
+
url, domain = rand_url(r), rand_domain(r)
|
| 207 |
+
score = r.randint(0,100)
|
| 208 |
+
payload = {"url":url,"domain":domain,"risk_score":score}
|
| 209 |
+
user = f"PAYLOAD:\n{jd(payload)}\n\nCopia esattamente URL, dominio e risk_score."
|
| 210 |
+
ans = f"URL: {url}. Dominio: {domain}. Risk score: {score}."
|
| 211 |
+
return one(sys_renderer(), user, ans, "exact_url_domain")
|
| 212 |
+
|
| 213 |
+
def tool_weather(r):
|
| 214 |
+
city = r.choice(CITIES)
|
| 215 |
+
sys = system_with_tools([tool_line("weather.forecast", ["city"])])
|
| 216 |
+
user = r.choice([
|
| 217 |
+
f"Che tempo fa a {city}?",
|
| 218 |
+
f"Mi dici il meteo di {city}?",
|
| 219 |
+
f"Weather for {city}.",
|
| 220 |
+
f"Vorrei conoscere le previsioni per {city}.",
|
| 221 |
+
f"Meteo {city}, grazie.",
|
| 222 |
+
f"Controlla il tempo a {city}.",
|
| 223 |
+
f"Serve il meteo aggiornato per {city}.",
|
| 224 |
+
f"Dimmi temperatura e condizioni a {city}.",
|
| 225 |
+
]) + noisy_suffix(r)
|
| 226 |
+
return one(sys, user, call("weather.forecast", {"city": city}), "tool_weather")
|
| 227 |
+
|
| 228 |
+
def tool_finance(r):
|
| 229 |
+
sym = r.choice(STOCKS)
|
| 230 |
+
sys = system_with_tools([tool_line("finance.quote", ["symbol"])])
|
| 231 |
+
user = r.choice([
|
| 232 |
+
f"Quanto quota {sym}?",
|
| 233 |
+
f"Prezzo attuale di {sym}.",
|
| 234 |
+
f"Quote for {sym}.",
|
| 235 |
+
f"Controlla la quotazione {sym}.",
|
| 236 |
+
f"Mi dai il valore di {sym}?",
|
| 237 |
+
f"Valore corrente ticker {sym}.",
|
| 238 |
+
f"Controlla il prezzo del titolo {sym}.",
|
| 239 |
+
]) + noisy_suffix(r)
|
| 240 |
+
return one(sys, user, call("finance.quote", {"symbol": sym}), "tool_finance")
|
| 241 |
+
|
| 242 |
+
def tool_dns(r):
|
| 243 |
+
domain, rt = rand_domain(r), r.choice(["A","AAAA","MX","NS","TXT"])
|
| 244 |
+
sys = system_with_tools([tool_line("dns.lookup", ["domain","record_type"])])
|
| 245 |
+
user = r.choice([f"Qual è il record {rt} di {domain}?", f"Risolvi {domain} record {rt}.", f"DNS {rt} per {domain}."])
|
| 246 |
+
return one(sys, user, call("dns.lookup", {"domain": domain, "record_type": rt}), "tool_dns")
|
| 247 |
+
|
| 248 |
+
def tool_spotify(r):
|
| 249 |
+
sys = system_with_tools([tool_line("spotify.current_song", [])])
|
| 250 |
+
user = r.choice([
|
| 251 |
+
"Che brano sto ascoltando?",
|
| 252 |
+
"Che canzone sta suonando?",
|
| 253 |
+
"Current song?",
|
| 254 |
+
"Dimmi la canzone in riproduzione.",
|
| 255 |
+
"Qual è il brano corrente?",
|
| 256 |
+
"Identifica la traccia attuale.",
|
| 257 |
+
"Cosa sta andando ora su Spotify?",
|
| 258 |
+
]) + noisy_suffix(r)
|
| 259 |
+
return one(sys, user, call("spotify.current_song", {}), "tool_spotify")
|
| 260 |
+
|
| 261 |
+
def tool_mail(r):
|
| 262 |
+
sys = system_with_tools([tool_line("unread_mail_count", [])])
|
| 263 |
+
user = r.choice([
|
| 264 |
+
"Quante email non lette ho?",
|
| 265 |
+
"Unread emails?",
|
| 266 |
+
"Controlla le mail non lette.",
|
| 267 |
+
"Quanta posta non letta c'è?",
|
| 268 |
+
"Dimmi il numero di email da leggere.",
|
| 269 |
+
"Verifica la posta non letta.",
|
| 270 |
+
"Conta le email ancora da leggere.",
|
| 271 |
+
]) + noisy_suffix(r)
|
| 272 |
+
return one(sys, user, call("unread_mail_count", {}), "tool_mail")
|
| 273 |
+
|
| 274 |
+
def tool_calendar(r):
|
| 275 |
+
sys = system_with_tools([tool_line("calendar.next_event", [])])
|
| 276 |
+
user = r.choice([
|
| 277 |
+
"Qual è il mio prossimo appuntamento?",
|
| 278 |
+
"Cosa ho in agenda?",
|
| 279 |
+
"Next calendar event?",
|
| 280 |
+
"Dimmi il prossimo evento.",
|
| 281 |
+
"Qual è la prossima riunione?",
|
| 282 |
+
"Controlla il prossimo evento in calendario.",
|
| 283 |
+
"Che appuntamento ho dopo?",
|
| 284 |
+
]) + noisy_suffix(r)
|
| 285 |
+
return one(sys, user, call("calendar.next_event", {}), "tool_calendar")
|
| 286 |
+
|
| 287 |
+
RENDERERS = [renderer_weather, renderer_finance, renderer_spotify, renderer_mail, renderer_calendar, renderer_dns, renderer_whois, renderer_json_complex]
|
| 288 |
+
EXACTS = [exact_hash, exact_network, exact_url_domain]
|
| 289 |
+
TOOLS = [tool_weather, tool_finance, tool_dns, tool_spotify, tool_mail, tool_calendar]
|
| 290 |
+
|
| 291 |
+
def stable(obj):
|
| 292 |
+
return hashlib.sha256(jd(obj["messages"]).encode("utf-8")).hexdigest()
|
| 293 |
+
|
| 294 |
+
def add_unique(rows, seen, counts, gen, r, target):
|
| 295 |
+
made = 0
|
| 296 |
+
attempts = 0
|
| 297 |
+
while made < target and attempts < target * 20:
|
| 298 |
+
attempts += 1
|
| 299 |
+
obj = gen(r)
|
| 300 |
+
k = stable(obj)
|
| 301 |
+
if k in seen:
|
| 302 |
+
continue
|
| 303 |
+
seen.add(k); rows.append(obj)
|
| 304 |
+
counts[obj["category"]] = counts.get(obj["category"], 0) + 1
|
| 305 |
+
made += 1
|
| 306 |
+
if made < target:
|
| 307 |
+
raise RuntimeError(f"Categoria {gen.__name__} ha prodotto solo {made}/{target} esempi unici")
|
| 308 |
+
print(f"{gen.__name__}: {made}", flush=True)
|
| 309 |
+
|
| 310 |
+
def generate(out_dir, n_renderer, n_exact, n_tool, val_size, seed):
|
| 311 |
+
r = random.Random(seed)
|
| 312 |
+
out = Path(out_dir); out.mkdir(parents=True, exist_ok=True)
|
| 313 |
+
rows, seen, counts = [], set(), {}
|
| 314 |
+
|
| 315 |
+
for idx, gen in enumerate(RENDERERS):
|
| 316 |
+
target = n_renderer // len(RENDERERS) + (1 if idx < n_renderer % len(RENDERERS) else 0)
|
| 317 |
+
add_unique(rows, seen, counts, gen, r, target)
|
| 318 |
+
|
| 319 |
+
for idx, gen in enumerate(EXACTS):
|
| 320 |
+
target = n_exact // len(EXACTS) + (1 if idx < n_exact % len(EXACTS) else 0)
|
| 321 |
+
add_unique(rows, seen, counts, gen, r, target)
|
| 322 |
+
|
| 323 |
+
for idx, gen in enumerate(TOOLS):
|
| 324 |
+
target = n_tool // len(TOOLS) + (1 if idx < n_tool % len(TOOLS) else 0)
|
| 325 |
+
add_unique(rows, seen, counts, gen, r, target)
|
| 326 |
+
|
| 327 |
+
r.shuffle(rows)
|
| 328 |
+
val_n = min(val_size, max(1, len(rows)//100))
|
| 329 |
+
val, train = rows[:val_n], rows[val_n:]
|
| 330 |
+
|
| 331 |
+
with (out/"train.jsonl").open("w", encoding="utf-8") as f:
|
| 332 |
+
for obj in train: f.write(json.dumps(obj, ensure_ascii=False) + "\n")
|
| 333 |
+
with (out/"validation.jsonl").open("w", encoding="utf-8") as f:
|
| 334 |
+
for obj in val: f.write(json.dumps(obj, ensure_ascii=False) + "\n")
|
| 335 |
+
(out/"README.md").write_text(
|
| 336 |
+
"---\nlicense: cc-by-4.0\nlanguage:\n- it\n- en\ntask_categories:\n- text-generation\n---\n\n# Scugnizz Agentic Repair 50k v3\n\n"
|
| 337 |
+
+ json.dumps(counts, ensure_ascii=False, indent=2),
|
| 338 |
+
encoding="utf-8"
|
| 339 |
+
)
|
| 340 |
+
print("DONE", out, "TRAIN", len(train), "VAL", len(val), flush=True)
|
| 341 |
+
print(json.dumps(counts, ensure_ascii=False, indent=2), flush=True)
|
| 342 |
+
print("SAMPLE", json.dumps(rows[0], ensure_ascii=False)[:2000], flush=True)
|
| 343 |
+
return out
|
| 344 |
+
|
| 345 |
+
def upload(folder, repo_id, private=False):
|
| 346 |
+
token = os.environ.get("HF_TOKEN") or os.environ.get("UV_SCRIPT_HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
| 347 |
+
api = HfApi(token=token)
|
| 348 |
+
api.create_repo(repo_id, repo_type="dataset", private=private, exist_ok=True)
|
| 349 |
+
upload_folder(repo_id=repo_id, repo_type="dataset", folder_path=str(folder), commit_message="Add Scugnizz agentic repair dataset v3", token=token)
|
| 350 |
+
print("UPLOADED", repo_id, flush=True)
|
| 351 |
+
|
| 352 |
+
def main():
|
| 353 |
+
p = argparse.ArgumentParser()
|
| 354 |
+
p.add_argument("--out-dir", default="data/scugnizz-agentic-repair-50k-v3")
|
| 355 |
+
p.add_argument("--repo-id", default="ProjectScugnizz/scugnizz-agentic-repair-50k-v3")
|
| 356 |
+
p.add_argument("--n-renderer", type=int, default=30000)
|
| 357 |
+
p.add_argument("--n-exact", type=int, default=10000)
|
| 358 |
+
p.add_argument("--n-tool", type=int, default=10000)
|
| 359 |
+
p.add_argument("--val-size", type=int, default=1000)
|
| 360 |
+
p.add_argument("--seed", type=int, default=20260710)
|
| 361 |
+
p.add_argument("--upload", action="store_true")
|
| 362 |
+
p.add_argument("--private", action="store_true")
|
| 363 |
+
a = p.parse_args()
|
| 364 |
+
folder = generate(a.out_dir, a.n_renderer, a.n_exact, a.n_tool, a.val_size, a.seed)
|
| 365 |
+
if a.upload:
|
| 366 |
+
upload(folder, a.repo_id, a.private)
|
| 367 |
+
|
| 368 |
+
if __name__ == "__main__":
|
| 369 |
+
main()
|