问题描述:在使用marvin(通过llama-index)从文本块中提取相关元数据时,遇到了一个问题。首先,这个问题与ai_model装饰器有关:按照notebook中的说明,似乎无法对继承自"llama_index.core.bridge.pydantic"中BaseModel实现的类进行装饰。尝试使用pydantic中的BaseModel直接解决这个问题,但这又产生了一个新的问题:在MarvinMetadataExtractor类中,以下代码似乎有问题:
from marvin import ai_model
if not issubclass(marvin_model, ai_model):
raise ValueError("marvin_model must be a subclass of ai_model")
从第63行开始,由于ai_model不是一个类,而是一个函数,所以这个定义似乎有问题。
版本:llama-index-extractors-marvin="0.1.3"
重现步骤:
- 导入所需的库和模块;
- 设置环境变量;
- 定义LLM模型字符串;
- 使用ai_model装饰器定义RiskExtractor类;
- 创建MarvinMetadataExtractor示例。
相关日志/回溯:
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
TypeError: issubclass() arg 2 must be a class, a tuple of classes, or a union
1条答案
按热度按时间lvjbypge1#
嘿 @DioTeamGit! 我来帮助你解决遇到的问题。我是一个可以协助你解决bug、回答问题并成为贡献者的机器人。告诉我如何帮助你!
要解决你在使用
MarvinMetadataExtractor
和ai_model
装饰器时遇到的问题的步骤如下:ai_model
被正确应用:ai_model
装饰器应该应用于继承自 Pydantic 的BaseModel
的类。确保ai_model
装饰器被正确导入和应用。ai_model
装饰器:ai_model
装饰器应该是一个修改其修饰类的函数。如果ai_model
不是一个类而是一个函数,那么检查issubclass(marvin_model, ai_model)
将失败。你需要确保ai_model
被正确使用。MarvinMetadataExtractor
类: 更新MarvinMetadataExtractor
类以正确处理ai_model
装饰器。以下是如何修改类的示例:MarvinMetadataExtractor
和ai_model
装饰器的使用是正确的:通过确保
ai_model
装饰器被正确应用并修改MarvinMetadataExtractor
类以检查装饰器,你应该能够解决你正在面临的问题 1(https://github.com/run-llama/llama_index/blob/main/llama-index-legacy/llama_index/legacy/extractors/marvin_metadata_extractor.py)2(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/extractors/llama-index-extractors-marvin/llama_index/extractors/marvin/base.py)。