1818from pathlib import Path
1919
2020import jsonschema
21- from a2ui_schema import A2UI_SCHEMA
21+ from a2ui . core . validator import A2uiValidator
2222
2323logger = logging .getLogger (__name__ )
2424
3434
3535FLOOR_PLAN_FILE = "floor_plan.json"
3636
37- def load_examples (base_url : str = "http://localhost:10004" ) -> str :
37+ def load_examples (validator : A2uiValidator , base_url : str = "http://localhost:10004" ) -> str :
3838 """
3939 Loads, validates, and formats the UI examples from JSON files.
4040
4141 Args:
42+ validator: The validator to use for validation.
4243 base_url: The base URL to replace placeholder URLs with.
4344 (Currently examples have http://localhost:10004 hardcoded,
4445 but we can make this dynamic if needed).
@@ -47,15 +48,6 @@ def load_examples(base_url: str = "http://localhost:10004") -> str:
4748 A string containing all formatted examples for the prompt.
4849 """
4950
50- # Pre-parse validator
51- try :
52- single_msg_schema = json .loads (A2UI_SCHEMA )
53- # Examples are typically lists of messages
54- list_schema = {"type" : "array" , "items" : single_msg_schema }
55- except json .JSONDecodeError :
56- logger .error ("Failed to parse A2UI_SCHEMA for validation" )
57- list_schema = None
58-
5951 examples_dir = Path (os .path .dirname (__file__ )) / "examples"
6052 formatted_output = []
6153
@@ -68,12 +60,11 @@ def load_examples(base_url: str = "http://localhost:10004") -> str:
6860 # content = content.replace("{{BASE_URL}}", base_url)
6961
7062 # Validation
71- if list_schema :
72- try :
73- data = json .loads (content )
74- jsonschema .validate (instance = data , schema = list_schema )
75- except (json .JSONDecodeError , jsonschema .ValidationError ) as e :
76- logger .warning (f"Example { filename } validation failed: { e } " )
63+ try :
64+ data = json .loads (content )
65+ validator .validate (instance = data )
66+ except (json .JSONDecodeError , jsonschema .ValidationError ) as e :
67+ logger .warning (f"Example { filename } validation failed: { e } " )
7768
7869 formatted_output .append (f"---BEGIN { curr_name } ---" )
7970 # Handle examples that include user/model text
0 commit comments