llama_index [Bug]: 指导文档中的 guidance_pydantic 已过时

dw1jzc5e  于 6个月前  发布在  其他
关注(0)|答案(2)|浏览(51)

你好!
晚上好!
似乎https://docs.llamaindex.ai/en/stable/examples/output_parsing/guidance_pydantic_program/文档已经过时了,你能看一下吗?这些示例会抛出异常。
llama-index==0.10.43
llama-index-program-guidance==0.1.2

版本

0.10.43

重现步骤

请检查第3步(导入)的colab。
https://docs.llamaindex.ai/en/stable/examples/output_parsing/guidance_pydantic_program/

相关日志/回溯

ImportError                               Traceback (most recent call last)

<ipython-input-3-fc0a30d8938f> in <cell line: 1>()
----> 1 from llama_index.question_gen.guidance import GuidanceQuestionGenerator
      2 from guidance.llms import OpenAI as GuidanceOpenAI

3 frames

/usr/local/lib/python3.10/dist-packages/llama_index/program/guidance/base.py in <module>
     11 from guidance import assistant, gen, user
     12 from guidance.models import Model as GuidanceLLM
---> 13 from guidance.models import OpenAIChat
     14 
     15 

ImportError: cannot import name 'OpenAIChat' from 'guidance.models' (/usr/local/lib/python3.10/dist-packages/guidance/models/__init__.py)
k4aesqcs

k4aesqcs1#

晚上好,@zeloras!我在这里为您提供任何错误、问题或贡献的帮助。让我们一起解决这个问题!
要解决LlamaIndex包中"Guidance Pydantic Program"文档中的导入错误,请确保在脚本开头正确包含以下导入:

from functools import partial
from typing import Any, Optional, Type, cast

from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.program.llm_prompt_program import BaseLLMFunctionProgram
from llama_index.core.prompts.base import PromptTemplate
from llama_index.program.guidance.utils import (
    parse_pydantic_from_guidance_program,
)

from guidance import assistant, gen, user
from guidance.models import Model as GuidanceLLM
from guidance.models import OpenAI

此外,确保您已从llama_index.program.guidance.base模块正确导入了GuidancePydanticProgram类:

from llama_index.program.guidance.base import GuidancePydanticProgram

这些导入对于GuidancePydanticProgram类的正常运行是必要的。请确保您的环境中所有导入的模块和类都是可用的。如果缺少这些模块中的任何一个,您可能需要安装它们或检查它们的路径。
此外,请确保您正在使用Pydantic的正确版本。llama_index.core.bridge.pydantic模块尝试首先导入pydantic.v1,如果前者不可用,则回退到pydantic。请确保已安装pydantic.v1或相应地调整导入:

try:
    import pydantic.v1 as pydantic
    from pydantic.v1 import (
        BaseConfig,
        BaseModel,
        Field,
        PrivateAttr,
        StrictFloat,
        StrictInt,
        StrictStr,
        create_model,
        root_validator,
        validator,
    )
    from pydantic.v1.error_wrappers import ValidationError
    from pydantic.v1.fields import FieldInfo
    from pydantic.v1.generics import GenericModel
except ImportError:
    import pydantic  # type: ignore
    from pydantic import (
        BaseConfig,
        BaseModel,
        Field,
        PrivateAttr,
        StrictFloat,
        StrictInt,
        StrictStr,
        create_model,
        root_validator,
        validator,
    )
    from pydantic.error_wrappers import ValidationError
    from pydantic.fields import FieldInfo
    from pydantic.generics import GenericModel

这确保了与Guidance Pydantic Program的兼容性并解决了潜在的导入错误1(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/program/llama-index-program-guidance/llama_index/program/guidance/base.py)2(https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/program/llama-index-program-guidance/llama_index/program/guidance/init.py)3(https://github.com/run-llama/llama_index/blob/main/llama-index-core/llama_index/core/bridge/pydantic.py)4(https://github.com/run-llama/llama_index/blob/main/llama-index-legacy/llama_index/legacy/bridge/pydantic.py)。

  • 要继续与@dosu交谈,请提及@dosu。*

相关问题