MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _coerce_model

Function _coerce_model

openkb/cli.py:848–869  ·  view source on GitHub ↗

Strip a model string; treat blanks as unset; reject unsafe values. Mirrors ``_coerce_language``. The model string is passed to LiteLLM and also echoed in logs/CLI output, so embedded control characters would corrupt that output. Capping length keeps pathological values out of config

(value: str | None)

Source from the content-addressed store, hash-verified

846
847
848def _coerce_model(value: str | None) -> str | None:
849 """Strip a model string; treat blanks as unset; reject unsafe values.
850
851 Mirrors ``_coerce_language``. The model string is passed to LiteLLM and
852 also echoed in logs/CLI output, so embedded control characters would
853 corrupt that output. Capping length keeps pathological values out of
854 config.yaml.
855
856 Returns the cleaned string, or ``None`` if the input was missing or blank
857 after stripping. Raises ``click.BadParameter`` on unsafe input.
858 """
859 if value is None:
860 return None
861 value = value.strip()
862 if not value:
863 return None
864 if len(value) > _MODEL_MAX_LEN or any(c in value for c in "\n\r\t"):
865 raise click.BadParameter(
866 f"model must be {_MODEL_MAX_LEN} characters or fewer with no control characters",
867 param_hint="'--model'",
868 )
869 return value
870
871
872def _model_option_callback(_ctx, _param, value):

Callers 2

_model_option_callbackFunction · 0.85
initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected