47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.4 KiB
3.4 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| sdcli_generate | function | go | ml | 1.0.0 | impure | func SdcliGenerate(ctx context.Context, bin SdcliBinary, cfg GenerationConfig, outPath string, onProgress SdcliProgressCallback) (ImageGenResult, error) | Ejecuta el binario sd de stable-diffusion.cpp para generar una imagen. Construye los args CLI via GenconfigToSdcliArgs, lanza el proceso via SubprocessStream, parsea el progreso de stderr en tiempo real via SdcliParseProgress, y retorna ImageGenResult con los bytes PNG, metadata y duration_ms. |
|
|
|
false | error_go_core |
|
|
ImageGenResult con ImageBytes (bytes del PNG), Format='png', Meta (backend, binary_path, model, seed, steps, etc.) y DurationMs medido desde el inicio de la llamada. | true |
|
functions/ml/sdcli_test.go | functions/ml/sdcli_generate.go |
Ejemplo
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
bin, err := SdcliResolveBinary("")
if err != nil {
log.Fatal(err)
}
cfg := GenerationConfig{
Prompt: "a red apple on a wooden table",
Seed: 42,
Steps: 20,
CfgScale: 7.0,
Sampler: "euler_a",
Width: 512,
Height: 512,
Model: ModelRef{
Name: "sd15",
ModelType: "sd15",
Quantization: "fp16",
Path: "/path/to/model.safetensors",
},
}
result, err := SdcliGenerate(ctx, bin, cfg, "/tmp/out.png", func(p SdcliProgress) {
fmt.Printf("step %d/%d (%.1f%%)\n", p.Step, p.TotalSteps, p.Percent)
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("generated %d bytes in %dms\n", len(result.ImageBytes), result.DurationMs)
Notas
El binario sd de stable-diffusion.cpp escribe la imagen directamente en disco
(-o outPath). La funcion lee el archivo tras la finalizacion del proceso y
carga los bytes en ImageGenResult.ImageBytes.
Si el proceso termina con ExitCode != 0, el error incluye las ultimas 10 lineas
de stderr para facilitar el diagnostico.
El callback onProgress se llama desde la goroutine de lectura de eventos.
Si el callback hace I/O o es lento, considera usar un canal con buffer para
desacoplar.
Para modelos SD Turbo / SDXL Turbo con steps <= 4 y cfg_scale = 1.0, el
sampler euler_a es el recomendado. Para SD 1.5 estandar usar euler o
dpm++2m con steps >= 20.