Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate extracted data against schema #132

Merged
merged 21 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bananalyzer/runner/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ async def result(self, page, agent_constructor):
agent = agent_constructor()
try:
data = await agent.run(page, self.example)
validator = PydanticSchemaParser(self.example.schema_)
if self.example.type == "detail":
validated_data = validator.validate(data, self.example.url)
elif self.example.type == "listing_detail":
validated_data = []
for d in data:
validated_data.append(validator.validate(d, self.example.url))
else:
validated_data = data
except Exception as e:
error = e
yield data, error
yield validated_data, error

{"".join(self._generate_eval_test(eval_, i, {
"category": example.category,
Expand Down
1 change: 1 addition & 0 deletions bananalyzer/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def create_test_file(

from bananalyzer.data.examples import get_example_by_url
from playwright.async_api import async_playwright
from harambe.parser.parser import PydanticSchemaParser

@pytest.fixture(scope="session")
def event_loop():
Expand Down
Loading
Loading