Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
feat: fix structured output schema conversion and improve error handling
Magnus Müller3e0c0f74e408
diff --git a/eval/service.py b/eval/service.pyindex 563a97746..e1240a886 100644--- a/eval/service.py+++ b/eval/service.py@@ -1087,6 +1087,8 @@ def create_pydantic_model_from_schema(schema: dict, model_name: str = 'DynamicMoif isinstance(schema, str):schema = json.loads(schema)+ logger.debug(f'Creating Pydantic model from schema: {schema}')+# Initialize paths for cleanupschema_path = Nonemodel_path = None@@ -1104,12 +1106,13 @@ def create_pydantic_model_from_schema(schema: dict, model_name: str = 'DynamicMogenerate(input_=schema_path,output=model_path,- output_model_type=DataModelType.PydanticBaseModel,+ output_model_type=DataModelType.PydanticV2BaseModel,class_name=model_name,)# Read the generated Python codegenerated_code = model_path.read_text()+ logger.debug(f'Generated Pydantic model code:\n{generated_code}')# Create a module and execute the generated codespec = importlib.util.spec_from_loader(f'dynamic_model_{model_name}', loader=None)@@ -1123,12 +1126,15 @@ def create_pydantic_model_from_schema(schema: dict, model_name: str = 'DynamicMo# Get the generated model classif hasattr(module, model_name):- return getattr(module, model_name)+ model_class = getattr(module, model_name)+ logger.debug(f'Successfully created Pydantic model: {model_class}')+ return model_classelse:# Fallback: look for any BaseModel subclass in the modulefor attr_name in dir(module):attr = getattr(module, attr_name)if isinstance(attr, type) and issubclass(attr, BaseModel) and attr != BaseModel:+ logger.debug(f'Using fallback model class: {attr}')return attrraise ValueError('No Pydantic model class found in generated code')@@ -1152,7 +1158,7 @@ def create_pydantic_model_from_schema(schema: dict, model_name: str = 'DynamicMotry:# Fallback to basic implementation if datamodel-code-generator is not available- from typing import Any+ from typing import Any, Optionalfrom pydantic import create_model@@ -1191,9 +1197,7 @@ def create_pydantic_model_from_schema(schema: dict, model_name: str = 'DynamicMoif field_name in required_fields:field_definitions[field_name] = (field_type, ...) # Required fieldelse:- from typing import Union-- optional_type = Union[field_type, None]+ optional_type = Optional[field_type] # Use Optional instead of Union[T, None]field_definitions[field_name] = (optional_type, None) # Optional field with default None# Create the dynamic model using create_model