mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 13:00:34 +00:00
removing id -> str costly field validator
This commit is contained in:
parent
0da364fbc8
commit
48284ccbb4
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
||||||
|
|
||||||
from pydantic import ConfigDict, Field, field_validator
|
from pydantic import ConfigDict, Field
|
||||||
|
|
||||||
from langchain_core.load.serializable import Serializable
|
from langchain_core.load.serializable import Serializable
|
||||||
from langchain_core.utils import get_bolded_text
|
from langchain_core.utils import get_bolded_text
|
||||||
@ -52,7 +52,7 @@ class BaseMessage(Serializable):
|
|||||||
model implementation.
|
model implementation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id: Optional[str] = None
|
id: Optional[str] = Field(default=None, coerce_numbers_to_str=True)
|
||||||
"""An optional unique identifier for the message. This should ideally be
|
"""An optional unique identifier for the message. This should ideally be
|
||||||
provided by the provider/model which created the message."""
|
provided by the provider/model which created the message."""
|
||||||
|
|
||||||
@ -60,13 +60,6 @@ class BaseMessage(Serializable):
|
|||||||
extra="allow",
|
extra="allow",
|
||||||
)
|
)
|
||||||
|
|
||||||
@field_validator("id", mode="before")
|
|
||||||
def cast_id_to_str(cls, id_value: Any) -> Optional[str]:
|
|
||||||
"""Coerce the id field to a string."""
|
|
||||||
if id_value is not None:
|
|
||||||
return str(id_value)
|
|
||||||
return id_value
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, content: Union[str, list[Union[str, dict]]], **kwargs: Any
|
self, content: Union[str, list[Union[str, dict]]], **kwargs: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user