run-llama / llama_extract

MIT License
105 stars 16 forks source link

TypeError: BaseModel.validate() takes 2 positional arguments but 3 were given #37

Open pn12 opened 2 weeks ago

pn12 commented 2 weeks ago

I am running the below example :

from llama_extract import LlamaExtract

extractor = LlamaExtract()

extraction_schema = extractor.infer_schema("Test Schema", ["./file1.pdf","./file2.pdf"])

On executing, I get the below error:


TypeError                                 Traceback (most recent call last)
Cell In[38], line 1
----> 1 extraction_schema = extractor.infer_schema("Test_Schema",["./file1.pdf","./file2.pdf"])

File /home/pn12/ubuntu/env3/lib/python3.10/site-packages/llama_extract/base.py:235, in LlamaExtract.infer_schema(self, name, seed_files, schema_id, project_id)
    233 """Infer schema for a given set of seed files."""
    234 try:
--> 235     return asyncio_run(
    236         self.ainfer_schema(name, seed_files, schema_id, project_id)
    237     )
    238 except RuntimeError as e:
    239     if nest_asyncio_err in str(e):

File /home/pn12/ubuntu/env3/lib/python3.10/site-packages/llama_index/core/async_utils.py:33, in asyncio_run(coro)
     30     loop = asyncio.get_event_loop()
     32     # If we're here, there's an existing loop but it's not running
---> 33     return loop.run_until_complete(coro)
     35 except RuntimeError as e:
     36     # If we can't get the event loop, we're likely in a different thread, or its already running
     37     try:

File /home/pn12/ubuntu/env3/lib/python3.10/site-packages/nest_asyncio.py:98, in _patch_loop.<locals>.run_until_complete(self, future)
     95 if not f.done():
     96     raise RuntimeError(
     97         'Event loop stopped before Future completed.')
---> 98 return f.result()

File /usr/lib/python3.10/asyncio/futures.py:201, in Future.result(self)
    199 self.__log_traceback = False
    200 if self._exception is not None:
--> 201     raise self._exception.with_traceback(self._exception_tb)
    202 return self._result

File /usr/lib/python3.10/asyncio/tasks.py:232, in Task.__step(***failed resolving arguments***)
    228 try:
    229     if exc is None:
    230         # We use the `send` method directly, because coroutines
    231         # don't have `__iter__` and `__next__` methods.
--> 232         result = coro.send(None)
    233     else:
    234         result = coro.throw(exc)

File /home/pn12/ubuntu/env3/lib/python3.10/site-packages/llama_extract/base.py:215, in LlamaExtract.ainfer_schema(self, name, seed_files, schema_id, project_id)
    205 _response = await self._async_client._client_wrapper.httpx_client.post(
    206     urllib.parse.urljoin(
    207         f"{self._async_client._client_wrapper.get_base_url()}/",
   (...)
    211     headers=self._async_client._client_wrapper.get_headers(),
    212 )
    214 if 200 <= _response.status_code < 300:
--> 215     return pydantic.parse_obj_as(ExtractionSchema, _response.json())  # type: ignore
    216 if _response.status_code == 422:
    217     raise UnprocessableEntityError(
    218         pydantic.parse_obj_as(HttpValidationError, _response.json())
    219     )  # type: ignore

File /home/pn12/ubuntu/env3/lib/python3.10/site-packages/pydantic/deprecated/tools.py:42, in parse_obj_as(type_, obj, type_name)
     36 if type_name is not None:  # pragma: no cover
     37     warnings.warn(
     38         'The type_name parameter is deprecated. parse_obj_as no longer creates temporary models',
     39         DeprecationWarning,
     40         stacklevel=2,
     41     )
---> 42 return TypeAdapter(type_).validate_python(obj)

File /home/pn12/ubuntu/env3/lib/python3.10/site-packages/pydantic/type_adapter.py:135, in _frame_depth.<locals>.wrapper.<locals>.wrapped(self, *args, **kwargs)
    132 @wraps(func)
    133 def wrapped(self: TypeAdapterT, *args: P.args, **kwargs: P.kwargs) -> R:
    134     with self._with_frame_depth(depth + 1):  # depth + 1 for the wrapper function
--> 135         return func(self, *args, **kwargs)

File /home/pn12/ubuntu/env3/lib/python3.10/site-packages/pydantic/type_adapter.py:366, in TypeAdapter.validate_python(self, object, strict, from_attributes, context)
    341 @_frame_depth(1)
    342 def validate_python(
    343     self,
   (...)
    349     context: dict[str, Any] | None = None,
    350 ) -> T:
    351     """Validate a Python object against the model.
    352 
    353     Args:
   (...)
    364         The validated object.
    365     """
--> 366     return self.validator.validate_python(object, strict=strict, from_attributes=from_attributes, context=context)

TypeError: BaseModel.validate() takes 2 positional arguments but 3 were given