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

[Bug]: Marvin Metadata Extractor Demo code not working #13360

Open
sachinmandhotra1 opened this issue May 8, 2024 · 1 comment
Open

[Bug]: Marvin Metadata Extractor Demo code not working #13360

sachinmandhotra1 opened this issue May 8, 2024 · 1 comment
Labels
bug Something isn't working p2

Comments

@sachinmandhotra1
Copy link

Bug Description

While trying to run the code sample provided in the demo jupyter botebook for getting started with Metadata Extraction and Augmentation w/ Marvin, I'm facing the below error -
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Version

Name: llama-index Version: 0.10.35

Steps to Reproduce

Source code for reproducing the issue -

%pip install llama-index-llms-openai
%pip install llama-index-extractors-marvin

!pip install marvin

from llama_index.core import SimpleDirectoryReader
from llama_index.llms.openai import OpenAI
from llama_index.core.node_parser import TokenTextSplitter
from llama_index.extractors.marvin import MarvinMetadataExtractor

import os
import openai

os.environ["OPENAI_API_KEY"] = "sk-..."

documents = SimpleDirectoryReader("data").load_data()

documents[0].text = documents[0].text[:10000]

import marvin
from marvin import ai_model

from llama_index.core.bridge.pydantic import BaseModel, Field

marvin.settings.openai.api_key = os.environ["OPENAI_API_KEY"]

@ai_model
class SportsSupplement(BaseModel):
name: str = Field(..., description="The name of the sports supplement")
description: str = Field(
..., description="A description of the sports supplement"
)
pros_cons: str = Field(
..., description="The pros and cons of the sports supplement"
)

Source Link - https://docs.llamaindex.ai/en/stable/examples/metadata_extraction/MarvinMetadataExtractorDemo/

Relevant Logs/Tracbacks

TypeError                                 Traceback (most recent call last)
<ipython-input-23-a58fbcab93de> in <cell line: 5>()
      4 
      5 @ai_model
----> 6 class SportsSupplement(BaseModel):
      7     name: str = Field(..., description="The name of the sports supplement")
      8     description: str = Field(..., description="A description of the sports supplement")

1 frames
/usr/local/lib/python3.10/dist-packages/marvin/ai/text.py in decorator(cls)
    713 
    714     def decorator(cls: Type[M]) -> Type[M]:
--> 715         class WrappedModel(Model, cls):
    716             @wraps(cls.__init__)
    717             def __init__(self, *args, **kwargs):

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
@sachinmandhotra1 sachinmandhotra1 added bug Something isn't working triage Issue needs to be triaged/prioritized labels May 8, 2024
Copy link

dosubot bot commented May 8, 2024

The error you're encountering, TypeError: metaclass conflict, typically occurs when there's a clash between the metaclasses of the base classes in your class definition. This can happen when combining classes or decorators from different libraries that use incompatible metaclasses. Here's how you can address this issue:

  1. Identify Incompatible Metaclasses: Check the metaclasses for BaseModel, BaseExtractor, and any decorators like @ai_model used in your class. This involves inspecting the __class__ attribute or using type() on these classes to understand their metaclass dependencies.

  2. Unified Metaclass Solution: If incompatible metaclasses are identified, you might need to create a new metaclass that inherits from the conflicting metaclasses and use this as the metaclass for your class. This approach requires a solid understanding of Python's metaclass mechanisms.

  3. Avoid Multiple Inheritance: If feasible, redesign your class to avoid inheriting from multiple classes with different metaclasses. This might mean changing the class hierarchy or preferring composition over inheritance.

  4. Consult Documentation: Look into the documentation for marvin and other involved libraries for any guidance on integration and avoiding metaclass conflicts.

The issue arises from the attempt to mix classes or use decorators that introduce incompatible metaclasses. Ensuring compatibility between marvin_model and ai_model is crucial, as the error suggests a conflict when trying to subclass ai_model. Reviewing the implementation of @ai_model or consulting its documentation may provide further insights into resolving the conflict.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@logan-markewich logan-markewich added p2 and removed triage Issue needs to be triaged/prioritized labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2
Projects
None yet
Development

No branches or pull requests

2 participants