Compare commits

...

5 Commits

Author SHA1 Message Date
Sydney Runkle
8bd7ea5a5e linting 2025-05-14 08:16:07 -07:00
Sydney Runkle
b9c2031795 Merge branch 'sr/remove-unused-validators' of https://github.com/langchain-ai/langchain into sr/remove-unused-validators 2025-05-14 08:14:39 -07:00
Sydney Runkle
94a637f4a8 Merge branch 'master' into sr/remove-unused-validators 2025-05-14 08:14:35 -07:00
Sydney Runkle
d8bb6b24c4 remove another id -> str custom validator 2025-05-14 08:08:37 -07:00
Sydney Runkle
f1e9bf9d85 removing id -> str costly field validator 2025-05-14 07:55:43 -07:00
2 changed files with 4 additions and 22 deletions

View File

@@ -8,7 +8,7 @@ from io import BufferedReader, BytesIO
from pathlib import Path, PurePath
from typing import TYPE_CHECKING, Any, Literal, Optional, Union, cast
from pydantic import ConfigDict, Field, field_validator, model_validator
from pydantic import ConfigDict, Field, model_validator
from langchain_core.load.serializable import Serializable
@@ -33,7 +33,7 @@ class BaseMedia(Serializable):
# The ID field is optional at the moment.
# It will likely become required in a future major release after
# it has been adopted by enough vectorstore implementations.
id: Optional[str] = None
id: Optional[str] = Field(default=None, coerce_numbers_to_str=True)
"""An optional identifier for the document.
Ideally this should be unique across the document collection and formatted
@@ -45,17 +45,6 @@ class BaseMedia(Serializable):
metadata: dict = Field(default_factory=dict)
"""Arbitrary metadata associated with the content."""
@field_validator("id", mode="before")
def cast_id_to_str(cls, id_value: Any) -> Optional[str]:
"""Coerce the id field to a string.
Args:
id_value: The id value to coerce.
"""
if id_value is not None:
return str(id_value)
return id_value
class Blob(BaseMedia):
"""Blob represents raw data by either reference or value.

View File

@@ -4,7 +4,7 @@ from __future__ import annotations
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.utils import get_bolded_text
@@ -52,7 +52,7 @@ class BaseMessage(Serializable):
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
provided by the provider/model which created the message."""
@@ -60,13 +60,6 @@ class BaseMessage(Serializable):
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__(
self, content: Union[str, list[Union[str, dict]]], **kwargs: Any
) -> None: