NewRuntime validates and normalizes advisor runtime configuration.
(cfg RuntimeConfig)
| 35 | |
| 36 | // NewRuntime validates and normalizes advisor runtime configuration. |
| 37 | func NewRuntime(cfg RuntimeConfig) (*Runtime, error) { |
| 38 | if cfg.Model == nil { |
| 39 | return nil, xerrors.New("advisor model is required") |
| 40 | } |
| 41 | if cfg.MaxUsesPerRun <= 0 { |
| 42 | return nil, xerrors.New("advisor max uses per run must be positive") |
| 43 | } |
| 44 | if cfg.MaxOutputTokens <= 0 { |
| 45 | return nil, xerrors.New("advisor max output tokens must be positive") |
| 46 | } |
| 47 | if cfg.ModelConfig.MaxOutputTokens != nil && |
| 48 | *cfg.ModelConfig.MaxOutputTokens != cfg.MaxOutputTokens { |
| 49 | return nil, xerrors.Errorf( |
| 50 | "advisor model_config.max_output_tokens (%d) must match runtime max output tokens (%d)", |
| 51 | *cfg.ModelConfig.MaxOutputTokens, |
| 52 | cfg.MaxOutputTokens, |
| 53 | ) |
| 54 | } |
| 55 | |
| 56 | normalized := cfg |
| 57 | normalized.ProviderOptions = cloneProviderOptions(cfg.ProviderOptions) |
| 58 | maxOutputTokens := cfg.MaxOutputTokens |
| 59 | normalized.ModelConfig.MaxOutputTokens = &maxOutputTokens |
| 60 | |
| 61 | return &Runtime{cfg: normalized}, nil |
| 62 | } |
| 63 | |
| 64 | // cloneProviderOptions returns a copy of opts with pointer entries for known, |
| 65 | // in-place mutated provider option types replaced by a shallow struct copy. |