mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
Do not issue beta or deprecation warnings on internal calls (#15641)
This commit is contained in:
parent
ef22559f1f
commit
7ce4cd0709
@ -56,7 +56,7 @@ from langchain_core.caches import RETURN_VAL_TYPE, BaseCache
|
|||||||
from langchain_core.embeddings import Embeddings
|
from langchain_core.embeddings import Embeddings
|
||||||
from langchain_core.language_models.llms import LLM, get_prompts
|
from langchain_core.language_models.llms import LLM, get_prompts
|
||||||
from langchain_core.load.dump import dumps
|
from langchain_core.load.dump import dumps
|
||||||
from langchain_core.load.load import _loads_suppress_warning
|
from langchain_core.load.load import loads
|
||||||
from langchain_core.outputs import ChatGeneration, Generation
|
from langchain_core.outputs import ChatGeneration, Generation
|
||||||
from langchain_core.utils import get_from_env
|
from langchain_core.utils import get_from_env
|
||||||
|
|
||||||
@ -149,10 +149,7 @@ def _loads_generations(generations_str: str) -> Union[RETURN_VAL_TYPE, None]:
|
|||||||
RETURN_VAL_TYPE: A list of generations.
|
RETURN_VAL_TYPE: A list of generations.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
generations = [
|
generations = [loads(_item_str) for _item_str in json.loads(generations_str)]
|
||||||
_loads_suppress_warning(_item_str)
|
|
||||||
for _item_str in json.loads(generations_str)
|
|
||||||
]
|
|
||||||
return generations
|
return generations
|
||||||
except (json.JSONDecodeError, TypeError):
|
except (json.JSONDecodeError, TypeError):
|
||||||
# deferring the (soft) handling to after the legacy-format attempt
|
# deferring the (soft) handling to after the legacy-format attempt
|
||||||
@ -227,7 +224,7 @@ class SQLAlchemyCache(BaseCache):
|
|||||||
rows = session.execute(stmt).fetchall()
|
rows = session.execute(stmt).fetchall()
|
||||||
if rows:
|
if rows:
|
||||||
try:
|
try:
|
||||||
return [_loads_suppress_warning(row[0]) for row in rows]
|
return [loads(row[0]) for row in rows]
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Retrieving a cache value that could not be deserialized "
|
"Retrieving a cache value that could not be deserialized "
|
||||||
@ -398,7 +395,7 @@ class RedisCache(BaseCache):
|
|||||||
if results:
|
if results:
|
||||||
for _, text in results.items():
|
for _, text in results.items():
|
||||||
try:
|
try:
|
||||||
generations.append(_loads_suppress_warning(text))
|
generations.append(loads(text))
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Retrieving a cache value that could not be deserialized "
|
"Retrieving a cache value that could not be deserialized "
|
||||||
@ -538,9 +535,7 @@ class RedisSemanticCache(BaseCache):
|
|||||||
if results:
|
if results:
|
||||||
for document in results:
|
for document in results:
|
||||||
try:
|
try:
|
||||||
generations.extend(
|
generations.extend(loads(document.metadata["return_val"]))
|
||||||
_loads_suppress_warning(document.metadata["return_val"])
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Retrieving a cache value that could not be deserialized "
|
"Retrieving a cache value that could not be deserialized "
|
||||||
@ -1190,7 +1185,7 @@ class SQLAlchemyMd5Cache(BaseCache):
|
|||||||
"""Look up based on prompt and llm_string."""
|
"""Look up based on prompt and llm_string."""
|
||||||
rows = self._search_rows(prompt, llm_string)
|
rows = self._search_rows(prompt, llm_string)
|
||||||
if rows:
|
if rows:
|
||||||
return [_loads_suppress_warning(row[0]) for row in rows]
|
return [loads(row[0]) for row in rows]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def update(self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE) -> None:
|
def update(self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE) -> None:
|
||||||
|
@ -4,7 +4,7 @@ import logging
|
|||||||
from typing import TYPE_CHECKING, Dict, Iterable, Iterator, List, Optional, Union, cast
|
from typing import TYPE_CHECKING, Dict, Iterable, Iterator, List, Optional, Union, cast
|
||||||
|
|
||||||
from langchain_core.chat_sessions import ChatSession
|
from langchain_core.chat_sessions import ChatSession
|
||||||
from langchain_core.load.load import _load_suppress_warning
|
from langchain_core.load.load import load
|
||||||
|
|
||||||
from langchain_community.chat_loaders.base import BaseChatLoader
|
from langchain_community.chat_loaders.base import BaseChatLoader
|
||||||
|
|
||||||
@ -66,10 +66,8 @@ class LangSmithRunChatLoader(BaseChatLoader):
|
|||||||
raise ValueError(f"Run has no 'messages' inputs. Got {llm_run.inputs}")
|
raise ValueError(f"Run has no 'messages' inputs. Got {llm_run.inputs}")
|
||||||
if not llm_run.outputs:
|
if not llm_run.outputs:
|
||||||
raise ValueError("Cannot convert pending run")
|
raise ValueError("Cannot convert pending run")
|
||||||
messages = _load_suppress_warning(llm_run.inputs)["messages"]
|
messages = load(llm_run.inputs)["messages"]
|
||||||
message_chunk = _load_suppress_warning(llm_run.outputs)["generations"][0][
|
message_chunk = load(llm_run.outputs)["generations"][0]["message"]
|
||||||
"message"
|
|
||||||
]
|
|
||||||
return ChatSession(messages=messages + [message_chunk])
|
return ChatSession(messages=messages + [message_chunk])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -4,10 +4,9 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Set
|
from typing import TYPE_CHECKING, Dict, Optional, Set
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from langchain_core._api.deprecation import suppress_langchain_deprecation_warning
|
|
||||||
from langchain_core.messages import BaseMessage
|
from langchain_core.messages import BaseMessage
|
||||||
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
|
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
|
||||||
from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env
|
from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env
|
||||||
@ -73,11 +72,6 @@ class ChatAnyscale(ChatOpenAI):
|
|||||||
available_models: Optional[Set[str]] = None
|
available_models: Optional[Set[str]] = None
|
||||||
"""Available models from Anyscale API."""
|
"""Available models from Anyscale API."""
|
||||||
|
|
||||||
def __init__(self, *kwargs: Any) -> None:
|
|
||||||
# bypass deprecation warning for ChatOpenAI
|
|
||||||
with suppress_langchain_deprecation_warning():
|
|
||||||
super().__init__(*kwargs)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_available_models(
|
def get_available_models(
|
||||||
anyscale_api_key: Optional[str] = None,
|
anyscale_api_key: Optional[str] = None,
|
||||||
|
@ -3,9 +3,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Set
|
from typing import TYPE_CHECKING, Dict, Optional, Set
|
||||||
|
|
||||||
from langchain_core._api.deprecation import suppress_langchain_deprecation_warning
|
|
||||||
from langchain_core.messages import BaseMessage
|
from langchain_core.messages import BaseMessage
|
||||||
from langchain_core.pydantic_v1 import Field, root_validator
|
from langchain_core.pydantic_v1 import Field, root_validator
|
||||||
from langchain_core.utils import get_from_dict_or_env
|
from langchain_core.utils import get_from_dict_or_env
|
||||||
@ -65,11 +64,6 @@ class ChatEverlyAI(ChatOpenAI):
|
|||||||
available_models: Optional[Set[str]] = None
|
available_models: Optional[Set[str]] = None
|
||||||
"""Available models from EverlyAI API."""
|
"""Available models from EverlyAI API."""
|
||||||
|
|
||||||
def __init__(self, *kwargs: Any) -> None:
|
|
||||||
# bypass deprecation warning for ChatOpenAI
|
|
||||||
with suppress_langchain_deprecation_warning():
|
|
||||||
super().__init__(*kwargs)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_available_models() -> Set[str]:
|
def get_available_models() -> Set[str]:
|
||||||
"""Get available models from EverlyAI API."""
|
"""Get available models from EverlyAI API."""
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from langchain_core._api.deprecation import suppress_langchain_deprecation_warning
|
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
AsyncCallbackManagerForLLMRun,
|
AsyncCallbackManagerForLLMRun,
|
||||||
CallbackManagerForLLMRun,
|
CallbackManagerForLLMRun,
|
||||||
@ -40,11 +39,6 @@ class PromptLayerChatOpenAI(ChatOpenAI):
|
|||||||
pl_tags: Optional[List[str]]
|
pl_tags: Optional[List[str]]
|
||||||
return_pl_id: Optional[bool] = False
|
return_pl_id: Optional[bool] = False
|
||||||
|
|
||||||
def __init__(self, *kwargs: Any) -> None:
|
|
||||||
# bypass deprecation warning for ChatOpenAI
|
|
||||||
with suppress_langchain_deprecation_warning():
|
|
||||||
super().__init__(*kwargs)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_lc_serializable(cls) -> bool:
|
def is_lc_serializable(cls) -> bool:
|
||||||
return False
|
return False
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from langchain_core._api.deprecation import suppress_langchain_deprecation_warning
|
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
AsyncCallbackManagerForLLMRun,
|
AsyncCallbackManagerForLLMRun,
|
||||||
CallbackManagerForLLMRun,
|
CallbackManagerForLLMRun,
|
||||||
@ -38,11 +37,6 @@ class PromptLayerOpenAI(OpenAI):
|
|||||||
pl_tags: Optional[List[str]]
|
pl_tags: Optional[List[str]]
|
||||||
return_pl_id: Optional[bool] = False
|
return_pl_id: Optional[bool] = False
|
||||||
|
|
||||||
def __init__(self, *kwargs: Any) -> None:
|
|
||||||
# bypass deprecation warning for ChatOpenAI
|
|
||||||
with suppress_langchain_deprecation_warning():
|
|
||||||
super().__init__(*kwargs)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_lc_serializable(cls) -> bool:
|
def is_lc_serializable(cls) -> bool:
|
||||||
return False
|
return False
|
||||||
|
@ -15,6 +15,8 @@ import inspect
|
|||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Callable, Generator, Type, TypeVar
|
from typing import Any, Callable, Generator, Type, TypeVar
|
||||||
|
|
||||||
|
from langchain_core._api.internal import is_caller_internal
|
||||||
|
|
||||||
|
|
||||||
class LangChainBetaWarning(DeprecationWarning):
|
class LangChainBetaWarning(DeprecationWarning):
|
||||||
"""A class for issuing beta warnings for LangChain users."""
|
"""A class for issuing beta warnings for LangChain users."""
|
||||||
@ -78,6 +80,34 @@ def beta(
|
|||||||
_addendum: str = addendum,
|
_addendum: str = addendum,
|
||||||
) -> T:
|
) -> T:
|
||||||
"""Implementation of the decorator returned by `beta`."""
|
"""Implementation of the decorator returned by `beta`."""
|
||||||
|
|
||||||
|
def emit_warning() -> None:
|
||||||
|
"""Emit the warning."""
|
||||||
|
warn_beta(
|
||||||
|
message=_message,
|
||||||
|
name=_name,
|
||||||
|
obj_type=_obj_type,
|
||||||
|
addendum=_addendum,
|
||||||
|
)
|
||||||
|
|
||||||
|
warned = False
|
||||||
|
|
||||||
|
def warning_emitting_wrapper(*args: Any, **kwargs: Any) -> Any:
|
||||||
|
"""Wrapper for the original wrapped callable that emits a warning.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*args: The positional arguments to the function.
|
||||||
|
**kwargs: The keyword arguments to the function.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The return value of the function being wrapped.
|
||||||
|
"""
|
||||||
|
nonlocal warned
|
||||||
|
if not warned and not is_caller_internal():
|
||||||
|
warned = True
|
||||||
|
emit_warning()
|
||||||
|
return wrapped(*args, **kwargs)
|
||||||
|
|
||||||
if isinstance(obj, type):
|
if isinstance(obj, type):
|
||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "class"
|
_obj_type = "class"
|
||||||
@ -85,14 +115,25 @@ def beta(
|
|||||||
_name = _name or obj.__name__
|
_name = _name or obj.__name__
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
def finalize(_: Any, new_doc: str) -> T:
|
||||||
"""Finalize the annotation of a class."""
|
"""Finalize the annotation of a class."""
|
||||||
try:
|
try:
|
||||||
obj.__doc__ = new_doc
|
obj.__doc__ = new_doc
|
||||||
except AttributeError: # Can't set on some extension objects.
|
except AttributeError: # Can't set on some extension objects.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def warn_if_direct_instance(
|
||||||
|
self: Any, *args: Any, **kwargs: Any
|
||||||
|
) -> Any:
|
||||||
|
"""Warn that the class is in beta."""
|
||||||
|
nonlocal warned
|
||||||
|
if not warned and type(self) is obj and not is_caller_internal():
|
||||||
|
warned = True
|
||||||
|
emit_warning()
|
||||||
|
return wrapped(self, *args, **kwargs)
|
||||||
|
|
||||||
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
||||||
wrapper
|
warn_if_direct_instance
|
||||||
)
|
)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@ -155,28 +196,6 @@ def beta(
|
|||||||
wrapper.__doc__ = new_doc
|
wrapper.__doc__ = new_doc
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def emit_warning() -> None:
|
|
||||||
"""Emit the warning."""
|
|
||||||
warn_beta(
|
|
||||||
message=_message,
|
|
||||||
name=_name,
|
|
||||||
obj_type=_obj_type,
|
|
||||||
addendum=_addendum,
|
|
||||||
)
|
|
||||||
|
|
||||||
def warning_emitting_wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
||||||
"""Wrapper for the original wrapped callable that emits a warning.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
*args: The positional arguments to the function.
|
|
||||||
**kwargs: The keyword arguments to the function.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The return value of the function being wrapped.
|
|
||||||
"""
|
|
||||||
emit_warning()
|
|
||||||
return wrapped(*args, **kwargs)
|
|
||||||
|
|
||||||
old_doc = inspect.cleandoc(old_doc or "").strip("\n")
|
old_doc = inspect.cleandoc(old_doc or "").strip("\n")
|
||||||
|
|
||||||
if not old_doc:
|
if not old_doc:
|
||||||
|
@ -16,6 +16,8 @@ import inspect
|
|||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Callable, Generator, Type, TypeVar
|
from typing import Any, Callable, Generator, Type, TypeVar
|
||||||
|
|
||||||
|
from langchain_core._api.internal import is_caller_internal
|
||||||
|
|
||||||
|
|
||||||
class LangChainDeprecationWarning(DeprecationWarning):
|
class LangChainDeprecationWarning(DeprecationWarning):
|
||||||
"""A class for issuing deprecation warnings for LangChain users."""
|
"""A class for issuing deprecation warnings for LangChain users."""
|
||||||
@ -107,6 +109,38 @@ def deprecated(
|
|||||||
_addendum: str = addendum,
|
_addendum: str = addendum,
|
||||||
) -> T:
|
) -> T:
|
||||||
"""Implementation of the decorator returned by `deprecated`."""
|
"""Implementation of the decorator returned by `deprecated`."""
|
||||||
|
|
||||||
|
def emit_warning() -> None:
|
||||||
|
"""Emit the warning."""
|
||||||
|
warn_deprecated(
|
||||||
|
since,
|
||||||
|
message=_message,
|
||||||
|
name=_name,
|
||||||
|
alternative=_alternative,
|
||||||
|
pending=_pending,
|
||||||
|
obj_type=_obj_type,
|
||||||
|
addendum=_addendum,
|
||||||
|
removal=removal,
|
||||||
|
)
|
||||||
|
|
||||||
|
warned = False
|
||||||
|
|
||||||
|
def warning_emitting_wrapper(*args: Any, **kwargs: Any) -> Any:
|
||||||
|
"""Wrapper for the original wrapped callable that emits a warning.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*args: The positional arguments to the function.
|
||||||
|
**kwargs: The keyword arguments to the function.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The return value of the function being wrapped.
|
||||||
|
"""
|
||||||
|
nonlocal warned
|
||||||
|
if not warned and not is_caller_internal():
|
||||||
|
warned = True
|
||||||
|
emit_warning()
|
||||||
|
return wrapped(*args, **kwargs)
|
||||||
|
|
||||||
if isinstance(obj, type):
|
if isinstance(obj, type):
|
||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "class"
|
_obj_type = "class"
|
||||||
@ -114,14 +148,25 @@ def deprecated(
|
|||||||
_name = _name or obj.__name__
|
_name = _name or obj.__name__
|
||||||
old_doc = obj.__doc__
|
old_doc = obj.__doc__
|
||||||
|
|
||||||
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
def finalize(_: Any, new_doc: str) -> T:
|
||||||
"""Finalize the deprecation of a class."""
|
"""Finalize the deprecation of a class."""
|
||||||
try:
|
try:
|
||||||
obj.__doc__ = new_doc
|
obj.__doc__ = new_doc
|
||||||
except AttributeError: # Can't set on some extension objects.
|
except AttributeError: # Can't set on some extension objects.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def warn_if_direct_instance(
|
||||||
|
self: Any, *args: Any, **kwargs: Any
|
||||||
|
) -> Any:
|
||||||
|
"""Warn that the class is in beta."""
|
||||||
|
nonlocal warned
|
||||||
|
if not warned and type(self) is obj and not is_caller_internal():
|
||||||
|
warned = True
|
||||||
|
emit_warning()
|
||||||
|
return wrapped(self, *args, **kwargs)
|
||||||
|
|
||||||
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
||||||
wrapper
|
warn_if_direct_instance
|
||||||
)
|
)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@ -184,32 +229,6 @@ def deprecated(
|
|||||||
wrapper.__doc__ = new_doc
|
wrapper.__doc__ = new_doc
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def emit_warning() -> None:
|
|
||||||
"""Emit the warning."""
|
|
||||||
warn_deprecated(
|
|
||||||
since,
|
|
||||||
message=_message,
|
|
||||||
name=_name,
|
|
||||||
alternative=_alternative,
|
|
||||||
pending=_pending,
|
|
||||||
obj_type=_obj_type,
|
|
||||||
addendum=_addendum,
|
|
||||||
removal=removal,
|
|
||||||
)
|
|
||||||
|
|
||||||
def warning_emitting_wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
||||||
"""Wrapper for the original wrapped callable that emits a warning.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
*args: The positional arguments to the function.
|
|
||||||
**kwargs: The keyword arguments to the function.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The return value of the function being wrapped.
|
|
||||||
"""
|
|
||||||
emit_warning()
|
|
||||||
return wrapped(*args, **kwargs)
|
|
||||||
|
|
||||||
old_doc = inspect.cleandoc(old_doc or "").strip("\n")
|
old_doc = inspect.cleandoc(old_doc or "").strip("\n")
|
||||||
|
|
||||||
if not old_doc:
|
if not old_doc:
|
||||||
|
23
libs/core/langchain_core/_api/internal.py
Normal file
23
libs/core/langchain_core/_api/internal.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import inspect
|
||||||
|
|
||||||
|
|
||||||
|
def is_caller_internal(depth: int = 2) -> bool:
|
||||||
|
"""Return whether the caller at `depth` of this function is internal."""
|
||||||
|
try:
|
||||||
|
frame = inspect.currentframe()
|
||||||
|
except AttributeError:
|
||||||
|
return False
|
||||||
|
if frame is None:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
for _ in range(depth):
|
||||||
|
frame = frame.f_back
|
||||||
|
if frame is None:
|
||||||
|
return False
|
||||||
|
caller_module = inspect.getmodule(frame)
|
||||||
|
if caller_module is None:
|
||||||
|
return False
|
||||||
|
caller_module_name = caller_module.__name__
|
||||||
|
return caller_module_name.startswith("langchain")
|
||||||
|
finally:
|
||||||
|
del frame
|
@ -3,7 +3,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from langchain_core._api import beta, suppress_langchain_beta_warning
|
from langchain_core._api import beta
|
||||||
from langchain_core.load.mapping import (
|
from langchain_core.load.mapping import (
|
||||||
OLD_PROMPT_TEMPLATE_FORMATS,
|
OLD_PROMPT_TEMPLATE_FORMATS,
|
||||||
SERIALIZABLE_MAPPING,
|
SERIALIZABLE_MAPPING,
|
||||||
@ -125,16 +125,6 @@ def loads(
|
|||||||
return json.loads(text, object_hook=Reviver(secrets_map, valid_namespaces))
|
return json.loads(text, object_hook=Reviver(secrets_map, valid_namespaces))
|
||||||
|
|
||||||
|
|
||||||
def _loads_suppress_warning(
|
|
||||||
text: str,
|
|
||||||
*,
|
|
||||||
secrets_map: Optional[Dict[str, str]] = None,
|
|
||||||
valid_namespaces: Optional[List[str]] = None,
|
|
||||||
) -> Any:
|
|
||||||
with suppress_langchain_beta_warning():
|
|
||||||
return loads(text, secrets_map=secrets_map, valid_namespaces=valid_namespaces)
|
|
||||||
|
|
||||||
|
|
||||||
@beta()
|
@beta()
|
||||||
def load(
|
def load(
|
||||||
obj: Any,
|
obj: Any,
|
||||||
@ -166,13 +156,3 @@ def load(
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
return _load(obj)
|
return _load(obj)
|
||||||
|
|
||||||
|
|
||||||
def _load_suppress_warning(
|
|
||||||
obj: Any,
|
|
||||||
*,
|
|
||||||
secrets_map: Optional[Dict[str, str]] = None,
|
|
||||||
valid_namespaces: Optional[List[str]] = None,
|
|
||||||
) -> Any:
|
|
||||||
with suppress_langchain_beta_warning():
|
|
||||||
return load(obj, secrets_map=secrets_map, valid_namespaces=valid_namespaces)
|
|
||||||
|
@ -14,7 +14,7 @@ from typing import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from langchain_core.chat_history import BaseChatMessageHistory
|
from langchain_core.chat_history import BaseChatMessageHistory
|
||||||
from langchain_core.load.load import _load_suppress_warning
|
from langchain_core.load.load import load
|
||||||
from langchain_core.pydantic_v1 import BaseModel, create_model
|
from langchain_core.pydantic_v1 import BaseModel, create_model
|
||||||
from langchain_core.runnables.base import Runnable, RunnableBindingBase, RunnableLambda
|
from langchain_core.runnables.base import Runnable, RunnableBindingBase, RunnableLambda
|
||||||
from langchain_core.runnables.config import run_in_executor
|
from langchain_core.runnables.config import run_in_executor
|
||||||
@ -337,7 +337,7 @@ class RunnableWithMessageHistory(RunnableBindingBase):
|
|||||||
hist = config["configurable"]["message_history"]
|
hist = config["configurable"]["message_history"]
|
||||||
|
|
||||||
# Get the input messages
|
# Get the input messages
|
||||||
inputs = _load_suppress_warning(run.inputs)
|
inputs = load(run.inputs)
|
||||||
input_val = inputs[self.input_messages_key or "input"]
|
input_val = inputs[self.input_messages_key or "input"]
|
||||||
input_messages = self._get_input_messages(input_val)
|
input_messages = self._get_input_messages(input_val)
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ class RunnableWithMessageHistory(RunnableBindingBase):
|
|||||||
input_messages = input_messages[len(historic_messages) :]
|
input_messages = input_messages[len(historic_messages) :]
|
||||||
|
|
||||||
# Get the output messages
|
# Get the output messages
|
||||||
output_val = _load_suppress_warning(run.outputs)
|
output_val = load(run.outputs)
|
||||||
output_messages = self._get_output_messages(output_val)
|
output_messages = self._get_output_messages(output_val)
|
||||||
|
|
||||||
for m in input_messages + output_messages:
|
for m in input_messages + output_messages:
|
||||||
|
@ -20,7 +20,7 @@ from uuid import UUID
|
|||||||
import jsonpatch # type: ignore[import]
|
import jsonpatch # type: ignore[import]
|
||||||
from anyio import create_memory_object_stream
|
from anyio import create_memory_object_stream
|
||||||
|
|
||||||
from langchain_core.load.load import _load_suppress_warning
|
from langchain_core.load.load import load
|
||||||
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk
|
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk
|
||||||
from langchain_core.tracers.base import BaseTracer
|
from langchain_core.tracers.base import BaseTracer
|
||||||
from langchain_core.tracers.schemas import Run
|
from langchain_core.tracers.schemas import Run
|
||||||
@ -293,7 +293,7 @@ class LogStreamCallbackHandler(BaseTracer):
|
|||||||
"op": "add",
|
"op": "add",
|
||||||
"path": f"/logs/{index}/final_output",
|
"path": f"/logs/{index}/final_output",
|
||||||
# to undo the dumpd done by some runnables / tracer / etc
|
# to undo the dumpd done by some runnables / tracer / etc
|
||||||
"value": _load_suppress_warning(run.outputs),
|
"value": load(run.outputs),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"op": "add",
|
"op": "add",
|
||||||
|
Loading…
Reference in New Issue
Block a user