generated from coulomb/repo-seed
Forward instruction schemas to llm-connect
This commit is contained in:
@@ -180,7 +180,10 @@ def _llm_run_config(instr: Any) -> dict[str, Any]:
|
||||
value = getattr(instr, field, None)
|
||||
if value is not None:
|
||||
config[field] = value
|
||||
model_params = getattr(instr, "model_params", None)
|
||||
model_params = dict(getattr(instr, "model_params", None) or {})
|
||||
schema = _load_output_schema(getattr(instr, "output_schema", ""))
|
||||
if schema is not None:
|
||||
model_params.setdefault("json_schema", schema)
|
||||
if model_params:
|
||||
config["model_params"] = model_params
|
||||
return config
|
||||
@@ -263,16 +266,33 @@ def _validate_against_schema(data: Any, schema_path: str) -> str | None:
|
||||
if not schema_path:
|
||||
return None
|
||||
|
||||
try:
|
||||
schema = _load_output_schema(schema_path)
|
||||
except (OSError, json.JSONDecodeError, TypeError) as exc:
|
||||
return f"could not read output schema: {exc}"
|
||||
if schema is None:
|
||||
return None
|
||||
|
||||
return _validate_schema_node(data, schema, "$")
|
||||
|
||||
|
||||
def _load_output_schema(schema_path: str) -> dict[str, Any] | None:
|
||||
"""Load a JSON schema file when present.
|
||||
|
||||
Missing schema files are intentionally tolerated for backward
|
||||
compatibility with existing tests and definitions.
|
||||
"""
|
||||
if not schema_path:
|
||||
return None
|
||||
|
||||
path = Path(schema_path)
|
||||
if not path.exists():
|
||||
return None
|
||||
|
||||
try:
|
||||
schema = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError) as exc:
|
||||
return f"could not read output schema: {exc}"
|
||||
|
||||
return _validate_schema_node(data, schema, "$")
|
||||
schema = json.loads(path.read_text(encoding="utf-8"))
|
||||
if not isinstance(schema, dict):
|
||||
raise TypeError("output schema must be a JSON object")
|
||||
return schema
|
||||
|
||||
|
||||
def _validate_schema_node(data: Any, schema: dict[str, Any], path: str) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user