Open zeloras opened 3 weeks ago
Good evening, @zeloras! I'm here to assist you with any bugs, questions, or contributions you have. Let's tackle this issue together!
To resolve the import errors in the "Guidance Pydantic Program" documentation for the LlamaIndex package, ensure that the following imports are correctly included at the beginning of your script:
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
Additionally, make sure that you have the GuidancePydanticProgram
class correctly imported from the llama_index.program.guidance.base
module:
from llama_index.program.guidance.base import GuidancePydanticProgram
These imports are necessary for the GuidancePydanticProgram
class to function correctly. Make sure that all the modules and classes being imported are available in your environment. If any of these modules are missing, you may need to install them or check their paths.
Also, ensure that you are using the correct version of Pydantic. The llama_index.core.bridge.pydantic
module attempts to import pydantic.v1
first, and falls back to pydantic
if the former is not available. Make sure you have pydantic.v1
installed or adjust the imports accordingly:
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
This ensures compatibility with the Guidance Pydantic Program
and resolves potential import errors [1][2][3][4].
To continue talking to Dosu, mention @dosu.
Bug Description
Good evening! it seems that the https://docs.llamaindex.ai/en/stable/examples/output_parsing/guidance_pydantic_program/ documentation is out of time, could you take a look? those example's giving exceptions
llama-index==0.10.43 llama-index-program-guidance==0.1.2
Version
0.10.43
Steps to Reproduce
Please check the colab on the 3rd step(imports) https://docs.llamaindex.ai/en/stable/examples/output_parsing/guidance_pydantic_program/
Relevant Logs/Tracbacks