`langchain_core.utils.pydantic._create_subset_model_v1` 对于使用 `Annotated with Field` 的 Pydantic v1 模型失败,例如:

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

遗憾的是,这个功能对于使用AnnotatedField的pydantic v1模型失败,例如:

class InputModel(BaseModel):
    query: Annotated[str, pydantic_v1.Field(description="Hello World")]

_create_subset_model_v1("test", InputModel, InputModel.__annotations__.keys())

这会产生以下错误:

ValueError: cannot specify `Annotated` and value `Field`s together for 'query'
  • 原帖由@tdiggelm在#24418(评论)中发布*
a9wyjsp7

a9wyjsp71#

出于好奇,你没有像这样定义InputModel的原因是什么?

$x_1^a_0 b_1^x$

vof42yt1

vof42yt12#

没有特定的原因,只是使用了一个有效的定义字段的变体:https://docs.pydantic.dev/1.10/usage/schema/#typingannotated-fields

相关问题