Skip to content

Commit 1a52b54

Browse files
authored
Merge branch 'master' into docs/qwen3-think-mode
2 parents 2d5ca6c + 8868701 commit 1a52b54

File tree

8 files changed

+105
-25
lines changed

8 files changed

+105
-25
lines changed

docs/docs/integrations/chat/anthropic.ipynb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,26 @@
568568
" ```\n",
569569
" and specifying `\"cache_control\": {\"type\": \"ephemeral\", \"ttl\": \"1h\"}`.\n",
570570
"\n",
571+
" Details of cached token counts will be included on the `InputTokenDetails` of response's `usage_metadata`:\n",
572+
"\n",
573+
" ```python\n",
574+
" response = llm.invoke(messages)\n",
575+
" response.usage_metadata\n",
576+
" ```\n",
577+
" ```\n",
578+
" {\n",
579+
" \"input_tokens\": 1500,\n",
580+
" \"output_tokens\": 200,\n",
581+
" \"total_tokens\": 1700,\n",
582+
" \"input_token_details\": {\n",
583+
" \"cache_read\": 0,\n",
584+
" \"cache_creation\": 1000,\n",
585+
" \"ephemeral_1h_input_tokens\": 750,\n",
586+
" \"ephemeral_5m_input_tokens\": 250,\n",
587+
" }\n",
588+
" }\n",
589+
" ```\n",
590+
"\n",
571591
":::"
572592
]
573593
},

docs/docs/integrations/chat/groq.ipynb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
"cell_type": "markdown",
5959
"id": "72ee0c4b-9764-423a-9dbf-95129e185210",
6060
"metadata": {},
61-
"source": "To enable automated tracing of your model calls, set your [LangSmith](https://docs.smith.langchain.com/) API key:"
61+
"source": [
62+
"To enable automated tracing of your model calls, set your [LangSmith](https://docs.smith.langchain.com/) API key:"
63+
]
6264
},
6365
{
6466
"cell_type": "code",
@@ -98,22 +100,30 @@
98100
"source": [
99101
"## Instantiation\n",
100102
"\n",
101-
"Now we can instantiate our model object and generate chat completions:"
103+
"Now we can instantiate our model object and generate chat completions. \n",
104+
"\n",
105+
"\n",
106+
":::note Reasoning Format\n",
107+
"\n",
108+
"If you choose to set a `reasoning_format`, you must ensure that the model you are using supports it. You can find a list of supported models in the [Groq documentation](https://console.groq.com/docs/reasoning).\n",
109+
"\n",
110+
":::"
102111
]
103112
},
104113
{
105114
"cell_type": "code",
106-
"execution_count": 1,
115+
"execution_count": 6,
107116
"id": "cb09c344-1836-4e0c-acf8-11d13ac1dbae",
108117
"metadata": {},
109118
"outputs": [],
110119
"source": [
111120
"from langchain_groq import ChatGroq\n",
112121
"\n",
113122
"llm = ChatGroq(\n",
114-
" model=\"llama-3.1-8b-instant\",\n",
123+
" model=\"deepseek-r1-distill-llama-70b\",\n",
115124
" temperature=0,\n",
116125
" max_tokens=None,\n",
126+
" reasoning_format=\"parsed\",\n",
117127
" timeout=None,\n",
118128
" max_retries=2,\n",
119129
" # other params...\n",
@@ -130,7 +140,7 @@
130140
},
131141
{
132142
"cell_type": "code",
133-
"execution_count": 2,
143+
"execution_count": 7,
134144
"id": "62e0dbc3",
135145
"metadata": {
136146
"tags": []
@@ -139,10 +149,10 @@
139149
{
140150
"data": {
141151
"text/plain": [
142-
"AIMessage(content='The translation of \"I love programming\" to French is:\\n\\n\"J\\'adore le programmation.\"', additional_kwargs={}, response_metadata={'token_usage': {'completion_tokens': 22, 'prompt_tokens': 55, 'total_tokens': 77, 'completion_time': 0.029333333, 'prompt_time': 0.003502892, 'queue_time': 0.553054073, 'total_time': 0.032836225}, 'model_name': 'llama-3.1-8b-instant', 'system_fingerprint': 'fp_a491995411', 'finish_reason': 'stop', 'logprobs': None}, id='run-2b2da04a-993c-40ab-becc-201eab8b1a1b-0', usage_metadata={'input_tokens': 55, 'output_tokens': 22, 'total_tokens': 77})"
152+
"AIMessage(content=\"J'aime la programmation.\", additional_kwargs={'reasoning_content': 'Okay, so I need to translate the sentence \"I love programming.\" into French. Let me think about how to approach this. \\n\\nFirst, I know that \"I\" in French is \"Je.\" That\\'s straightforward. Now, the verb \"love\" in French is \"aime\" when referring to oneself. So, \"I love\" would be \"J\\'aime.\" \\n\\nNext, the word \"programming.\" In French, programming is \"la programmation.\" But wait, in French, when you talk about loving an activity, you often use the definite article. So, it would be \"la programmation.\" \\n\\nPutting it all together, \"I love programming\" becomes \"J\\'aime la programmation.\" That sounds right. I think that\\'s the correct translation. \\n\\nI should double-check to make sure I\\'m not missing anything. Maybe I can think of similar phrases. For example, \"I love reading\" is \"J\\'aime lire,\" but when it\\'s a noun, like \"I love music,\" it\\'s \"J\\'aime la musique.\" So, yes, using \"la programmation\" makes sense here. \\n\\nI don\\'t think I need to change anything else. The sentence structure in French is Subject-Verb-Object, just like in English, so \"J\\'aime la programmation\" should be correct. \\n\\nI guess another way to say it could be \"J\\'adore la programmation,\" using \"adore\" instead of \"aime,\" but \"aime\" is more commonly used in this context. So, sticking with \"J\\'aime la programmation\" is probably the best choice.\\n'}, response_metadata={'token_usage': {'completion_tokens': 346, 'prompt_tokens': 23, 'total_tokens': 369, 'completion_time': 1.447541218, 'prompt_time': 0.000983386, 'queue_time': 0.009673684, 'total_time': 1.448524604}, 'model_name': 'deepseek-r1-distill-llama-70b', 'system_fingerprint': 'fp_e98d30d035', 'finish_reason': 'stop', 'logprobs': None}, id='run--5679ae4f-f4e8-4931-bcd5-7304223832c0-0', usage_metadata={'input_tokens': 23, 'output_tokens': 346, 'total_tokens': 369})"
143153
]
144154
},
145-
"execution_count": 2,
155+
"execution_count": 7,
146156
"metadata": {},
147157
"output_type": "execute_result"
148158
}
@@ -161,17 +171,15 @@
161171
},
162172
{
163173
"cell_type": "code",
164-
"execution_count": 3,
174+
"execution_count": 8,
165175
"id": "d86145b3-bfef-46e8-b227-4dda5c9c2705",
166176
"metadata": {},
167177
"outputs": [
168178
{
169179
"name": "stdout",
170180
"output_type": "stream",
171181
"text": [
172-
"The translation of \"I love programming\" to French is:\n",
173-
"\n",
174-
"\"J'adore le programmation.\"\n"
182+
"J'aime la programmation.\n"
175183
]
176184
}
177185
],
@@ -191,17 +199,17 @@
191199
},
192200
{
193201
"cell_type": "code",
194-
"execution_count": 4,
202+
"execution_count": 9,
195203
"id": "e197d1d7-a070-4c96-9f8a-a0e86d046e0b",
196204
"metadata": {},
197205
"outputs": [
198206
{
199207
"data": {
200208
"text/plain": [
201-
"AIMessage(content='Ich liebe Programmieren.', additional_kwargs={}, response_metadata={'token_usage': {'completion_tokens': 6, 'prompt_tokens': 50, 'total_tokens': 56, 'completion_time': 0.008, 'prompt_time': 0.003337935, 'queue_time': 0.20949214500000002, 'total_time': 0.011337935}, 'model_name': 'llama-3.1-8b-instant', 'system_fingerprint': 'fp_a491995411', 'finish_reason': 'stop', 'logprobs': None}, id='run-e33b48dc-5e55-466e-9ebd-7b48c81c3cbd-0', usage_metadata={'input_tokens': 50, 'output_tokens': 6, 'total_tokens': 56})"
209+
"AIMessage(content='The translation of \"I love programming\" into German is \"Ich liebe das Programmieren.\" \\n\\n**Step-by-Step Explanation:**\\n\\n1. **Subject Pronoun:** \"I\" translates to \"Ich.\"\\n2. **Verb Conjugation:** \"Love\" becomes \"liebe\" (first person singular of \"lieben\").\\n3. **Gerund Translation:** \"Programming\" is translated using the infinitive noun \"Programmieren.\"\\n4. **Article Usage:** The definite article \"das\" is included before the infinitive noun for natural phrasing.\\n\\nThus, the complete and natural translation is:\\n\\n**Ich liebe das Programmieren.**', additional_kwargs={'reasoning_content': 'Okay, so I need to translate the sentence \"I love programming.\" into German. Hmm, let\\'s break this down. \\n\\nFirst, \"I\" in German is \"Ich.\" That\\'s straightforward. Now, \"love\" translates to \"liebe.\" Wait, but in German, the verb conjugation depends on the subject. Since it\\'s \"I,\" the verb would be \"liebe\" because \"lieben\" is the infinitive, and for first person singular, it\\'s \"liebe.\" \\n\\nNext, \"programming\" is a gerund in English, which is the -ing form. In German, the equivalent would be the present participle, which is \"programmierend.\" But wait, sometimes in German, they use the noun form instead of the gerund. So maybe it\\'s better to say \"Ich liebe das Programmieren.\" Because \"Programmieren\" is the infinitive noun form, and it\\'s commonly used in such contexts. \\n\\nLet me think again. \"I love programming\" could be directly translated as \"Ich liebe Programmieren,\" but I\\'ve heard both \"Programmieren\" and \"programmierend\" used. However, \"Ich liebe das Programmieren\" sounds more natural because it uses the definite article \"das\" before the infinitive noun. \\n\\nAlternatively, if I use \"programmieren\" without the article, it\\'s still correct but maybe a bit less common. So, to make it sound more natural and fluent, including the article \"das\" would be better. \\n\\nTherefore, the correct translation should be \"Ich liebe das Programmieren.\" That makes sense because it\\'s similar to saying \"I love (the act of) programming.\" \\n\\nI think that\\'s the most accurate and natural way to express it in German. Let me double-check some examples. If someone says \"I love reading,\" in German it\\'s \"Ich liebe das Lesen.\" So yes, using \"das\" before the infinitive noun is the correct structure. \\n\\nSo, putting it all together, \"I love programming\" becomes \"Ich liebe das Programmieren.\" That should be the right translation.\\n'}, response_metadata={'token_usage': {'completion_tokens': 569, 'prompt_tokens': 18, 'total_tokens': 587, 'completion_time': 2.511255685, 'prompt_time': 0.001466702, 'queue_time': 0.009628211, 'total_time': 2.512722387}, 'model_name': 'deepseek-r1-distill-llama-70b', 'system_fingerprint': 'fp_87eae35036', 'finish_reason': 'stop', 'logprobs': None}, id='run--4d5ee86d-5eec-495c-9c4e-261526cf6e3d-0', usage_metadata={'input_tokens': 18, 'output_tokens': 569, 'total_tokens': 587})"
202210
]
203211
},
204-
"execution_count": 4,
212+
"execution_count": 9,
205213
"metadata": {},
206214
"output_type": "execute_result"
207215
}
@@ -236,7 +244,7 @@
236244
"source": [
237245
"## API reference\n",
238246
"\n",
239-
"For detailed documentation of all ChatGroq features and configurations head to the API reference: https://python.langchain.com/api_reference/groq/chat_models/langchain_groq.chat_models.ChatGroq.html"
247+
"For detailed documentation of all ChatGroq features and configurations head to the [API reference](https://python.langchain.com/api_reference/groq/chat_models/langchain_groq.chat_models.ChatGroq.html)."
240248
]
241249
}
242250
],

libs/core/langchain_core/messages/ai.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class InputTokenDetails(TypedDict, total=False):
5555
}
5656
5757
.. versionadded:: 0.3.9
58+
59+
May also hold extra provider-specific keys.
5860
"""
5961

6062
audio: int

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@
702702
}
703703

704704
.. versionadded:: 0.3.9
705+
706+
May also hold extra provider-specific keys.
705707
''',
706708
'properties': dict({
707709
'audio': dict({
@@ -2132,6 +2134,8 @@
21322134
}
21332135

21342136
.. versionadded:: 0.3.9
2137+
2138+
May also hold extra provider-specific keys.
21352139
''',
21362140
'properties': dict({
21372141
'audio': dict({

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,8 @@
11051105
}
11061106

11071107
.. versionadded:: 0.3.9
1108+
1109+
May also hold extra provider-specific keys.
11081110
''',
11091111
'properties': dict({
11101112
'audio': dict({

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,8 @@
26502650
}
26512651

26522652
.. versionadded:: 0.3.9
2653+
2654+
May also hold extra provider-specific keys.
26532655
''',
26542656
'properties': dict({
26552657
'audio': dict({
@@ -4124,6 +4126,8 @@
41244126
}
41254127

41264128
.. versionadded:: 0.3.9
4129+
4130+
May also hold extra provider-specific keys.
41274131
''',
41284132
'properties': dict({
41294133
'audio': dict({
@@ -5629,6 +5633,8 @@
56295633
}
56305634

56315635
.. versionadded:: 0.3.9
5636+
5637+
May also hold extra provider-specific keys.
56325638
''',
56335639
'properties': dict({
56345640
'audio': dict({
@@ -7009,6 +7015,8 @@
70097015
}
70107016

70117017
.. versionadded:: 0.3.9
7018+
7019+
May also hold extra provider-specific keys.
70127020
''',
70137021
'properties': dict({
70147022
'audio': dict({
@@ -8525,6 +8533,8 @@
85258533
}
85268534

85278535
.. versionadded:: 0.3.9
8536+
8537+
May also hold extra provider-specific keys.
85288538
''',
85298539
'properties': dict({
85308540
'audio': dict({
@@ -9950,6 +9960,8 @@
99509960
}
99519961

99529962
.. versionadded:: 0.3.9
9963+
9964+
May also hold extra provider-specific keys.
99539965
''',
99549966
'properties': dict({
99559967
'audio': dict({
@@ -11374,6 +11386,8 @@
1137411386
}
1137511387

1137611388
.. versionadded:: 0.3.9
11389+
11390+
May also hold extra provider-specific keys.
1137711391
''',
1137811392
'properties': dict({
1137911393
'audio': dict({
@@ -12840,6 +12854,8 @@
1284012854
}
1284112855

1284212856
.. versionadded:: 0.3.9
12857+
12858+
May also hold extra provider-specific keys.
1284312859
''',
1284412860
'properties': dict({
1284512861
'audio': dict({

libs/partners/anthropic/langchain_anthropic/chat_models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ class Joke(BaseModel):
955955
956956
.. dropdown:: Extended caching
957957
958+
.. versionadded:: 0.3.15
959+
958960
The cache lifetime is 5 minutes by default. If this is too short, you can
959961
apply one hour caching by enabling the ``"extended-cache-ttl-2025-04-11"``
960962
beta header:
@@ -968,6 +970,28 @@ class Joke(BaseModel):
968970
969971
and specifying ``"cache_control": {"type": "ephemeral", "ttl": "1h"}``.
970972
973+
Details of cached token counts will be included on the ``InputTokenDetails``
974+
of response's ``usage_metadata``:
975+
976+
.. code-block:: python
977+
978+
response = llm.invoke(messages)
979+
response.usage_metadata
980+
981+
.. code-block:: python
982+
983+
{
984+
"input_tokens": 1500,
985+
"output_tokens": 200,
986+
"total_tokens": 1700,
987+
"input_token_details": {
988+
"cache_read": 0,
989+
"cache_creation": 1000,
990+
"ephemeral_1h_input_tokens": 750,
991+
"ephemeral_5m_input_tokens": 250,
992+
}
993+
}
994+
971995
See `Claude documentation <https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#1-hour-cache-duration-beta>`_
972996
for detail.
973997

libs/partners/groq/langchain_groq/chat_models.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class ChatGroq(BaseChatModel):
168168
'logprobs': None}, id='run-ecc71d70-e10c-4b69-8b8c-b8027d95d4b8-0')
169169
170170
Stream:
171+
172+
Streaming `text` for each content chunk received:
173+
171174
.. code-block:: python
172175
173176
for chunk in llm.stream(messages):
@@ -185,6 +188,8 @@ class ChatGroq(BaseChatModel):
185188
content='' response_metadata={'finish_reason': 'stop'}
186189
id='run-4e9f926b-73f5-483b-8ef5-09533d925853
187190
191+
Reconstructing a full response:
192+
188193
.. code-block:: python
189194
190195
stream = llm.stream(messages)
@@ -196,16 +201,15 @@ class ChatGroq(BaseChatModel):
196201
.. code-block:: python
197202
198203
AIMessageChunk(content='The English sentence "I love programming"
199-
can be translated to French as "J\'aime programmer".
200-
Here\'s the breakdown of the sentence:\n\n* "J\'aime" is the
201-
French equivalent of "I love"\n* "programmer" is the French
202-
infinitive for "to program"\n\nSo, the literal translation
203-
is "I love to program". However, in English we often omit the
204-
"to" when talking about activities we love, and the same applies
205-
to French. Therefore, "J\'aime programmer" is the correct and
206-
natural way to express "I love programming" in French.',
207-
response_metadata={'finish_reason': 'stop'},
208-
id='run-a3c35ac4-0750-4d08-ac55-bfc63805de76')
204+
can be translated to French as "J\'aime programmer". Here\'s the
205+
breakdown of the sentence: "J\'aime" is the French equivalent of "
206+
I love", and "programmer" is the French infinitive for "to program".
207+
So, the literal translation is "I love to program". However, in
208+
English we often omit the "to" when talking about activities we
209+
love, and the same applies to French. Therefore, "J\'aime
210+
programmer" is the correct and natural way to express "I love
211+
programming" in French.', response_metadata={'finish_reason':
212+
'stop'}, id='run-a3c35ac4-0750-4d08-ac55-bfc63805de76')
209213
210214
Async:
211215
.. code-block:: python

0 commit comments

Comments
 (0)