You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
@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"
)
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
The text was updated successfully, but these errors were encountered:
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:
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.
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.
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.
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.
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.
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
The text was updated successfully, but these errors were encountered: