-
Hi, just wondering, types like However, even pre-defined values don't have default values there, which kind of defeats the purpose. I mean, it might be nice to say: messages_param = ChatCompletionSystemMessageParam(
content="You are a helpful assistant."
) But that does not work, because the role does not have a default value, even though it is defined as a literal: role: Required[Literal["system"]] Is this intentional, or perhaps an oversight wrt to how Pydantic 2 work? There that constant like field could be set to have a default value, or it could be a ClassVar, to have it there automatically. The default value would be like: role: Required[Literal["system"]] = "system" |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Ah I just learned the answer, when tried to subclass and fix this for myself: it's actually a TypedDict, not a Pydantic type, so it can't have default values like that. |
Beta Was this translation helpful? Give feedback.
-
Ok so TypedDict does not work like that, so am using this. I guess the reason for TypedDict vs. Pydantic there is that people are used to writing dict literals with strings. #class SystemMessage(ChatCompletionSystemMessageParam):
# role: Required[Literal["system"]] = "system"
def system_message(content: str):
return ChatCompletionSystemMessageParam(
content=content,
role="system"
)
def user_message(content: str):
return ChatCompletionUserMessageParam(
content=content,
role="user"
) |
Beta Was this translation helpful? Give feedback.
Ok so TypedDict does not work like that, so am using this. I guess the reason for TypedDict vs. Pydantic there is that people are used to writing dict literals with strings.