mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-12 06:13:36 +00:00
This PR adds scaffolding for langchain 1.0 entry package. Most contents have been removed. Currently remaining entrypoints for: * chat models * embedding models * memory -> trimming messages, filtering messages and counting tokens [we may remove this] * prompts -> we may remove some prompts * storage: primarily to support cache backed embeddings, may remove the kv store * tools -> report tool primitives Things to be added: * Selected agent implementations * Selected workflows * Common primitives: messages, Document * Primitives for type hinting: BaseChatModel, BaseEmbeddings * Selected retrievers * Selected text splitters Things to be removed: * Globals needs to be removed (needs an update in langchain core) Todos: * TBD indexing api (requires sqlalchemy which we don't want as a dependency) * Be explicit about public/private interfaces (e.g., likely rename chat_models.base.py to something more internal) * Remove dockerfiles * Update module doc-strings and README.md
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from typing import Any
|
|
|
|
from langchain_core.documents import Document
|
|
from langchain_core.messages import AIMessage, AIMessageChunk, HumanMessage
|
|
|
|
|
|
class AnyStr(str):
|
|
__slots__ = ()
|
|
|
|
def __eq__(self, other: object) -> bool:
|
|
return isinstance(other, str)
|
|
|
|
|
|
# The code below creates version of pydantic models
|
|
# that will work in unit tests with AnyStr as id field
|
|
# Please note that the `id` field is assigned AFTER the model is created
|
|
# to workaround an issue with pydantic ignoring the __eq__ method on
|
|
# subclassed strings.
|
|
|
|
|
|
def _AnyIdDocument(**kwargs: Any) -> Document:
|
|
"""Create a document with an id field."""
|
|
message = Document(**kwargs)
|
|
message.id = AnyStr()
|
|
return message
|
|
|
|
|
|
def _AnyIdAIMessage(**kwargs: Any) -> AIMessage:
|
|
"""Create ai message with an any id field."""
|
|
message = AIMessage(**kwargs)
|
|
message.id = AnyStr()
|
|
return message
|
|
|
|
|
|
def _AnyIdAIMessageChunk(**kwargs: Any) -> AIMessageChunk:
|
|
"""Create ai message with an any id field."""
|
|
message = AIMessageChunk(**kwargs)
|
|
message.id = AnyStr()
|
|
return message
|
|
|
|
|
|
def _AnyIdHumanMessage(**kwargs: Any) -> HumanMessage:
|
|
"""Create a human with an any id field."""
|
|
message = HumanMessage(**kwargs)
|
|
message.id = AnyStr()
|
|
return message
|