11from .batch_fetch import BatchFetchManager
22from .crawl import WebCrawlManager
3- from hyperbrowser .exceptions import HyperbrowserError
43from hyperbrowser .models import (
54 FetchParams ,
65 FetchResponse ,
76 WebSearchParams ,
87 WebSearchResponse ,
98)
109from ....schema_utils import inject_web_output_schemas
10+ from ...serialization_utils import serialize_model_dump_to_dict
1111from ...response_utils import parse_response_model
1212
1313
@@ -18,17 +18,10 @@ def __init__(self, client):
1818 self .crawl = WebCrawlManager (client )
1919
2020 async def fetch (self , params : FetchParams ) -> FetchResponse :
21- try :
22- payload = params .model_dump (exclude_none = True , by_alias = True )
23- except HyperbrowserError :
24- raise
25- except Exception as exc :
26- raise HyperbrowserError (
27- "Failed to serialize web fetch params" ,
28- original_error = exc ,
29- ) from exc
30- if type (payload ) is not dict :
31- raise HyperbrowserError ("Failed to serialize web fetch params" )
21+ payload = serialize_model_dump_to_dict (
22+ params ,
23+ error_message = "Failed to serialize web fetch params" ,
24+ )
3225 inject_web_output_schemas (
3326 payload , params .outputs .formats if params .outputs else None
3427 )
@@ -44,17 +37,10 @@ async def fetch(self, params: FetchParams) -> FetchResponse:
4437 )
4538
4639 async def search (self , params : WebSearchParams ) -> WebSearchResponse :
47- try :
48- payload = params .model_dump (exclude_none = True , by_alias = True )
49- except HyperbrowserError :
50- raise
51- except Exception as exc :
52- raise HyperbrowserError (
53- "Failed to serialize web search params" ,
54- original_error = exc ,
55- ) from exc
56- if type (payload ) is not dict :
57- raise HyperbrowserError ("Failed to serialize web search params" )
40+ payload = serialize_model_dump_to_dict (
41+ params ,
42+ error_message = "Failed to serialize web search params" ,
43+ )
5844 response = await self ._client .transport .post (
5945 self ._client ._build_url ("/web/search" ),
6046 data = payload ,
0 commit comments