a802f59f55
- 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>
3.1 KiB
3.1 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 | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| genconfig_json_marshal | function | go | ml | 1.0.0 | impure | func GenconfigMarshal(cfg GenerationConfig) ([]byte, error) func GenconfigUnmarshal(data []byte) (GenerationConfig, error) | Wrappers json.Marshal/Unmarshal para GenerationConfig con formato canonico (MarshalIndent 2 espacios). Garantiza roundtrip identico al Python: json.dumps(indent=2, sort_keys=False). Campos JSON en snake_case. |
|
|
false | error_go_core |
|
|
GenconfigMarshal: bytes JSON con indent 2 espacios, orden de campos segun declaracion del struct (prompt, negative_prompt, seed, steps, cfg_scale, sampler, width, height, model, loras, clip_skip). GenconfigUnmarshal: GenerationConfig poblado o error de parsing. | true |
|
functions/ml/genconfig_test.go | functions/ml/genconfig_json_marshal.go |
Ejemplo
cfg := ml.GenerationConfig{
Prompt: "a mountain at sunset",
Seed: 1234,
Steps: 30,
CfgScale: 7.0,
Sampler: "euler",
Width: 768,
Height: 512,
Model: ml.ModelRef{Name: "sdxl-base", ModelType: "sdxl", Quantization: "fp16"},
}
b, err := ml.GenconfigMarshal(cfg)
// b == {
// "prompt": "a mountain at sunset",
// "seed": 1234,
// ...
// }
cfg2, err := ml.GenconfigUnmarshal(b)
// cfg2 == cfg (DeepEqual)
Notas
Formato canonico y compatibilidad con Python
GenconfigMarshal usa json.MarshalIndent(cfg, "", " "). El formato resultante es identico al que produce Python con model.model_dump_json() o json.dumps(data, indent=2) cuando sort_keys=False:
- Keys en orden de declaracion del struct (no alfabetico).
- Indent de 2 espacios, sin trailing whitespace.
- Campos omitempty ausentes si zero:
negative_promptausente si"",lorasausente si[],clip_skipausente sinil.
Keys JSON (snake_case obligatorio)
| Campo Go | Key JSON |
|---|---|
Prompt |
"prompt" |
NegativePrompt |
"negative_prompt" |
Seed |
"seed" |
Steps |
"steps" |
CfgScale |
"cfg_scale" |
Sampler |
"sampler" |
Width |
"width" |
Height |
"height" |
Model.ModelType |
"model_type" |
Model.Quantization |
"quantization" |
ClipSkip |
"clip_skip" |
Por que impure
Los errores de json.Unmarshal son errores de parsing del input externo, no de I/O, pero se modelan como (T, error) para forzar manejo explicito en el caller. Marcado impure con error_type: error_go_core por convencion del registry.