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

Error when testing code example for megaparsevision with Claude 3.5 Sonnet #172

Open
OSS-GR opened this issue Dec 7, 2024 · 0 comments
Open

Comments

@OSS-GR
Copy link

OSS-GR commented Dec 7, 2024

I was testing the megaparsevision code and I used Claude 3.5 sonnet and it spit out this error


You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.
  warnings.warn(

Traceback (most recent call last):
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/megaparse/core/megaparse.py", line 91, in load
    parsed_document: str = loop.run_until_complete(
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/.pyenv/versions/3.12.0/lib/python3.12/asyncio/base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/megaparse/core/parser/megaparse_vision.py", line 141, in convert
    self.parsed_chunks = await asyncio.gather(*tasks)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/megaparse/core/parser/megaparse_vision.py", line 114, in send_to_mlm
    response = await self.model.ainvoke([message])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 307, in ainvoke
    llm_result = await self.agenerate_prompt(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 796, in agenerate_prompt
    return await self.agenerate(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 756, in agenerate
    raise exceptions[0]
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py", line 924, in _agenerate_with_cache
    result = await self._agenerate(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/langchain_anthropic/chat_models.py", line 812, in _agenerate
    data = await self._async_client.messages.create(**payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/anthropic/resources/messages.py", line 1817, in create
    return await self._post(
           ^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/anthropic/_base_client.py", line 1842, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/anthropic/_base_client.py", line 1536, in request
    return await self._request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/anthropic/_base_client.py", line 1637, in _request
    raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.0.content.3.image.source.base64.data: The image specified was not valid'}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/orestis/Repos/test_megaparser/basic_test.py", line 15, in <module>
    response = megaparse.load("./monthly-budget-breakdown-revised.pdf")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orestis/Repos/test_megaparser/megaparser/lib/python3.12/site-packages/megaparse/core/megaparse.py", line 101, in load
    raise ValueError(f"Error while parsing {file_path}: {e}")
ValueError: Error while parsing monthly-budget-breakdown-revised.pdf: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.0.content.3.image.source.base64.data: The image specified was not valid'}}

Here is the code itself:

from langchain_anthropic import ChatAnthropic
from megaparse.core.parser.unstructured_parser import UnstructuredParser
from megaparse.core.parser.megaparse_vision import MegaParseVision
import os

# Initialize the language model
model = ChatAnthropic(model="claude-3-5-sonnet-20241022", api_key=os.getenv("ANTHROPIC_API_KEY"))

# Set up the parser
parser = MegaParseVision(model=model)
megaparse = MegaParse(parser)

# Load and process the document
response = megaparse.load("./monthly-budget-breakdown-revised.pdf")
print(response)

# Save the processed content to a markdown file
megaparse.save("./test.md")```


It worked with the UnstructuredParser so there is no issue with the API key as far as I can tell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant