chore: auto-commit (95 archivos)
- cmd/fn/doctor.go - cmd/fn/main.go - cpp/apps/primitives_gallery/playground/tables/CMakeLists.txt - cpp/apps/primitives_gallery/playground/tables/data_table.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.h - cpp/apps/primitives_gallery/playground/tables/self_test.cpp - cpp/apps/primitives_gallery/playground/tables/tql.cpp - cpp/apps/primitives_gallery/playground/tables/viz.cpp - cpp/apps/primitives_gallery/playground/tables/viz.h - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
---
|
||||
name: genconfig_save_json
|
||||
kind: function
|
||||
lang: py
|
||||
domain: ml
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "def genconfig_save_json(cfg: GenerationConfig, path: str) -> str"
|
||||
description: "Serializa un GenerationConfig a JSON (pydantic model_dump_json o dataclass fallback) y lo escribe en disco. Crea directorios padre si no existen. Retorna el path absoluto del archivo escrito."
|
||||
tags: [ml, generation, json, io, serialization]
|
||||
params:
|
||||
- name: cfg
|
||||
desc: "Instancia de GenerationConfig a serializar. Pydantic o dataclass."
|
||||
- name: path
|
||||
desc: "Ruta de destino del archivo JSON. Relativa o absoluta."
|
||||
output: "Path absoluto (str) del archivo JSON escrito en disco."
|
||||
uses_functions: []
|
||||
uses_types:
|
||||
- generation_config_py_ml
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: []
|
||||
tested: true
|
||||
tests:
|
||||
- "save escribe archivo JSON valido en la ruta indicada"
|
||||
- "save crea directorios padre si no existen"
|
||||
- "json contiene claves en snake_case"
|
||||
test_file_path: "python/functions/ml/tests/test_genconfig_json_roundtrip.py"
|
||||
file_path: "python/functions/ml/genconfig_save_json.py"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```python
|
||||
from ml.genconfig_save_json import genconfig_save_json
|
||||
from ml.generation_config import GenerationConfig
|
||||
from ml.model_ref import ModelRef
|
||||
|
||||
cfg = GenerationConfig(
|
||||
prompt="a forest at dusk",
|
||||
seed=123,
|
||||
steps=25,
|
||||
cfg_scale=7.5,
|
||||
sampler="euler",
|
||||
width=512,
|
||||
height=512,
|
||||
model=ModelRef(name="runwayml/stable-diffusion-v1-5", model_type="sd15"),
|
||||
)
|
||||
|
||||
saved_path = genconfig_save_json(cfg, "/tmp/gen_config.json")
|
||||
# saved_path == "/tmp/gen_config.json"
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Usa pydantic model_dump_json cuando disponible (JSON canonico con snake_case
|
||||
interoperable con Go). En entornos sin pydantic usa json.dumps + dataclasses.asdict.
|
||||
Los directorios padre se crean con os.makedirs(exist_ok=True).
|
||||
Reference in New Issue
Block a user