Skip to content

Commit 5ef7d42

Browse files
authored
refactor(core): remove example attribute from AIMessage and HumanMessage (#32565)
1 parent 750a3ff commit 5ef7d42

File tree

11 files changed

+293
-558
lines changed

11 files changed

+293
-558
lines changed

libs/core/langchain_core/messages/ai.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ class AIMessage(BaseMessage):
155155
(e.g., tool calls, usage metadata) added by the LangChain framework.
156156
"""
157157

158-
example: bool = False
159-
"""Use to denote that a message is part of an example conversation.
160-
161-
At the moment, this is ignored by most models. Usage is discouraged.
162-
"""
163-
164158
tool_calls: list[ToolCall] = []
165159
"""If provided, tool calls associated with the message."""
166160
invalid_tool_calls: list[InvalidToolCall] = []
@@ -543,17 +537,10 @@ def add_ai_message_chunks(
543537
left: The first ``AIMessageChunk``.
544538
*others: Other ``AIMessageChunk``s to add.
545539
546-
Raises:
547-
ValueError: If the example values of the chunks are not the same.
548-
549540
Returns:
550541
The resulting ``AIMessageChunk``.
551542
552543
"""
553-
if any(left.example != o.example for o in others):
554-
msg = "Cannot concatenate AIMessageChunks with different example values."
555-
raise ValueError(msg)
556-
557544
content = merge_content(left.content, *(o.content for o in others))
558545
additional_kwargs = merge_dicts(
559546
left.additional_kwargs, *(o.additional_kwargs for o in others)
@@ -615,7 +602,6 @@ def add_ai_message_chunks(
615602
)
616603

617604
return left.__class__(
618-
example=left.example,
619605
content=content,
620606
additional_kwargs=additional_kwargs,
621607
tool_call_chunks=tool_call_chunks,

libs/core/langchain_core/messages/human.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ class HumanMessage(BaseMessage):
2828
2929
"""
3030

31-
example: bool = False
32-
"""Use to denote that a message is part of an example conversation.
33-
34-
At the moment, this is ignored by most models. Usage is discouraged.
35-
Defaults to False.
36-
"""
37-
3831
type: Literal["human"] = "human"
3932
"""The type of the message (used for serialization). Defaults to "human"."""
4033

libs/core/tests/unit_tests/prompts/__snapshots__/test_chat.ambr

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
]),
4040
'title': 'Content',
4141
}),
42-
'example': dict({
43-
'default': False,
44-
'title': 'Example',
45-
'type': 'boolean',
46-
}),
4742
'id': dict({
4843
'anyOf': list([
4944
dict({
@@ -156,11 +151,6 @@
156151
]),
157152
'title': 'Content',
158153
}),
159-
'example': dict({
160-
'default': False,
161-
'title': 'Example',
162-
'type': 'boolean',
163-
}),
164154
'id': dict({
165155
'anyOf': list([
166156
dict({
@@ -573,11 +563,6 @@
573563
]),
574564
'title': 'Content',
575565
}),
576-
'example': dict({
577-
'default': False,
578-
'title': 'Example',
579-
'type': 'boolean',
580-
}),
581566
'id': dict({
582567
'anyOf': list([
583568
dict({
@@ -648,11 +633,6 @@
648633
]),
649634
'title': 'Content',
650635
}),
651-
'example': dict({
652-
'default': False,
653-
'title': 'Example',
654-
'type': 'boolean',
655-
}),
656636
'id': dict({
657637
'anyOf': list([
658638
dict({
@@ -1489,11 +1469,6 @@
14891469
]),
14901470
'title': 'Content',
14911471
}),
1492-
'example': dict({
1493-
'default': False,
1494-
'title': 'Example',
1495-
'type': 'boolean',
1496-
}),
14971472
'id': dict({
14981473
'anyOf': list([
14991474
dict({
@@ -1606,11 +1581,6 @@
16061581
]),
16071582
'title': 'Content',
16081583
}),
1609-
'example': dict({
1610-
'default': False,
1611-
'title': 'Example',
1612-
'type': 'boolean',
1613-
}),
16141584
'id': dict({
16151585
'anyOf': list([
16161586
dict({
@@ -2023,11 +1993,6 @@
20231993
]),
20241994
'title': 'Content',
20251995
}),
2026-
'example': dict({
2027-
'default': False,
2028-
'title': 'Example',
2029-
'type': 'boolean',
2030-
}),
20311996
'id': dict({
20321997
'anyOf': list([
20331998
dict({
@@ -2098,11 +2063,6 @@
20982063
]),
20992064
'title': 'Content',
21002065
}),
2101-
'example': dict({
2102-
'default': False,
2103-
'title': 'Example',
2104-
'type': 'boolean',
2105-
}),
21062066
'id': dict({
21072067
'anyOf': list([
21082068
dict({

libs/core/tests/unit_tests/prompts/test_chat.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,9 @@ async def test_chat_prompt_template_from_messages_using_role_strings() -> None:
260260
SystemMessage(
261261
content="You are a helpful AI bot. Your name is Bob.", additional_kwargs={}
262262
),
263-
HumanMessage(
264-
content="Hello, how are you doing?", additional_kwargs={}, example=False
265-
),
266-
AIMessage(
267-
content="I'm doing well, thanks!", additional_kwargs={}, example=False
268-
),
269-
HumanMessage(content="What is your name?", additional_kwargs={}, example=False),
263+
HumanMessage(content="Hello, how are you doing?", additional_kwargs={}),
264+
AIMessage(content="I'm doing well, thanks!", additional_kwargs={}),
265+
HumanMessage(content="What is your name?", additional_kwargs={}),
270266
]
271267

272268
messages = template.format_messages(name="Bob", user_input="What is your name?")
@@ -296,13 +292,9 @@ def test_chat_prompt_template_from_messages_mustache() -> None:
296292
SystemMessage(
297293
content="You are a helpful AI bot. Your name is Bob.", additional_kwargs={}
298294
),
299-
HumanMessage(
300-
content="Hello, how are you doing?", additional_kwargs={}, example=False
301-
),
302-
AIMessage(
303-
content="I'm doing well, thanks!", additional_kwargs={}, example=False
304-
),
305-
HumanMessage(content="What is your name?", additional_kwargs={}, example=False),
295+
HumanMessage(content="Hello, how are you doing?", additional_kwargs={}),
296+
AIMessage(content="I'm doing well, thanks!", additional_kwargs={}),
297+
HumanMessage(content="What is your name?", additional_kwargs={}),
306298
]
307299

308300

@@ -324,13 +316,9 @@ def test_chat_prompt_template_from_messages_jinja2() -> None:
324316
SystemMessage(
325317
content="You are a helpful AI bot. Your name is Bob.", additional_kwargs={}
326318
),
327-
HumanMessage(
328-
content="Hello, how are you doing?", additional_kwargs={}, example=False
329-
),
330-
AIMessage(
331-
content="I'm doing well, thanks!", additional_kwargs={}, example=False
332-
),
333-
HumanMessage(content="What is your name?", additional_kwargs={}, example=False),
319+
HumanMessage(content="Hello, how are you doing?", additional_kwargs={}),
320+
AIMessage(content="I'm doing well, thanks!", additional_kwargs={}),
321+
HumanMessage(content="What is your name?", additional_kwargs={}),
334322
]
335323

336324

libs/core/tests/unit_tests/prompts/test_few_shot.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ async def test_few_shot_chat_message_prompt_template() -> None:
358358

359359
expected = [
360360
SystemMessage(content="You are a helpful AI Assistant", additional_kwargs={}),
361-
HumanMessage(content="2+2", additional_kwargs={}, example=False),
362-
AIMessage(content="4", additional_kwargs={}, example=False),
363-
HumanMessage(content="2+3", additional_kwargs={}, example=False),
364-
AIMessage(content="5", additional_kwargs={}, example=False),
365-
HumanMessage(content="100 + 1", additional_kwargs={}, example=False),
361+
HumanMessage(content="2+2", additional_kwargs={}),
362+
AIMessage(content="4", additional_kwargs={}),
363+
HumanMessage(content="2+3", additional_kwargs={}),
364+
AIMessage(content="5", additional_kwargs={}),
365+
HumanMessage(content="100 + 1", additional_kwargs={}),
366366
]
367367

368368
messages = final_prompt.format_messages(input="100 + 1")
@@ -433,11 +433,11 @@ def test_few_shot_chat_message_prompt_template_with_selector() -> None:
433433
)
434434
expected = [
435435
SystemMessage(content="You are a helpful AI Assistant", additional_kwargs={}),
436-
HumanMessage(content="2+2", additional_kwargs={}, example=False),
437-
AIMessage(content="4", additional_kwargs={}, example=False),
438-
HumanMessage(content="2+3", additional_kwargs={}, example=False),
439-
AIMessage(content="5", additional_kwargs={}, example=False),
440-
HumanMessage(content="100 + 1", additional_kwargs={}, example=False),
436+
HumanMessage(content="2+2", additional_kwargs={}),
437+
AIMessage(content="4", additional_kwargs={}),
438+
HumanMessage(content="2+3", additional_kwargs={}),
439+
AIMessage(content="5", additional_kwargs={}),
440+
HumanMessage(content="100 + 1", additional_kwargs={}),
441441
]
442442
messages = final_prompt.format_messages(input="100 + 1")
443443
assert messages == expected
@@ -532,11 +532,11 @@ async def test_few_shot_chat_message_prompt_template_with_selector_async() -> No
532532
)
533533
expected = [
534534
SystemMessage(content="You are a helpful AI Assistant", additional_kwargs={}),
535-
HumanMessage(content="2+2", additional_kwargs={}, example=False),
536-
AIMessage(content="4", additional_kwargs={}, example=False),
537-
HumanMessage(content="2+3", additional_kwargs={}, example=False),
538-
AIMessage(content="5", additional_kwargs={}, example=False),
539-
HumanMessage(content="100 + 1", additional_kwargs={}, example=False),
535+
HumanMessage(content="2+2", additional_kwargs={}),
536+
AIMessage(content="4", additional_kwargs={}),
537+
HumanMessage(content="2+3", additional_kwargs={}),
538+
AIMessage(content="5", additional_kwargs={}),
539+
HumanMessage(content="100 + 1", additional_kwargs={}),
540540
]
541541
messages = await final_prompt.aformat_messages(input="100 + 1")
542542
assert messages == expected

libs/core/tests/unit_tests/runnables/__snapshots__/test_graph.ambr

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,6 @@
442442
]),
443443
'title': 'Content',
444444
}),
445-
'example': dict({
446-
'default': False,
447-
'title': 'Example',
448-
'type': 'boolean',
449-
}),
450445
'id': dict({
451446
'anyOf': list([
452447
dict({
@@ -559,11 +554,6 @@
559554
]),
560555
'title': 'Content',
561556
}),
562-
'example': dict({
563-
'default': False,
564-
'title': 'Example',
565-
'type': 'boolean',
566-
}),
567557
'id': dict({
568558
'anyOf': list([
569559
dict({
@@ -976,11 +966,6 @@
976966
]),
977967
'title': 'Content',
978968
}),
979-
'example': dict({
980-
'default': False,
981-
'title': 'Example',
982-
'type': 'boolean',
983-
}),
984969
'id': dict({
985970
'anyOf': list([
986971
dict({
@@ -1051,11 +1036,6 @@
10511036
]),
10521037
'title': 'Content',
10531038
}),
1054-
'example': dict({
1055-
'default': False,
1056-
'title': 'Example',
1057-
'type': 'boolean',
1058-
}),
10591039
'id': dict({
10601040
'anyOf': list([
10611041
dict({

0 commit comments

Comments
 (0)