langchain-core 0.3.77__py3-none-any.whl → 0.3.79__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of langchain-core might be problematic. Click here for more details.
- langchain_core/messages/utils.py +5 -0
- langchain_core/prompts/string.py +17 -4
- langchain_core/version.py +1 -1
- {langchain_core-0.3.77.dist-info → langchain_core-0.3.79.dist-info}/METADATA +1 -1
- {langchain_core-0.3.77.dist-info → langchain_core-0.3.79.dist-info}/RECORD +7 -7
- {langchain_core-0.3.77.dist-info → langchain_core-0.3.79.dist-info}/WHEEL +0 -0
- {langchain_core-0.3.77.dist-info → langchain_core-0.3.79.dist-info}/entry_points.txt +0 -0
langchain_core/messages/utils.py
CHANGED
|
@@ -1040,6 +1040,7 @@ def convert_to_openai_messages(
|
|
|
1040
1040
|
messages: Union[MessageLikeRepresentation, Sequence[MessageLikeRepresentation]],
|
|
1041
1041
|
*,
|
|
1042
1042
|
text_format: Literal["string", "block"] = "string",
|
|
1043
|
+
include_id: bool = False,
|
|
1043
1044
|
) -> Union[dict, list[dict]]:
|
|
1044
1045
|
"""Convert LangChain messages into OpenAI message dicts.
|
|
1045
1046
|
|
|
@@ -1057,6 +1058,8 @@ def convert_to_openai_messages(
|
|
|
1057
1058
|
If a message has a string content, this is turned into a list
|
|
1058
1059
|
with a single content block of type ``'text'``. If a message has
|
|
1059
1060
|
content blocks these are left as is.
|
|
1061
|
+
include_id: Whether to include message ids in the openai messages, if they
|
|
1062
|
+
are present in the source messages.
|
|
1060
1063
|
|
|
1061
1064
|
Raises:
|
|
1062
1065
|
ValueError: if an unrecognized ``text_format`` is specified, or if a message
|
|
@@ -1145,6 +1148,8 @@ def convert_to_openai_messages(
|
|
|
1145
1148
|
oai_msg["refusal"] = message.additional_kwargs["refusal"]
|
|
1146
1149
|
if isinstance(message, ToolMessage):
|
|
1147
1150
|
oai_msg["tool_call_id"] = message.tool_call_id
|
|
1151
|
+
if include_id and message.id:
|
|
1152
|
+
oai_msg["id"] = message.id
|
|
1148
1153
|
|
|
1149
1154
|
if not message.content:
|
|
1150
1155
|
content = "" if text_format == "string" else []
|
langchain_core/prompts/string.py
CHANGED
|
@@ -4,8 +4,9 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import warnings
|
|
6
6
|
from abc import ABC
|
|
7
|
+
from collections.abc import Callable, Sequence
|
|
7
8
|
from string import Formatter
|
|
8
|
-
from typing import Any,
|
|
9
|
+
from typing import Any, Literal
|
|
9
10
|
|
|
10
11
|
from pydantic import BaseModel, create_model
|
|
11
12
|
|
|
@@ -148,9 +149,7 @@ def mustache_template_vars(
|
|
|
148
149
|
Defs = dict[str, "Defs"]
|
|
149
150
|
|
|
150
151
|
|
|
151
|
-
def mustache_schema(
|
|
152
|
-
template: str,
|
|
153
|
-
) -> type[BaseModel]:
|
|
152
|
+
def mustache_schema(template: str) -> type[BaseModel]:
|
|
154
153
|
"""Get the variables from a mustache template.
|
|
155
154
|
|
|
156
155
|
Args:
|
|
@@ -174,6 +173,11 @@ def mustache_schema(
|
|
|
174
173
|
fields[prefix] = False
|
|
175
174
|
elif type_ in {"variable", "no escape"}:
|
|
176
175
|
fields[prefix + tuple(key.split("."))] = True
|
|
176
|
+
|
|
177
|
+
for fkey, fval in fields.items():
|
|
178
|
+
fields[fkey] = fval and not any(
|
|
179
|
+
is_subsequence(fkey, k) for k in fields if k != fkey
|
|
180
|
+
)
|
|
177
181
|
defs: Defs = {} # None means leaf node
|
|
178
182
|
while fields:
|
|
179
183
|
field, is_leaf = fields.popitem()
|
|
@@ -326,3 +330,12 @@ class StringPromptTemplate(BasePromptTemplate, ABC):
|
|
|
326
330
|
def pretty_print(self) -> None:
|
|
327
331
|
"""Print a pretty representation of the prompt."""
|
|
328
332
|
print(self.pretty_repr(html=is_interactive_env())) # noqa: T201
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def is_subsequence(child: Sequence, parent: Sequence) -> bool:
|
|
336
|
+
"""Return True if child is subsequence of parent."""
|
|
337
|
+
if len(child) == 0 or len(parent) == 0:
|
|
338
|
+
return False
|
|
339
|
+
if len(parent) < len(child):
|
|
340
|
+
return False
|
|
341
|
+
return all(child[i] == parent[i] for i in range(len(child)))
|
langchain_core/version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
langchain_core-0.3.
|
|
2
|
-
langchain_core-0.3.
|
|
3
|
-
langchain_core-0.3.
|
|
1
|
+
langchain_core-0.3.79.dist-info/METADATA,sha256=zXbyMC_ayuewGmdE_v74VpKWbKQ6-YQSK6TVcoYNz8s,3155
|
|
2
|
+
langchain_core-0.3.79.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
|
3
|
+
langchain_core-0.3.79.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
4
4
|
langchain_core/__init__.py,sha256=TgvhxbrjCRVJwr2HddiyHvtH8W94K-uLM6-6ifNIBXo,713
|
|
5
5
|
langchain_core/_api/__init__.py,sha256=WDOMw4faVuscjDCL5ttnRQNienJP_M9vGMmJUXS6L5w,1976
|
|
6
6
|
langchain_core/_api/beta_decorator.py,sha256=XK7dDgbsyBTiZMjUxVB_bUuuGR1X8T_zBgEBya55mQU,8813
|
|
@@ -68,7 +68,7 @@ langchain_core/messages/human.py,sha256=UZjG3KJLX8IF2VrYtj8EQ_O9tLjz-Xlp8gL60qDR
|
|
|
68
68
|
langchain_core/messages/modifier.py,sha256=N0vSbZa1jpzMom8_Vr0hr-ZAJi9eh1I8NkMVB5TQ2RI,895
|
|
69
69
|
langchain_core/messages/system.py,sha256=cMSNtauXX9AJ7NiJ8tYXa0rrVT46s-6t09Ec00la3PQ,1692
|
|
70
70
|
langchain_core/messages/tool.py,sha256=DiJQUmrOnRDUz74q7jofvJwbh_ghnT50iveMeGfy2hY,12668
|
|
71
|
-
langchain_core/messages/utils.py,sha256=
|
|
71
|
+
langchain_core/messages/utils.py,sha256=GCybSPKerfy7KYttj3EtPeK2BZ2V8N2fzL_m61s0xXk,70715
|
|
72
72
|
langchain_core/output_parsers/__init__.py,sha256=R8L0GwY-vD9qvqze3EVELXF6i45IYUJ_FbSfno_IREg,2873
|
|
73
73
|
langchain_core/output_parsers/base.py,sha256=53Yt9dOlR686ku0dP2LK9hHKGprxw_YEsAsY04dejmE,11225
|
|
74
74
|
langchain_core/output_parsers/format_instructions.py,sha256=8oUbeysnVGvXWyNd5gqXlEL850D31gMTy74GflsuvRU,553
|
|
@@ -98,7 +98,7 @@ langchain_core/prompts/loading.py,sha256=_T26PCTuZuOsCkHk_uv-h_zoIMonXojBdYJA3Us
|
|
|
98
98
|
langchain_core/prompts/message.py,sha256=9I5IZXFn2Bwv8CIZ0zMp7k8C48xQyiAOqyv6uAYJdY0,2624
|
|
99
99
|
langchain_core/prompts/pipeline.py,sha256=Zj6aqIcU874mnYG__0I4nHmz4p7uaNAdYsJpMDb1LyQ,4612
|
|
100
100
|
langchain_core/prompts/prompt.py,sha256=RfD-w7GKolgptGB72UVIb1q3iIOm4pv2hby6EmJf9kk,11667
|
|
101
|
-
langchain_core/prompts/string.py,sha256=
|
|
101
|
+
langchain_core/prompts/string.py,sha256=3S2JvvlXxYj1bU_9jQZ1TUMruHGef4ht394bN3Kbn6E,10852
|
|
102
102
|
langchain_core/prompts/structured.py,sha256=V5qfOpSPWBnF5xcRl_qEmrv1u7T_IfzONHJ-rUFiTyE,5957
|
|
103
103
|
langchain_core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
104
104
|
langchain_core/pydantic_v1/__init__.py,sha256=hqAsQjsfqLduCo5E0oAAAt21Nkls0S6bCQ4tD2moFfU,1080
|
|
@@ -170,5 +170,5 @@ langchain_core/vectorstores/__init__.py,sha256=5P0eoeoH5LHab64JjmEeWa6SxX4eMy-et
|
|
|
170
170
|
langchain_core/vectorstores/base.py,sha256=nWlfzbkVdOObfbPpvfdLKHw9J0PryACVohHC_Y6wWZM,41529
|
|
171
171
|
langchain_core/vectorstores/in_memory.py,sha256=btq53JnPZHMRGCbejVx1H-6RSNRAgtacd-XAx6dt-Q8,18076
|
|
172
172
|
langchain_core/vectorstores/utils.py,sha256=D6St53Xg1kO73dnw4MPd8vlkro4C3gmCpcghUzcepi0,4971
|
|
173
|
-
langchain_core/version.py,sha256=
|
|
174
|
-
langchain_core-0.3.
|
|
173
|
+
langchain_core/version.py,sha256=ZGSZY6K4Q6YurFJFB-TZaakyu68sDUPdaH7fA7HxP98,76
|
|
174
|
+
langchain_core-0.3.79.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|