core[patch]: Add an example to the Document schema doc-string (#23131)

Add an example to the document schema
This commit is contained in:
Eugene Yurtsev 2024-06-19 11:35:30 -04:00 committed by GitHub
parent 2b08e9e265
commit 883e90d06e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 12 deletions

View File

@ -7,7 +7,19 @@ from langchain_core.pydantic_v1 import Field
class Document(Serializable): class Document(Serializable):
"""Class for storing a piece of text and associated metadata.""" """Class for storing a piece of text and associated metadata.
Example:
.. code-block:: python
from langchain_core.documents import Document
document = Document(
page_content="Hello, world!",
metadata={"source": "https://example.com"}
)
"""
page_content: str page_content: str
"""String text.""" """String text."""

View File

@ -40,8 +40,9 @@ class AIMessage(BaseMessage):
"""Message from an AI.""" """Message from an AI."""
example: bool = False example: bool = False
"""Whether this Message is being passed in to the model as part of an example """Use to denote that a message is part of an example conversation.
conversation.
At the moment, this is ignored by most models. Usage is discouraged.
""" """
tool_calls: List[ToolCall] = [] tool_calls: List[ToolCall] = []

View File

@ -7,8 +7,9 @@ class HumanMessage(BaseMessage):
"""Message from a human.""" """Message from a human."""
example: bool = False example: bool = False
"""Whether this Message is being passed in to the model as part of an example """Use to denote that a message is part of an example conversation.
conversation.
At the moment, this is ignored by most models. Usage is discouraged.
""" """
type: Literal["human"] = "human" type: Literal["human"] = "human"

View File

@ -306,7 +306,7 @@ def test_schemas(snapshot: SnapshotAssertion) -> None:
"definitions": { "definitions": {
"Document": { "Document": {
"title": "Document", "title": "Document",
"description": "Class for storing a piece of text and associated metadata.", # noqa: E501 "description": AnyStr(),
"type": "object", "type": "object",
"properties": { "properties": {
"page_content": {"title": "Page Content", "type": "string"}, "page_content": {"title": "Page Content", "type": "string"},
@ -396,7 +396,7 @@ def test_schemas(snapshot: SnapshotAssertion) -> None:
}, },
"AIMessage": { "AIMessage": {
"title": "AIMessage", "title": "AIMessage",
"description": "Message from an AI.", "description": AnyStr(),
"type": "object", "type": "object",
"properties": { "properties": {
"content": { "content": {
@ -450,7 +450,7 @@ def test_schemas(snapshot: SnapshotAssertion) -> None:
}, },
"HumanMessage": { "HumanMessage": {
"title": "HumanMessage", "title": "HumanMessage",
"description": "Message from a human.", "description": AnyStr(),
"type": "object", "type": "object",
"properties": { "properties": {
"content": { "content": {
@ -491,7 +491,7 @@ def test_schemas(snapshot: SnapshotAssertion) -> None:
}, },
"ChatMessage": { "ChatMessage": {
"title": "ChatMessage", "title": "ChatMessage",
"description": "Message that can be assigned an arbitrary speaker (i.e. role).", # noqa: E501 "description": AnyStr(),
"type": "object", "type": "object",
"properties": { "properties": {
"content": { "content": {
@ -528,7 +528,7 @@ def test_schemas(snapshot: SnapshotAssertion) -> None:
}, },
"SystemMessage": { "SystemMessage": {
"title": "SystemMessage", "title": "SystemMessage",
"description": "Message for priming AI behavior, usually passed in as the first of a sequence\nof input messages.", # noqa: E501 "description": AnyStr(),
"type": "object", "type": "object",
"properties": { "properties": {
"content": { "content": {
@ -564,7 +564,7 @@ def test_schemas(snapshot: SnapshotAssertion) -> None:
}, },
"FunctionMessage": { "FunctionMessage": {
"title": "FunctionMessage", "title": "FunctionMessage",
"description": "Message for passing the result of executing a function back to a model.", # noqa: E501 "description": AnyStr(),
"type": "object", "type": "object",
"properties": { "properties": {
"content": { "content": {
@ -600,7 +600,7 @@ def test_schemas(snapshot: SnapshotAssertion) -> None:
}, },
"ToolMessage": { "ToolMessage": {
"title": "ToolMessage", "title": "ToolMessage",
"description": "Message for passing the result of executing a tool back to a model.", # noqa: E501 "description": AnyStr(),
"type": "object", "type": "object",
"properties": { "properties": {
"content": { "content": {