Bug描述
我发现在使用GPT-4O导出JSON格式的输出文本时,与VectorIndexAutoRetriever的正常运行存在一些差异。
在查看VectorIndexAutoRetriever源代码时,我发现它使用llm来预测query_bundle,以便为VectorIndexAutoRetriever输出必要的JSON结构。
如果你使用另一个OpenAI模型或另一个LLM模型,输出可以解析为JSON格式。但是当使用GPT-4O时,输出将包含"```json",这使得它无法解析为JSON格式。
我认为,这不仅会导致VectorIndexAutoRetriever出现错误,还会导致任何可以使用llm生成JSON结构的llama_index模型出现错误。
版本
0.10.42
重现步骤
from llama_index.core.retrievers import VectorIndexAutoRetriever
from llama_index.core.vector_stores.types import MetadataInfo, VectorStoreInfo
vector_store_info = VectorStoreInfo(
content_info="brief biography of celebrities",
metadata_info=[
MetadataInfo(
name="category",
type="str",
description=(
"Category of the celebrity, one of [Sports, Entertainment,"
" Business, Music]"
),
),
MetadataInfo(
name="country",
type="str",
description=(
"Country of the celebrity, one of [United States, Barbados,"
" Portugal]"
),
),
],
)
retriever = VectorIndexAutoRetriever(
index, vector_store_info=vector_store_info
)
相关日志/回溯
validation errors for VectorStoreQuerySpec
query
field required (type=value_error.missing)
filters
field required (type=value_error.missing)
5条答案
按热度按时间72qzrwbm1#
你好!我在这里帮助你解决任何错误、问题或贡献。
为了解决由于输出中存在 "```json" 分隔符而导致
VectorIndexAutoRetriever
在使用gpt-4o
模型时失败的问题,你可以修改代码在解析 JSON 之前去除这些分隔符。以下是操作方法:generate_retrieval_spec
方法,在解析之前从输出字符串中去除 "json" and "
" 分隔符。llama_index.legacy.output_parsers.utils
中的parse_code_markdown
实用函数处理markdown代码块分隔符的去除。以下是如何实现这些更改的示例:
在这个示例中,
parse_code_markdown
函数用于从输出字符串中去除markdown代码块分隔符。这确保了 JSON 可以被正确解析,避免了你遇到的验证错误。这种方法应该解决了在使用
gpt-4o
模型时出现的VectorIndexAutoRetriever
问题。wvmv3b1j2#
@viethoang261 感谢您的投稿,以便改进输出解析。否则我可能会最终完成它。
at0kjp5o3#
抱歉,我之前提到的有误。
这不是关于“```json”分隔符的问题。
而是关于gpt-4o无法提取输出。
当我使用gpt3.5-turbo时,输出如下:
但是当使用gpt-4o时,输出与schema_str值相同:
brtdzjyr4#
啊,是的。我看到过很多关于gpt-4o的报道,说实话,它在结构化输出和函数调用方面真的很糟糕。
drkbr07n5#
我遇到了相同的错误。有什么解决方法可以绕过这个问题吗?