Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions libs/core/langchain_core/messages/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ class AIMessage(BaseMessage):
(e.g., tool calls, usage metadata) added by the LangChain framework.
"""

example: bool = False
"""Use to denote that a message is part of an example conversation.

At the moment, this is ignored by most models. Usage is discouraged.
"""

tool_calls: list[ToolCall] = []
"""If provided, tool calls associated with the message."""
invalid_tool_calls: list[InvalidToolCall] = []
Expand Down Expand Up @@ -543,17 +537,10 @@ def add_ai_message_chunks(
left: The first ``AIMessageChunk``.
*others: Other ``AIMessageChunk``s to add.

Raises:
ValueError: If the example values of the chunks are not the same.

Returns:
The resulting ``AIMessageChunk``.

"""
if any(left.example != o.example for o in others):
msg = "Cannot concatenate AIMessageChunks with different example values."
raise ValueError(msg)

content = merge_content(left.content, *(o.content for o in others))
additional_kwargs = merge_dicts(
left.additional_kwargs, *(o.additional_kwargs for o in others)
Expand Down Expand Up @@ -615,7 +602,6 @@ def add_ai_message_chunks(
)

return left.__class__(
example=left.example,
content=content,
additional_kwargs=additional_kwargs,
tool_call_chunks=tool_call_chunks,
Expand Down
7 changes: 0 additions & 7 deletions libs/core/langchain_core/messages/human.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ class HumanMessage(BaseMessage):

"""

example: bool = False
"""Use to denote that a message is part of an example conversation.

At the moment, this is ignored by most models. Usage is discouraged.
Defaults to False.
"""

type: Literal["human"] = "human"
"""The type of the message (used for serialization). Defaults to "human"."""

Expand Down
40 changes: 0 additions & 40 deletions libs/core/tests/unit_tests/prompts/__snapshots__/test_chat.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -156,11 +151,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -573,11 +563,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -648,11 +633,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -1489,11 +1469,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -1606,11 +1581,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -2023,11 +1993,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -2098,11 +2063,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down
30 changes: 9 additions & 21 deletions libs/core/tests/unit_tests/prompts/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,9 @@ async def test_chat_prompt_template_from_messages_using_role_strings() -> None:
SystemMessage(
content="You are a helpful AI bot. Your name is Bob.", additional_kwargs={}
),
HumanMessage(
content="Hello, how are you doing?", additional_kwargs={}, example=False
),
AIMessage(
content="I'm doing well, thanks!", additional_kwargs={}, example=False
),
HumanMessage(content="What is your name?", additional_kwargs={}, example=False),
HumanMessage(content="Hello, how are you doing?", additional_kwargs={}),
AIMessage(content="I'm doing well, thanks!", additional_kwargs={}),
HumanMessage(content="What is your name?", additional_kwargs={}),
]

messages = template.format_messages(name="Bob", user_input="What is your name?")
Expand Down Expand Up @@ -296,13 +292,9 @@ def test_chat_prompt_template_from_messages_mustache() -> None:
SystemMessage(
content="You are a helpful AI bot. Your name is Bob.", additional_kwargs={}
),
HumanMessage(
content="Hello, how are you doing?", additional_kwargs={}, example=False
),
AIMessage(
content="I'm doing well, thanks!", additional_kwargs={}, example=False
),
HumanMessage(content="What is your name?", additional_kwargs={}, example=False),
HumanMessage(content="Hello, how are you doing?", additional_kwargs={}),
AIMessage(content="I'm doing well, thanks!", additional_kwargs={}),
HumanMessage(content="What is your name?", additional_kwargs={}),
]


Expand All @@ -324,13 +316,9 @@ def test_chat_prompt_template_from_messages_jinja2() -> None:
SystemMessage(
content="You are a helpful AI bot. Your name is Bob.", additional_kwargs={}
),
HumanMessage(
content="Hello, how are you doing?", additional_kwargs={}, example=False
),
AIMessage(
content="I'm doing well, thanks!", additional_kwargs={}, example=False
),
HumanMessage(content="What is your name?", additional_kwargs={}, example=False),
HumanMessage(content="Hello, how are you doing?", additional_kwargs={}),
AIMessage(content="I'm doing well, thanks!", additional_kwargs={}),
HumanMessage(content="What is your name?", additional_kwargs={}),
]


Expand Down
30 changes: 15 additions & 15 deletions libs/core/tests/unit_tests/prompts/test_few_shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ async def test_few_shot_chat_message_prompt_template() -> None:

expected = [
SystemMessage(content="You are a helpful AI Assistant", additional_kwargs={}),
HumanMessage(content="2+2", additional_kwargs={}, example=False),
AIMessage(content="4", additional_kwargs={}, example=False),
HumanMessage(content="2+3", additional_kwargs={}, example=False),
AIMessage(content="5", additional_kwargs={}, example=False),
HumanMessage(content="100 + 1", additional_kwargs={}, example=False),
HumanMessage(content="2+2", additional_kwargs={}),
AIMessage(content="4", additional_kwargs={}),
HumanMessage(content="2+3", additional_kwargs={}),
AIMessage(content="5", additional_kwargs={}),
HumanMessage(content="100 + 1", additional_kwargs={}),
]

messages = final_prompt.format_messages(input="100 + 1")
Expand Down Expand Up @@ -433,11 +433,11 @@ def test_few_shot_chat_message_prompt_template_with_selector() -> None:
)
expected = [
SystemMessage(content="You are a helpful AI Assistant", additional_kwargs={}),
HumanMessage(content="2+2", additional_kwargs={}, example=False),
AIMessage(content="4", additional_kwargs={}, example=False),
HumanMessage(content="2+3", additional_kwargs={}, example=False),
AIMessage(content="5", additional_kwargs={}, example=False),
HumanMessage(content="100 + 1", additional_kwargs={}, example=False),
HumanMessage(content="2+2", additional_kwargs={}),
AIMessage(content="4", additional_kwargs={}),
HumanMessage(content="2+3", additional_kwargs={}),
AIMessage(content="5", additional_kwargs={}),
HumanMessage(content="100 + 1", additional_kwargs={}),
]
messages = final_prompt.format_messages(input="100 + 1")
assert messages == expected
Expand Down Expand Up @@ -532,11 +532,11 @@ async def test_few_shot_chat_message_prompt_template_with_selector_async() -> No
)
expected = [
SystemMessage(content="You are a helpful AI Assistant", additional_kwargs={}),
HumanMessage(content="2+2", additional_kwargs={}, example=False),
AIMessage(content="4", additional_kwargs={}, example=False),
HumanMessage(content="2+3", additional_kwargs={}, example=False),
AIMessage(content="5", additional_kwargs={}, example=False),
HumanMessage(content="100 + 1", additional_kwargs={}, example=False),
HumanMessage(content="2+2", additional_kwargs={}),
AIMessage(content="4", additional_kwargs={}),
HumanMessage(content="2+3", additional_kwargs={}),
AIMessage(content="5", additional_kwargs={}),
HumanMessage(content="100 + 1", additional_kwargs={}),
]
messages = await final_prompt.aformat_messages(input="100 + 1")
assert messages == expected
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -559,11 +554,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -976,11 +966,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down Expand Up @@ -1051,11 +1036,6 @@
]),
'title': 'Content',
}),
'example': dict({
'default': False,
'title': 'Example',
'type': 'boolean',
}),
'id': dict({
'anyOf': list([
dict({
Expand Down
Loading