diff --git a/libs/core/langchain_core/utils/__init__.py b/libs/core/langchain_core/utils/__init__.py index 6383e8c4b0703..df7a586b8c3e8 100644 --- a/libs/core/langchain_core/utils/__init__.py +++ b/libs/core/langchain_core/utils/__init__.py @@ -4,7 +4,6 @@ These functions do not depend on any other LangChain module. """ -from langchain_core.utils.env import get_from_dict_or_env, get_from_env from langchain_core.utils.formatting import StrictFormatter, formatter from langchain_core.utils.input import ( get_bolded_text, @@ -12,7 +11,6 @@ get_colored_text, print_text, ) -from langchain_core.utils.strings import comma_list, stringify_dict, stringify_value from langchain_core.utils.utils import ( check_package_version, convert_to_secret_str, @@ -26,20 +24,15 @@ __all__ = [ "StrictFormatter", "check_package_version", - "comma_list", "convert_to_secret_str", "formatter", "get_bolded_text", "get_color_mapping", "get_colored_text", - "get_from_dict_or_env", - "get_from_env", "get_pydantic_field_names", "guard_import", "mock_now", "print_text", "raise_for_status_with_text", - "stringify_dict", - "stringify_value", "xor_args", ] diff --git a/libs/core/langchain_core/utils/env.py b/libs/core/langchain_core/utils/env.py deleted file mode 100644 index f9ac5aba926f7..0000000000000 --- a/libs/core/langchain_core/utils/env.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -from typing import Any, Dict, Optional - - -def get_from_dict_or_env( - data: Dict[str, Any], key: str, env_key: str, default: Optional[str] = None -) -> str: - """Get a value from a dictionary or an environment variable.""" - if key in data and data[key]: - return data[key] - else: - return get_from_env(key, env_key, default=default) - - -def get_from_env(key: str, env_key: str, default: Optional[str] = None) -> str: - """Get a value from a dictionary or an environment variable.""" - if env_key in os.environ and os.environ[env_key]: - return os.environ[env_key] - elif default is not None: - return default - else: - raise ValueError( - f"Did not find {key}, please add an environment variable" - f" `{env_key}` which contains it, or pass" - f" `{key}` as a named parameter." - ) diff --git a/libs/core/langchain_core/utils/strings.py b/libs/core/langchain_core/utils/strings.py deleted file mode 100644 index 3e866f059ffe2..0000000000000 --- a/libs/core/langchain_core/utils/strings.py +++ /dev/null @@ -1,40 +0,0 @@ -from typing import Any, List - - -def stringify_value(val: Any) -> str: - """Stringify a value. - - Args: - val: The value to stringify. - - Returns: - str: The stringified value. - """ - if isinstance(val, str): - return val - elif isinstance(val, dict): - return "\n" + stringify_dict(val) - elif isinstance(val, list): - return "\n".join(stringify_value(v) for v in val) - else: - return str(val) - - -def stringify_dict(data: dict) -> str: - """Stringify a dictionary. - - Args: - data: The dictionary to stringify. - - Returns: - str: The stringified dictionary. - """ - text = "" - for key, value in data.items(): - text += key + ": " + stringify_value(value) + "\n" - return text - - -def comma_list(items: List[Any]) -> str: - """Convert a list to a comma-separated string.""" - return ", ".join(str(item) for item in items) diff --git a/libs/core/tests/unit_tests/utils/test_imports.py b/libs/core/tests/unit_tests/utils/test_imports.py index a392d9e20cdff..91e5c016e7d67 100644 --- a/libs/core/tests/unit_tests/utils/test_imports.py +++ b/libs/core/tests/unit_tests/utils/test_imports.py @@ -3,21 +3,16 @@ EXPECTED_ALL = [ "StrictFormatter", "check_package_version", - "comma_list", "convert_to_secret_str", "formatter", "get_bolded_text", "get_color_mapping", "get_colored_text", - "get_from_dict_or_env", - "get_from_env", "get_pydantic_field_names", "guard_import", "mock_now", "print_text", "raise_for_status_with_text", - "stringify_dict", - "stringify_value", "xor_args", ] diff --git a/libs/langchain/langchain/cache.py b/libs/langchain/langchain/cache.py index 09aa6ead06f5e..46197c119a62a 100644 --- a/libs/langchain/langchain/cache.py +++ b/libs/langchain/langchain/cache.py @@ -56,9 +56,9 @@ from langchain_core.schema import ChatGeneration, Generation from langchain_core.schema.cache import RETURN_VAL_TYPE, BaseCache from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_env from langchain.llms.base import LLM, get_prompts +from langchain.utils import get_from_env from langchain.vectorstores.redis import Redis as RedisVectorstore logger = logging.getLogger(__file__) diff --git a/libs/langchain/langchain/callbacks/mlflow_callback.py b/libs/langchain/langchain/callbacks/mlflow_callback.py index 1fa30bfb91cd6..881d674547068 100644 --- a/libs/langchain/langchain/callbacks/mlflow_callback.py +++ b/libs/langchain/langchain/callbacks/mlflow_callback.py @@ -8,7 +8,6 @@ from typing import Any, Dict, List, Optional, Union from langchain_core.schema import AgentAction, AgentFinish, LLMResult -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.base import BaseCallbackHandler from langchain.callbacks.utils import ( @@ -19,6 +18,7 @@ import_spacy, import_textstat, ) +from langchain.utils import get_from_dict_or_env def import_mlflow() -> Any: diff --git a/libs/langchain/langchain/callbacks/whylabs_callback.py b/libs/langchain/langchain/callbacks/whylabs_callback.py index 5d5ebfed9b526..0eef25d360969 100644 --- a/libs/langchain/langchain/callbacks/whylabs_callback.py +++ b/libs/langchain/langchain/callbacks/whylabs_callback.py @@ -3,9 +3,8 @@ import logging from typing import TYPE_CHECKING, Any, Optional -from langchain_core.utils import get_from_env - from langchain.callbacks.base import BaseCallbackHandler +from langchain.utils import get_from_env if TYPE_CHECKING: from whylogs.api.logger.logger import Logger diff --git a/libs/langchain/langchain/chains/moderation.py b/libs/langchain/langchain/chains/moderation.py index 30d1e0f84059c..c2935f3feb317 100644 --- a/libs/langchain/langchain/chains/moderation.py +++ b/libs/langchain/langchain/chains/moderation.py @@ -2,10 +2,10 @@ from typing import Any, Dict, List, Optional from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForChainRun from langchain.chains.base import Chain +from langchain.utils import get_from_dict_or_env class OpenAIModerationChain(Chain): diff --git a/libs/langchain/langchain/chat_models/anyscale.py b/libs/langchain/langchain/chat_models/anyscale.py index ad542e75a5fda..9857e7a0a1348 100644 --- a/libs/langchain/langchain/chat_models/anyscale.py +++ b/libs/langchain/langchain/chat_models/anyscale.py @@ -9,7 +9,7 @@ import requests from langchain_core.pydantic_v1 import Field, SecretStr, root_validator from langchain_core.schema.messages import BaseMessage -from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env +from langchain_core.utils import convert_to_secret_str from langchain_core.utils.openai import is_openai_v1 from langchain.adapters.openai import convert_message_to_dict @@ -17,6 +17,7 @@ ChatOpenAI, _import_tiktoken, ) +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: import tiktoken diff --git a/libs/langchain/langchain/chat_models/azure_openai.py b/libs/langchain/langchain/chat_models/azure_openai.py index ef637b1f1d6c4..f82b353cc9b01 100644 --- a/libs/langchain/langchain/chat_models/azure_openai.py +++ b/libs/langchain/langchain/chat_models/azure_openai.py @@ -8,10 +8,10 @@ from langchain_core.pydantic_v1 import BaseModel, Field, root_validator from langchain_core.schema import ChatResult -from langchain_core.utils import get_from_dict_or_env from langchain_core.utils.openai import is_openai_v1 from langchain.chat_models.openai import ChatOpenAI +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/chat_models/azureml_endpoint.py b/libs/langchain/langchain/chat_models/azureml_endpoint.py index b16347a94a8a0..089acc6605108 100644 --- a/libs/langchain/langchain/chat_models/azureml_endpoint.py +++ b/libs/langchain/langchain/chat_models/azureml_endpoint.py @@ -9,11 +9,12 @@ HumanMessage, SystemMessage, ) -from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env +from langchain_core.utils import convert_to_secret_str from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.chat_models.base import SimpleChatModel from langchain.llms.azureml_endpoint import AzureMLEndpointClient, ContentFormatterBase +from langchain.utils import get_from_dict_or_env class LlamaContentFormatter(ContentFormatterBase): diff --git a/libs/langchain/langchain/chat_models/baichuan.py b/libs/langchain/langchain/chat_models/baichuan.py index 2bed3e9587b56..ee5bb850bbcba 100644 --- a/libs/langchain/langchain/chat_models/baichuan.py +++ b/libs/langchain/langchain/chat_models/baichuan.py @@ -23,12 +23,12 @@ from langchain_core.schema.output import ChatGenerationChunk from langchain_core.utils import ( convert_to_secret_str, - get_from_dict_or_env, get_pydantic_field_names, ) from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.chat_models.base import BaseChatModel, _generate_from_stream +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py b/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py index 75aaff26f3438..27f41463ed3d7 100644 --- a/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py +++ b/libs/langchain/langchain/chat_models/baidu_qianfan_endpoint.py @@ -15,13 +15,13 @@ SystemMessage, ) from langchain_core.schema.output import ChatGenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) from langchain.chat_models.base import BaseChatModel +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/chat_models/ernie.py b/libs/langchain/langchain/chat_models/ernie.py index 23d35a8becb69..65a037218a559 100644 --- a/libs/langchain/langchain/chat_models/ernie.py +++ b/libs/langchain/langchain/chat_models/ernie.py @@ -13,10 +13,10 @@ ChatResult, HumanMessage, ) -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.chat_models.base import BaseChatModel +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/chat_models/everlyai.py b/libs/langchain/langchain/chat_models/everlyai.py index 6a29c91f1212b..5b846fdce9c46 100644 --- a/libs/langchain/langchain/chat_models/everlyai.py +++ b/libs/langchain/langchain/chat_models/everlyai.py @@ -7,13 +7,13 @@ from langchain_core.pydantic_v1 import Field, root_validator from langchain_core.schema.messages import BaseMessage -from langchain_core.utils import get_from_dict_or_env from langchain.adapters.openai import convert_message_to_dict from langchain.chat_models.openai import ( ChatOpenAI, _import_tiktoken, ) +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: import tiktoken diff --git a/libs/langchain/langchain/chat_models/google_palm.py b/libs/langchain/langchain/chat_models/google_palm.py index fbdc209c3f911..ed85c236f6818 100644 --- a/libs/langchain/langchain/chat_models/google_palm.py +++ b/libs/langchain/langchain/chat_models/google_palm.py @@ -16,7 +16,6 @@ HumanMessage, SystemMessage, ) -from langchain_core.utils import get_from_dict_or_env from tenacity import ( before_sleep_log, retry, @@ -30,6 +29,7 @@ CallbackManagerForLLMRun, ) from langchain.chat_models.base import BaseChatModel +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: import google.generativeai as genai diff --git a/libs/langchain/langchain/chat_models/jinachat.py b/libs/langchain/langchain/chat_models/jinachat.py index 7ffe8728fb04c..ee4347e5ef310 100644 --- a/libs/langchain/langchain/chat_models/jinachat.py +++ b/libs/langchain/langchain/chat_models/jinachat.py @@ -35,7 +35,7 @@ SystemMessageChunk, ) from langchain_core.schema.output import ChatGenerationChunk -from langchain_core.utils import get_from_dict_or_env, get_pydantic_field_names +from langchain_core.utils import get_pydantic_field_names from tenacity import ( before_sleep_log, retry, @@ -53,6 +53,7 @@ _agenerate_from_stream, _generate_from_stream, ) +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/chat_models/konko.py b/libs/langchain/langchain/chat_models/konko.py index 7b6a0373481f3..aad978123dfae 100644 --- a/libs/langchain/langchain/chat_models/konko.py +++ b/libs/langchain/langchain/chat_models/konko.py @@ -20,7 +20,6 @@ from langchain_core.schema import ChatGeneration, ChatResult from langchain_core.schema.messages import AIMessageChunk, BaseMessage from langchain_core.schema.output import ChatGenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.adapters.openai import convert_dict_to_message, convert_message_to_dict from langchain.callbacks.manager import ( @@ -28,6 +27,7 @@ ) from langchain.chat_models.base import BaseChatModel, _generate_from_stream from langchain.chat_models.openai import _convert_delta_to_message_chunk +from langchain.utils import get_from_dict_or_env DEFAULT_API_BASE = "https://api.konko.ai/v1" DEFAULT_MODEL = "meta-llama/Llama-2-13b-chat-hf" diff --git a/libs/langchain/langchain/chat_models/litellm.py b/libs/langchain/langchain/chat_models/litellm.py index 143b4ef83a20c..c5b32fae61d61 100644 --- a/libs/langchain/langchain/chat_models/litellm.py +++ b/libs/langchain/langchain/chat_models/litellm.py @@ -36,7 +36,6 @@ SystemMessageChunk, ) from langchain_core.schema.output import ChatGenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -48,6 +47,7 @@ _generate_from_stream, ) from langchain.llms.base import create_base_retry_decorator +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/chat_models/openai.py b/libs/langchain/langchain/chat_models/openai.py index 21ca6360aa611..a1df98c3e48e3 100644 --- a/libs/langchain/langchain/chat_models/openai.py +++ b/libs/langchain/langchain/chat_models/openai.py @@ -36,7 +36,6 @@ ) from langchain_core.schema.output import ChatGenerationChunk from langchain_core.utils import ( - get_from_dict_or_env, get_pydantic_field_names, ) from langchain_core.utils.openai import is_openai_v1 @@ -52,6 +51,7 @@ _generate_from_stream, ) from langchain.llms.base import create_base_retry_decorator +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: import tiktoken diff --git a/libs/langchain/langchain/chat_models/pai_eas_endpoint.py b/libs/langchain/langchain/chat_models/pai_eas_endpoint.py index b4985687d23f4..23329144b72b2 100644 --- a/libs/langchain/langchain/chat_models/pai_eas_endpoint.py +++ b/libs/langchain/langchain/chat_models/pai_eas_endpoint.py @@ -16,7 +16,6 @@ SystemMessage, ) from langchain_core.schema.output import ChatGenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -24,6 +23,7 @@ ) from langchain.chat_models.base import BaseChatModel from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/chat_models/tongyi.py b/libs/langchain/langchain/chat_models/tongyi.py index ad84b1513ba18..c079349840c2f 100644 --- a/libs/langchain/langchain/chat_models/tongyi.py +++ b/libs/langchain/langchain/chat_models/tongyi.py @@ -30,7 +30,6 @@ SystemMessageChunk, ) from langchain_core.schema.output import ChatGenerationChunk, GenerationChunk -from langchain_core.utils import get_from_dict_or_env from requests.exceptions import HTTPError from tenacity import ( RetryCallState, @@ -45,6 +44,7 @@ BaseChatModel, _generate_from_stream, ) +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/document_loaders/airbyte_json.py b/libs/langchain/langchain/document_loaders/airbyte_json.py index ee8734331d6bc..02bcb9e50ef54 100644 --- a/libs/langchain/langchain/document_loaders/airbyte_json.py +++ b/libs/langchain/langchain/document_loaders/airbyte_json.py @@ -1,10 +1,9 @@ import json from typing import List -from langchain_core.utils import stringify_dict - from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader +from langchain.utils import stringify_dict class AirbyteJSONLoader(BaseLoader): diff --git a/libs/langchain/langchain/document_loaders/embaas.py b/libs/langchain/langchain/document_loaders/embaas.py index f80beaded6e66..8c1025f55f384 100644 --- a/libs/langchain/langchain/document_loaders/embaas.py +++ b/libs/langchain/langchain/document_loaders/embaas.py @@ -4,13 +4,13 @@ import requests from langchain_core.pydantic_v1 import BaseModel, root_validator, validator -from langchain_core.utils import get_from_dict_or_env from typing_extensions import NotRequired, TypedDict from langchain.docstore.document import Document from langchain.document_loaders.base import BaseBlobParser, BaseLoader from langchain.document_loaders.blob_loaders import Blob from langchain.text_splitter import TextSplitter +from langchain.utils import get_from_dict_or_env EMBAAS_DOC_API_URL = "https://api.embaas.io/v1/document/extract-text/bytes/" diff --git a/libs/langchain/langchain/document_loaders/github.py b/libs/langchain/langchain/document_loaders/github.py index 5f33dec51a1e3..01eb3a0e3d5a3 100644 --- a/libs/langchain/langchain/document_loaders/github.py +++ b/libs/langchain/langchain/document_loaders/github.py @@ -4,10 +4,10 @@ import requests from langchain_core.pydantic_v1 import BaseModel, root_validator, validator -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader +from langchain.utils import get_from_dict_or_env class BaseGitHubLoader(BaseLoader, BaseModel, ABC): diff --git a/libs/langchain/langchain/document_loaders/joplin.py b/libs/langchain/langchain/document_loaders/joplin.py index f6bcac6b1213a..3f16d25c928b4 100644 --- a/libs/langchain/langchain/document_loaders/joplin.py +++ b/libs/langchain/langchain/document_loaders/joplin.py @@ -4,9 +4,9 @@ from typing import Iterator, List, Optional from langchain_core.schema import Document -from langchain_core.utils import get_from_env from langchain.document_loaders.base import BaseLoader +from langchain.utils import get_from_env LINK_NOTE_TEMPLATE = "joplin://x-callback-url/openNote?id={id}" diff --git a/libs/langchain/langchain/document_loaders/modern_treasury.py b/libs/langchain/langchain/document_loaders/modern_treasury.py index 6c3632668e780..21607ba1c89eb 100644 --- a/libs/langchain/langchain/document_loaders/modern_treasury.py +++ b/libs/langchain/langchain/document_loaders/modern_treasury.py @@ -3,10 +3,9 @@ from base64 import b64encode from typing import List, Optional -from langchain_core.utils import get_from_env, stringify_value - from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader +from langchain.utils import get_from_env, stringify_value MODERN_TREASURY_ENDPOINTS = { "payment_orders": "https://app.moderntreasury.com/api/payment_orders", diff --git a/libs/langchain/langchain/document_loaders/pdf.py b/libs/langchain/langchain/document_loaders/pdf.py index 355e89ed11492..ff250370649fd 100644 --- a/libs/langchain/langchain/document_loaders/pdf.py +++ b/libs/langchain/langchain/document_loaders/pdf.py @@ -10,7 +10,6 @@ from urllib.parse import urlparse import requests -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader @@ -25,6 +24,7 @@ PyPDFParser, ) from langchain.document_loaders.unstructured import UnstructuredFileLoader +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__file__) diff --git a/libs/langchain/langchain/document_loaders/rspace.py b/libs/langchain/langchain/document_loaders/rspace.py index b92c0362dff19..4921cb34e65e1 100644 --- a/libs/langchain/langchain/document_loaders/rspace.py +++ b/libs/langchain/langchain/document_loaders/rspace.py @@ -1,11 +1,10 @@ import os from typing import Any, Dict, Iterator, List, Optional, Union -from langchain_core.utils import get_from_dict_or_env - from langchain.docstore.document import Document from langchain.document_loaders import PyPDFLoader from langchain.document_loaders.base import BaseLoader +from langchain.utils import get_from_dict_or_env class RSpaceLoader(BaseLoader): diff --git a/libs/langchain/langchain/document_loaders/spreedly.py b/libs/langchain/langchain/document_loaders/spreedly.py index c488287992452..e95518d106a14 100644 --- a/libs/langchain/langchain/document_loaders/spreedly.py +++ b/libs/langchain/langchain/document_loaders/spreedly.py @@ -2,10 +2,9 @@ import urllib.request from typing import List -from langchain_core.utils import stringify_dict - from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader +from langchain.utils import stringify_dict SPREEDLY_ENDPOINTS = { "gateways_options": "https://core.spreedly.com/v1/gateways_options.json", diff --git a/libs/langchain/langchain/document_loaders/stripe.py b/libs/langchain/langchain/document_loaders/stripe.py index 2a7f0d6d0cb95..95ea8615e9d4d 100644 --- a/libs/langchain/langchain/document_loaders/stripe.py +++ b/libs/langchain/langchain/document_loaders/stripe.py @@ -2,10 +2,9 @@ import urllib.request from typing import List, Optional -from langchain_core.utils import get_from_env, stringify_dict - from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader +from langchain.utils import get_from_env, stringify_dict STRIPE_ENDPOINTS = { "balance_transactions": "https://api.stripe.com/v1/balance_transactions", diff --git a/libs/langchain/langchain/document_loaders/trello.py b/libs/langchain/langchain/document_loaders/trello.py index 3fe57f5deda18..f199a68295ded 100644 --- a/libs/langchain/langchain/document_loaders/trello.py +++ b/libs/langchain/langchain/document_loaders/trello.py @@ -2,10 +2,9 @@ from typing import TYPE_CHECKING, Any, List, Literal, Optional, Tuple -from langchain_core.utils import get_from_env - from langchain.docstore.document import Document from langchain.document_loaders.base import BaseLoader +from langchain.utils import get_from_env if TYPE_CHECKING: from trello import Board, Card, TrelloClient diff --git a/libs/langchain/langchain/document_transformers/doctran_text_extract.py b/libs/langchain/langchain/document_transformers/doctran_text_extract.py index 42b8c7d4e8097..7a951dc5abe06 100644 --- a/libs/langchain/langchain/document_transformers/doctran_text_extract.py +++ b/libs/langchain/langchain/document_transformers/doctran_text_extract.py @@ -1,7 +1,8 @@ from typing import Any, List, Optional, Sequence from langchain_core.schema import BaseDocumentTransformer, Document -from langchain_core.utils import get_from_env + +from langchain.utils import get_from_env class DoctranPropertyExtractor(BaseDocumentTransformer): diff --git a/libs/langchain/langchain/document_transformers/doctran_text_qa.py b/libs/langchain/langchain/document_transformers/doctran_text_qa.py index 4405120a78d5a..463d7a93c49bf 100644 --- a/libs/langchain/langchain/document_transformers/doctran_text_qa.py +++ b/libs/langchain/langchain/document_transformers/doctran_text_qa.py @@ -1,7 +1,8 @@ from typing import Any, Optional, Sequence from langchain_core.schema import BaseDocumentTransformer, Document -from langchain_core.utils import get_from_env + +from langchain.utils import get_from_env class DoctranQATransformer(BaseDocumentTransformer): diff --git a/libs/langchain/langchain/document_transformers/doctran_text_translate.py b/libs/langchain/langchain/document_transformers/doctran_text_translate.py index 65a9d895ac079..0b685b311e976 100644 --- a/libs/langchain/langchain/document_transformers/doctran_text_translate.py +++ b/libs/langchain/langchain/document_transformers/doctran_text_translate.py @@ -1,7 +1,8 @@ from typing import Any, Optional, Sequence from langchain_core.schema import BaseDocumentTransformer, Document -from langchain_core.utils import get_from_env + +from langchain.utils import get_from_env class DoctranTextTranslator(BaseDocumentTransformer): diff --git a/libs/langchain/langchain/embeddings/aleph_alpha.py b/libs/langchain/langchain/embeddings/aleph_alpha.py index 5ec86bce38fee..a28a49c38e636 100644 --- a/libs/langchain/langchain/embeddings/aleph_alpha.py +++ b/libs/langchain/langchain/embeddings/aleph_alpha.py @@ -2,7 +2,8 @@ from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class AlephAlphaAsymmetricSemanticEmbedding(BaseModel, Embeddings): diff --git a/libs/langchain/langchain/embeddings/azure_openai.py b/libs/langchain/langchain/embeddings/azure_openai.py index 82391cbb9d3ee..199898730ef69 100644 --- a/libs/langchain/langchain/embeddings/azure_openai.py +++ b/libs/langchain/langchain/embeddings/azure_openai.py @@ -6,10 +6,10 @@ from typing import Dict, Optional, Union from langchain_core.pydantic_v1 import Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain_core.utils.openai import is_openai_v1 from langchain.embeddings.openai import OpenAIEmbeddings +from langchain.utils import get_from_dict_or_env class AzureOpenAIEmbeddings(OpenAIEmbeddings): diff --git a/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py b/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py index a7b4897022960..d440cd497a265 100644 --- a/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py +++ b/libs/langchain/langchain/embeddings/baidu_qianfan_endpoint.py @@ -5,7 +5,8 @@ from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/clarifai.py b/libs/langchain/langchain/embeddings/clarifai.py index 57865a6b0e5e7..9a3ccac7a2658 100644 --- a/libs/langchain/langchain/embeddings/clarifai.py +++ b/libs/langchain/langchain/embeddings/clarifai.py @@ -3,7 +3,8 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/cohere.py b/libs/langchain/langchain/embeddings/cohere.py index 58164efe25b8d..dd7b74b5cdb9b 100644 --- a/libs/langchain/langchain/embeddings/cohere.py +++ b/libs/langchain/langchain/embeddings/cohere.py @@ -2,7 +2,8 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class CohereEmbeddings(BaseModel, Embeddings): diff --git a/libs/langchain/langchain/embeddings/dashscope.py b/libs/langchain/langchain/embeddings/dashscope.py index 977927fa6254e..60a64fc57cd97 100644 --- a/libs/langchain/langchain/embeddings/dashscope.py +++ b/libs/langchain/langchain/embeddings/dashscope.py @@ -11,7 +11,6 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env from requests.exceptions import HTTPError from tenacity import ( before_sleep_log, @@ -21,6 +20,8 @@ wait_exponential, ) +from langchain.utils import get_from_dict_or_env + logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/deepinfra.py b/libs/langchain/langchain/embeddings/deepinfra.py index b8221da86f79c..20d57e5129633 100644 --- a/libs/langchain/langchain/embeddings/deepinfra.py +++ b/libs/langchain/langchain/embeddings/deepinfra.py @@ -3,7 +3,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env DEFAULT_MODEL_ID = "sentence-transformers/clip-ViT-B-32" diff --git a/libs/langchain/langchain/embeddings/edenai.py b/libs/langchain/langchain/embeddings/edenai.py index 39522277da8fd..da5869e0480b0 100644 --- a/libs/langchain/langchain/embeddings/edenai.py +++ b/libs/langchain/langchain/embeddings/edenai.py @@ -2,9 +2,9 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env from langchain.utilities.requests import Requests +from langchain.utils import get_from_dict_or_env class EdenAiEmbeddings(BaseModel, Embeddings): diff --git a/libs/langchain/langchain/embeddings/elasticsearch.py b/libs/langchain/langchain/embeddings/elasticsearch.py index 33ae9b95e6004..fb0db428597fc 100644 --- a/libs/langchain/langchain/embeddings/elasticsearch.py +++ b/libs/langchain/langchain/embeddings/elasticsearch.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, List, Optional -from langchain_core.utils import get_from_env +from langchain.utils import get_from_env if TYPE_CHECKING: from elasticsearch import Elasticsearch diff --git a/libs/langchain/langchain/embeddings/embaas.py b/libs/langchain/langchain/embeddings/embaas.py index cbc824521f2e4..3f054764fa11e 100644 --- a/libs/langchain/langchain/embeddings/embaas.py +++ b/libs/langchain/langchain/embeddings/embaas.py @@ -3,9 +3,10 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env from typing_extensions import NotRequired, TypedDict +from langchain.utils import get_from_dict_or_env + # Currently supported maximum batch size for embedding requests MAX_BATCH_SIZE = 256 EMBAAS_API_URL = "https://api.embaas.io/v1/embeddings/" diff --git a/libs/langchain/langchain/embeddings/ernie.py b/libs/langchain/langchain/embeddings/ernie.py index 495ef6a368f0a..9c147b00b4db8 100644 --- a/libs/langchain/langchain/embeddings/ernie.py +++ b/libs/langchain/langchain/embeddings/ernie.py @@ -7,7 +7,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/google_palm.py b/libs/langchain/langchain/embeddings/google_palm.py index 9fc0c20d405fb..afb38763a8e74 100644 --- a/libs/langchain/langchain/embeddings/google_palm.py +++ b/libs/langchain/langchain/embeddings/google_palm.py @@ -5,7 +5,6 @@ from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env from tenacity import ( before_sleep_log, retry, @@ -14,6 +13,8 @@ wait_exponential, ) +from langchain.utils import get_from_dict_or_env + logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/gradient_ai.py b/libs/langchain/langchain/embeddings/gradient_ai.py index 3bd5261d7e8a0..290b0d1219e27 100644 --- a/libs/langchain/langchain/embeddings/gradient_ai.py +++ b/libs/langchain/langchain/embeddings/gradient_ai.py @@ -9,7 +9,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env __all__ = ["GradientEmbeddings"] diff --git a/libs/langchain/langchain/embeddings/huggingface_hub.py b/libs/langchain/langchain/embeddings/huggingface_hub.py index 3162bcbceaac5..2c14614eea797 100644 --- a/libs/langchain/langchain/embeddings/huggingface_hub.py +++ b/libs/langchain/langchain/embeddings/huggingface_hub.py @@ -2,7 +2,8 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env DEFAULT_REPO_ID = "sentence-transformers/all-mpnet-base-v2" VALID_TASKS = ("feature-extraction",) diff --git a/libs/langchain/langchain/embeddings/jina.py b/libs/langchain/langchain/embeddings/jina.py index 60f1aedd658a1..c94728cb4f5da 100644 --- a/libs/langchain/langchain/embeddings/jina.py +++ b/libs/langchain/langchain/embeddings/jina.py @@ -4,7 +4,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class JinaEmbeddings(BaseModel, Embeddings): diff --git a/libs/langchain/langchain/embeddings/localai.py b/libs/langchain/langchain/embeddings/localai.py index 95c7653e082af..0f0e9ac1c929e 100644 --- a/libs/langchain/langchain/embeddings/localai.py +++ b/libs/langchain/langchain/embeddings/localai.py @@ -17,7 +17,7 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env, get_pydantic_field_names +from langchain_core.utils import get_pydantic_field_names from tenacity import ( AsyncRetrying, before_sleep_log, @@ -27,6 +27,8 @@ wait_exponential, ) +from langchain.utils import get_from_dict_or_env + logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/minimax.py b/libs/langchain/langchain/embeddings/minimax.py index ece194006839c..3bc2840cf136d 100644 --- a/libs/langchain/langchain/embeddings/minimax.py +++ b/libs/langchain/langchain/embeddings/minimax.py @@ -6,7 +6,6 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env from tenacity import ( before_sleep_log, retry, @@ -14,6 +13,8 @@ wait_exponential, ) +from langchain.utils import get_from_dict_or_env + logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/mosaicml.py b/libs/langchain/langchain/embeddings/mosaicml.py index 9c4182559bda2..72f8c341d1c91 100644 --- a/libs/langchain/langchain/embeddings/mosaicml.py +++ b/libs/langchain/langchain/embeddings/mosaicml.py @@ -3,7 +3,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class MosaicMLInstructorEmbeddings(BaseModel, Embeddings): diff --git a/libs/langchain/langchain/embeddings/nlpcloud.py b/libs/langchain/langchain/embeddings/nlpcloud.py index 0afb29fc811e7..38b44f7975e41 100644 --- a/libs/langchain/langchain/embeddings/nlpcloud.py +++ b/libs/langchain/langchain/embeddings/nlpcloud.py @@ -2,7 +2,8 @@ from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class NLPCloudEmbeddings(BaseModel, Embeddings): diff --git a/libs/langchain/langchain/embeddings/octoai_embeddings.py b/libs/langchain/langchain/embeddings/octoai_embeddings.py index fb34d34c0eda4..286173054fbad 100644 --- a/libs/langchain/langchain/embeddings/octoai_embeddings.py +++ b/libs/langchain/langchain/embeddings/octoai_embeddings.py @@ -2,7 +2,8 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env DEFAULT_EMBED_INSTRUCTION = "Represent this input: " DEFAULT_QUERY_INSTRUCTION = "Represent the question for retrieving similar documents: " diff --git a/libs/langchain/langchain/embeddings/openai.py b/libs/langchain/langchain/embeddings/openai.py index 1ab710171172e..60d55b1c1880f 100644 --- a/libs/langchain/langchain/embeddings/openai.py +++ b/libs/langchain/langchain/embeddings/openai.py @@ -22,7 +22,7 @@ import numpy as np from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import get_from_dict_or_env, get_pydantic_field_names +from langchain_core.utils import get_pydantic_field_names from packaging.version import Version, parse from tenacity import ( AsyncRetrying, @@ -33,6 +33,8 @@ wait_exponential, ) +from langchain.utils import get_from_dict_or_env + logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/embeddings/voyageai.py b/libs/langchain/langchain/embeddings/voyageai.py index a843d94df61ee..3f07a67bd30ad 100644 --- a/libs/langchain/langchain/embeddings/voyageai.py +++ b/libs/langchain/langchain/embeddings/voyageai.py @@ -16,7 +16,7 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, SecretStr, root_validator from langchain_core.schema.embeddings import Embeddings -from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env +from langchain_core.utils import convert_to_secret_str from tenacity import ( before_sleep_log, retry, @@ -24,6 +24,8 @@ wait_exponential, ) +from langchain.utils import get_from_dict_or_env + logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/graphs/neo4j_graph.py b/libs/langchain/langchain/graphs/neo4j_graph.py index be4d85d31527f..dfbf38bb98392 100644 --- a/libs/langchain/langchain/graphs/neo4j_graph.py +++ b/libs/langchain/langchain/graphs/neo4j_graph.py @@ -1,9 +1,8 @@ from typing import Any, Dict, List, Optional -from langchain_core.utils import get_from_env - from langchain.graphs.graph_document import GraphDocument from langchain.graphs.graph_store import GraphStore +from langchain.utils import get_from_env node_properties_query = """ CALL apoc.meta.data() diff --git a/libs/langchain/langchain/llms/ai21.py b/libs/langchain/langchain/llms/ai21.py index 34e600f7eae97..616c8a3649563 100644 --- a/libs/langchain/langchain/llms/ai21.py +++ b/libs/langchain/langchain/llms/ai21.py @@ -2,10 +2,11 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, 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 from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env class AI21PenaltyData(BaseModel): diff --git a/libs/langchain/langchain/llms/aleph_alpha.py b/libs/langchain/langchain/llms/aleph_alpha.py index 9a57ddb28362b..2ed1de4362202 100644 --- a/libs/langchain/langchain/llms/aleph_alpha.py +++ b/libs/langchain/langchain/llms/aleph_alpha.py @@ -1,11 +1,12 @@ from typing import Any, Dict, List, Optional, Sequence from langchain_core.pydantic_v1 import Extra, 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 from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env class AlephAlpha(LLM): diff --git a/libs/langchain/langchain/llms/anthropic.py b/libs/langchain/langchain/llms/anthropic.py index 31cbb31c1dd36..b93edd2647618 100644 --- a/libs/langchain/langchain/llms/anthropic.py +++ b/libs/langchain/langchain/llms/anthropic.py @@ -17,7 +17,6 @@ from langchain_core.schema.prompt import PromptValue from langchain_core.utils import ( check_package_version, - get_from_dict_or_env, get_pydantic_field_names, ) from langchain_core.utils.utils import build_extra_kwargs, convert_to_secret_str @@ -27,6 +26,7 @@ CallbackManagerForLLMRun, ) from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env class _AnthropicCommon(BaseLanguageModel): diff --git a/libs/langchain/langchain/llms/anyscale.py b/libs/langchain/langchain/llms/anyscale.py index 3a33f4eb14e2e..2ffeab409877e 100644 --- a/libs/langchain/langchain/llms/anyscale.py +++ b/libs/langchain/langchain/llms/anyscale.py @@ -15,7 +15,7 @@ from langchain_core.pydantic_v1 import Field, SecretStr, root_validator from langchain_core.schema import Generation, LLMResult from langchain_core.schema.output import GenerationChunk -from langchain_core.utils import convert_to_secret_str, get_from_dict_or_env +from langchain_core.utils import convert_to_secret_str from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -26,6 +26,7 @@ acompletion_with_retry, completion_with_retry, ) +from langchain.utils import get_from_dict_or_env def update_token_usage( diff --git a/libs/langchain/langchain/llms/arcee.py b/libs/langchain/langchain/llms/arcee.py index 90307aa38f632..72028097c2a05 100644 --- a/libs/langchain/langchain/llms/arcee.py +++ b/libs/langchain/langchain/llms/arcee.py @@ -1,11 +1,11 @@ from typing import Any, Dict, List, Optional from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.utilities.arcee import ArceeWrapper, DALMFilter +from langchain.utils import get_from_dict_or_env class Arcee(LLM): diff --git a/libs/langchain/langchain/llms/aviary.py b/libs/langchain/langchain/llms/aviary.py index 216c110c0c1a0..5eb4b4a53b132 100644 --- a/libs/langchain/langchain/llms/aviary.py +++ b/libs/langchain/langchain/llms/aviary.py @@ -4,11 +4,11 @@ import requests from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env TIMEOUT = 60 diff --git a/libs/langchain/langchain/llms/azureml_endpoint.py b/libs/langchain/langchain/llms/azureml_endpoint.py index 7e6337f046eab..a8e82cbdbce21 100644 --- a/libs/langchain/langchain/llms/azureml_endpoint.py +++ b/libs/langchain/langchain/llms/azureml_endpoint.py @@ -5,10 +5,10 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import BaseModel, validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env class AzureMLEndpointClient(object): diff --git a/libs/langchain/langchain/llms/baidu_qianfan_endpoint.py b/libs/langchain/langchain/llms/baidu_qianfan_endpoint.py index 7c05e14064f48..69f5538739d46 100644 --- a/libs/langchain/langchain/llms/baidu_qianfan_endpoint.py +++ b/libs/langchain/langchain/llms/baidu_qianfan_endpoint.py @@ -12,13 +12,13 @@ from langchain_core.pydantic_v1 import Field, root_validator from langchain_core.schema.output import GenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun, ) from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/bananadev.py b/libs/langchain/langchain/llms/bananadev.py index 934cd155b9c05..6c1aec0850083 100644 --- a/libs/langchain/langchain/llms/bananadev.py +++ b/libs/langchain/langchain/llms/bananadev.py @@ -2,11 +2,11 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/beam.py b/libs/langchain/langchain/llms/beam.py index c8a1123b9a3f1..7f661f5c2376c 100644 --- a/libs/langchain/langchain/llms/beam.py +++ b/libs/langchain/langchain/llms/beam.py @@ -8,10 +8,10 @@ import requests from langchain_core.pydantic_v1 import Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/bedrock.py b/libs/langchain/langchain/llms/bedrock.py index a7f251d813b36..7a1dd1b0a09a3 100644 --- a/libs/langchain/langchain/llms/bedrock.py +++ b/libs/langchain/langchain/llms/bedrock.py @@ -5,7 +5,6 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator from langchain_core.schema.output import GenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM @@ -14,6 +13,7 @@ get_num_tokens_anthropic, get_token_ids_anthropic, ) +from langchain.utils import get_from_dict_or_env HUMAN_PROMPT = "\n\nHuman:" ASSISTANT_PROMPT = "\n\nAssistant:" diff --git a/libs/langchain/langchain/llms/cerebriumai.py b/libs/langchain/langchain/llms/cerebriumai.py index 925fe74a6aef8..00fe2c1683f16 100644 --- a/libs/langchain/langchain/llms/cerebriumai.py +++ b/libs/langchain/langchain/llms/cerebriumai.py @@ -2,11 +2,11 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/clarifai.py b/libs/langchain/langchain/llms/clarifai.py index 596887d92e530..6da1851a70349 100644 --- a/libs/langchain/langchain/llms/clarifai.py +++ b/libs/langchain/langchain/llms/clarifai.py @@ -3,11 +3,11 @@ from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.schema import Generation, LLMResult -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/cohere.py b/libs/langchain/langchain/llms/cohere.py index 0f6aa47ec1325..754cfac28266f 100644 --- a/libs/langchain/langchain/llms/cohere.py +++ b/libs/langchain/langchain/llms/cohere.py @@ -5,7 +5,6 @@ from langchain_core.load.serializable import Serializable from langchain_core.pydantic_v1 import Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from tenacity import ( before_sleep_log, retry, @@ -20,6 +19,7 @@ ) from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/deepinfra.py b/libs/langchain/langchain/llms/deepinfra.py index d2e4479aebd71..44a8aab957c83 100644 --- a/libs/langchain/langchain/llms/deepinfra.py +++ b/libs/langchain/langchain/llms/deepinfra.py @@ -3,7 +3,6 @@ import aiohttp from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -12,6 +11,7 @@ from langchain.llms.base import LLM from langchain.schema.output import GenerationChunk from langchain.utilities.requests import Requests +from langchain.utils import get_from_dict_or_env DEFAULT_MODEL_ID = "google/flan-t5-xl" diff --git a/libs/langchain/langchain/llms/edenai.py b/libs/langchain/langchain/llms/edenai.py index 912dd3071d366..832151efa1e01 100644 --- a/libs/langchain/langchain/llms/edenai.py +++ b/libs/langchain/langchain/llms/edenai.py @@ -4,7 +4,6 @@ from aiohttp import ClientSession from langchain_core.pydantic_v1 import Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -13,6 +12,7 @@ from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens from langchain.utilities.requests import Requests +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/forefrontai.py b/libs/langchain/langchain/llms/forefrontai.py index 5a6a56dfce7c0..3664144be26d9 100644 --- a/libs/langchain/langchain/llms/forefrontai.py +++ b/libs/langchain/langchain/llms/forefrontai.py @@ -2,11 +2,11 @@ import requests from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env class ForefrontAI(LLM): diff --git a/libs/langchain/langchain/llms/google_palm.py b/libs/langchain/langchain/llms/google_palm.py index c648c5ede30e7..f3aadc3a0d33c 100644 --- a/libs/langchain/langchain/llms/google_palm.py +++ b/libs/langchain/langchain/llms/google_palm.py @@ -5,7 +5,6 @@ from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema import Generation, LLMResult -from langchain_core.utils import get_from_dict_or_env from tenacity import ( before_sleep_log, retry, @@ -16,6 +15,7 @@ from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms import BaseLLM +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/gooseai.py b/libs/langchain/langchain/llms/gooseai.py index bab0ea0068cf2..db08a360a91e6 100644 --- a/libs/langchain/langchain/llms/gooseai.py +++ b/libs/langchain/langchain/llms/gooseai.py @@ -2,10 +2,11 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import Extra, 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 from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/gradient_ai.py b/libs/langchain/langchain/llms/gradient_ai.py index aea09473a213a..3ee979aee3559 100644 --- a/libs/langchain/langchain/llms/gradient_ai.py +++ b/libs/langchain/langchain/llms/gradient_ai.py @@ -7,7 +7,6 @@ import requests from langchain_core.pydantic_v1 import Extra, Field, root_validator from langchain_core.schema import Generation, LLMResult -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -15,6 +14,7 @@ ) from langchain.llms.base import BaseLLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env class TrainResult(TypedDict): diff --git a/libs/langchain/langchain/llms/huggingface_endpoint.py b/libs/langchain/langchain/llms/huggingface_endpoint.py index 73c588d82a954..50c3f00807662 100644 --- a/libs/langchain/langchain/llms/huggingface_endpoint.py +++ b/libs/langchain/langchain/llms/huggingface_endpoint.py @@ -2,11 +2,11 @@ import requests from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env VALID_TASKS = ("text2text-generation", "text-generation", "summarization") diff --git a/libs/langchain/langchain/llms/huggingface_hub.py b/libs/langchain/langchain/llms/huggingface_hub.py index e935adb39ef71..4bda8a6cb9a4a 100644 --- a/libs/langchain/langchain/llms/huggingface_hub.py +++ b/libs/langchain/langchain/llms/huggingface_hub.py @@ -1,11 +1,11 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env DEFAULT_REPO_ID = "gpt2" VALID_TASKS = ("text2text-generation", "text-generation", "summarization") diff --git a/libs/langchain/langchain/llms/minimax.py b/libs/langchain/langchain/llms/minimax.py index e2abd455be35d..488f296d5a864 100644 --- a/libs/langchain/langchain/llms/minimax.py +++ b/libs/langchain/langchain/llms/minimax.py @@ -11,13 +11,13 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( CallbackManagerForLLMRun, ) from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/mosaicml.py b/libs/langchain/langchain/llms/mosaicml.py index 08fcb7a81008a..92a5d6d79ed84 100644 --- a/libs/langchain/langchain/llms/mosaicml.py +++ b/libs/langchain/langchain/llms/mosaicml.py @@ -2,11 +2,11 @@ import requests from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env INSTRUCTION_KEY = "### Instruction:" RESPONSE_KEY = "### Response:" diff --git a/libs/langchain/langchain/llms/nlpcloud.py b/libs/langchain/langchain/llms/nlpcloud.py index a5c77e1de07c2..c359284bd1937 100644 --- a/libs/langchain/langchain/llms/nlpcloud.py +++ b/libs/langchain/langchain/llms/nlpcloud.py @@ -1,10 +1,10 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env class NLPCloud(LLM): diff --git a/libs/langchain/langchain/llms/octoai_endpoint.py b/libs/langchain/langchain/llms/octoai_endpoint.py index 78250fb01f839..d563b1faa72db 100644 --- a/libs/langchain/langchain/llms/octoai_endpoint.py +++ b/libs/langchain/langchain/llms/octoai_endpoint.py @@ -1,11 +1,11 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env class OctoAIEndpoint(LLM): diff --git a/libs/langchain/langchain/llms/opaqueprompts.py b/libs/langchain/langchain/llms/opaqueprompts.py index 154a3bb700d77..9a58819045409 100644 --- a/libs/langchain/langchain/llms/opaqueprompts.py +++ b/libs/langchain/langchain/llms/opaqueprompts.py @@ -3,10 +3,10 @@ from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.schema.language_model import BaseLanguageModel -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/openai.py b/libs/langchain/langchain/llms/openai.py index c1c345b1cea9a..d312bbfe0f945 100644 --- a/libs/langchain/langchain/llms/openai.py +++ b/libs/langchain/langchain/llms/openai.py @@ -24,7 +24,7 @@ from langchain_core.pydantic_v1 import Field, root_validator from langchain_core.schema import Generation, LLMResult from langchain_core.schema.output import GenerationChunk -from langchain_core.utils import get_from_dict_or_env, get_pydantic_field_names +from langchain_core.utils import get_pydantic_field_names from langchain_core.utils.openai import is_openai_v1 from langchain_core.utils.utils import build_extra_kwargs @@ -33,6 +33,7 @@ CallbackManagerForLLMRun, ) from langchain.llms.base import BaseLLM, create_base_retry_decorator +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/pai_eas_endpoint.py b/libs/langchain/langchain/llms/pai_eas_endpoint.py index 857ccf8c62469..4e4bd7cde03bf 100644 --- a/libs/langchain/langchain/llms/pai_eas_endpoint.py +++ b/libs/langchain/langchain/llms/pai_eas_endpoint.py @@ -5,11 +5,11 @@ import requests from langchain_core.pydantic_v1 import root_validator from langchain_core.schema.output import GenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/petals.py b/libs/langchain/langchain/llms/petals.py index 9b9079071541b..ecd8df336e79b 100644 --- a/libs/langchain/langchain/llms/petals.py +++ b/libs/langchain/langchain/llms/petals.py @@ -2,11 +2,11 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/pipelineai.py b/libs/langchain/langchain/llms/pipelineai.py index 30c76c410cb80..8572c86f4e6f1 100644 --- a/libs/langchain/langchain/llms/pipelineai.py +++ b/libs/langchain/langchain/llms/pipelineai.py @@ -2,11 +2,11 @@ from typing import Any, Dict, List, Mapping, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/predictionguard.py b/libs/langchain/langchain/llms/predictionguard.py index c98ee96f751ee..850bcb763d57f 100644 --- a/libs/langchain/langchain/llms/predictionguard.py +++ b/libs/langchain/langchain/llms/predictionguard.py @@ -2,11 +2,11 @@ from typing import Any, Dict, List, Optional from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/replicate.py b/libs/langchain/langchain/llms/replicate.py index 40f7c073b3bc4..34e60851ed741 100644 --- a/libs/langchain/langchain/llms/replicate.py +++ b/libs/langchain/langchain/llms/replicate.py @@ -5,10 +5,10 @@ from langchain_core.pydantic_v1 import Extra, Field, root_validator from langchain_core.schema.output import GenerationChunk -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from replicate.prediction import Prediction diff --git a/libs/langchain/langchain/llms/stochasticai.py b/libs/langchain/langchain/llms/stochasticai.py index 9fa0b821e34c9..0737a1e71d81d 100644 --- a/libs/langchain/langchain/llms/stochasticai.py +++ b/libs/langchain/langchain/llms/stochasticai.py @@ -4,11 +4,11 @@ import requests from langchain_core.pydantic_v1 import Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/symblai_nebula.py b/libs/langchain/langchain/llms/symblai_nebula.py index 76d6b50dc6a36..ddf238c7af909 100644 --- a/libs/langchain/langchain/llms/symblai_nebula.py +++ b/libs/langchain/langchain/llms/symblai_nebula.py @@ -5,7 +5,6 @@ import requests from langchain_core.pydantic_v1 import Extra, SecretStr, root_validator from langchain_core.utils import convert_to_secret_str -from langchain_core.utils.env import get_from_dict_or_env from requests import ConnectTimeout, ReadTimeout, RequestException from tenacity import ( before_sleep_log, @@ -18,6 +17,7 @@ from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env DEFAULT_NEBULA_SERVICE_URL = "https://api-nebula.symbl.ai" DEFAULT_NEBULA_SERVICE_PATH = "/v1/model/generate" diff --git a/libs/langchain/langchain/llms/together.py b/libs/langchain/langchain/llms/together.py index 3cc0f47d2ea97..46ada2e9d3016 100644 --- a/libs/langchain/langchain/llms/together.py +++ b/libs/langchain/langchain/llms/together.py @@ -4,7 +4,6 @@ from aiohttp import ClientSession from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -12,6 +11,7 @@ ) from langchain.llms.base import LLM from langchain.utilities.requests import Requests +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/tongyi.py b/libs/langchain/langchain/llms/tongyi.py index ca8d08622b554..bd5e3df5e53f4 100644 --- a/libs/langchain/langchain/llms/tongyi.py +++ b/libs/langchain/langchain/llms/tongyi.py @@ -5,7 +5,6 @@ from langchain_core.pydantic_v1 import Field, root_validator from langchain_core.schema import Generation, LLMResult -from langchain_core.utils import get_from_dict_or_env from requests.exceptions import HTTPError from tenacity import ( before_sleep_log, @@ -17,6 +16,7 @@ from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/llms/writer.py b/libs/langchain/langchain/llms/writer.py index 962ea4f4ecbde..45b56e389d21b 100644 --- a/libs/langchain/langchain/llms/writer.py +++ b/libs/langchain/langchain/llms/writer.py @@ -2,11 +2,11 @@ import requests from langchain_core.pydantic_v1 import Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForLLMRun from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env class Writer(LLM): diff --git a/libs/langchain/langchain/llms/yandex.py b/libs/langchain/langchain/llms/yandex.py index a0268e1346fa6..c28c89a08348c 100644 --- a/libs/langchain/langchain/llms/yandex.py +++ b/libs/langchain/langchain/llms/yandex.py @@ -2,7 +2,6 @@ from langchain_core.load.serializable import Serializable from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForLLMRun, @@ -10,6 +9,7 @@ ) from langchain.llms.base import LLM from langchain.llms.utils import enforce_stop_tokens +from langchain.utils import get_from_dict_or_env class _BaseYandexGPT(Serializable): diff --git a/libs/langchain/langchain/memory/chat_message_histories/momento.py b/libs/langchain/langchain/memory/chat_message_histories/momento.py index 0a7986582c879..c2d70b88b6ad5 100644 --- a/libs/langchain/langchain/memory/chat_message_histories/momento.py +++ b/libs/langchain/langchain/memory/chat_message_histories/momento.py @@ -12,7 +12,8 @@ _message_to_dict, messages_from_dict, ) -from langchain_core.utils import get_from_env + +from langchain.utils import get_from_env if TYPE_CHECKING: import momento diff --git a/libs/langchain/langchain/memory/chat_message_histories/neo4j.py b/libs/langchain/langchain/memory/chat_message_histories/neo4j.py index a942ae8114bb1..b198ab05b2467 100644 --- a/libs/langchain/langchain/memory/chat_message_histories/neo4j.py +++ b/libs/langchain/langchain/memory/chat_message_histories/neo4j.py @@ -2,7 +2,8 @@ from langchain_core.schema import BaseChatMessageHistory from langchain_core.schema.messages import BaseMessage, messages_from_dict -from langchain_core.utils import get_from_env + +from langchain.utils import get_from_env class Neo4jChatMessageHistory(BaseChatMessageHistory): diff --git a/libs/langchain/langchain/output_parsers/datetime.py b/libs/langchain/langchain/output_parsers/datetime.py index 537dfcd83fe61..5113bb07efcdd 100644 --- a/libs/langchain/langchain/output_parsers/datetime.py +++ b/libs/langchain/langchain/output_parsers/datetime.py @@ -3,7 +3,8 @@ from typing import List from langchain_core.schema import BaseOutputParser, OutputParserException -from langchain_core.utils import comma_list + +from langchain.utils import comma_list def _generate_random_datetime_strings( diff --git a/libs/langchain/langchain/retrievers/arcee.py b/libs/langchain/langchain/retrievers/arcee.py index 4f5f271308bff..a3bd2883e3449 100644 --- a/libs/langchain/langchain/retrievers/arcee.py +++ b/libs/langchain/langchain/retrievers/arcee.py @@ -2,11 +2,11 @@ from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.schema import BaseRetriever -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.docstore.document import Document from langchain.utilities.arcee import ArceeWrapper, DALMFilter +from langchain.utils import get_from_dict_or_env class ArceeRetriever(BaseRetriever): diff --git a/libs/langchain/langchain/retrievers/azure_cognitive_search.py b/libs/langchain/langchain/retrievers/azure_cognitive_search.py index 0138f165ba9ab..4a75291a66bb6 100644 --- a/libs/langchain/langchain/retrievers/azure_cognitive_search.py +++ b/libs/langchain/langchain/retrievers/azure_cognitive_search.py @@ -7,12 +7,12 @@ import requests from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.schema import BaseRetriever, Document -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, CallbackManagerForRetrieverRun, ) +from langchain.utils import get_from_dict_or_env class AzureCognitiveSearchRetriever(BaseRetriever): diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index 60fc0395d9a62..313832534389d 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -4,10 +4,10 @@ from langchain_core.pydantic_v1 import Extra, root_validator from langchain_core.schema import Document -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import Callbacks from langchain.retrievers.document_compressors.base import BaseDocumentCompressor +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from cohere import Client diff --git a/libs/langchain/langchain/retrievers/google_cloud_documentai_warehouse.py b/libs/langchain/langchain/retrievers/google_cloud_documentai_warehouse.py index a0095972ec0ab..e7f5e65cbbde7 100644 --- a/libs/langchain/langchain/retrievers/google_cloud_documentai_warehouse.py +++ b/libs/langchain/langchain/retrievers/google_cloud_documentai_warehouse.py @@ -3,11 +3,11 @@ from langchain_core.pydantic_v1 import root_validator from langchain_core.schema import BaseRetriever -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.docstore.document import Document from langchain.utilities.vertexai import get_client_info +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from google.cloud.contentwarehouse_v1 import ( diff --git a/libs/langchain/langchain/retrievers/google_vertex_ai_search.py b/libs/langchain/langchain/retrievers/google_vertex_ai_search.py index da5bfe0932d84..786920b6625e2 100644 --- a/libs/langchain/langchain/retrievers/google_vertex_ai_search.py +++ b/libs/langchain/langchain/retrievers/google_vertex_ai_search.py @@ -5,10 +5,10 @@ from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator from langchain_core.schema import BaseRetriever, Document -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.utilities.vertexai import get_client_info +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from google.api_core.client_options import ClientOptions diff --git a/libs/langchain/langchain/retrievers/you.py b/libs/langchain/langchain/retrievers/you.py index 0080797ad4276..e0bb437e0f633 100644 --- a/libs/langchain/langchain/retrievers/you.py +++ b/libs/langchain/langchain/retrievers/you.py @@ -2,9 +2,9 @@ from langchain_core.pydantic_v1 import root_validator from langchain_core.schema import BaseRetriever, Document -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForRetrieverRun +from langchain.utils import get_from_dict_or_env class YouRetriever(BaseRetriever): diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py b/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py index 1532fe7a73cc1..6c00104e8977b 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/form_recognizer.py @@ -4,11 +4,11 @@ from typing import Any, Dict, List, Optional from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.azure_cognitive_services.utils import detect_file_src_type from langchain.tools.base import BaseTool +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py b/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py index 366eae379b952..efcab61ea2e53 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/image_analysis.py @@ -4,11 +4,11 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.azure_cognitive_services.utils import detect_file_src_type from langchain.tools.base import BaseTool +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py b/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py index d589f09dd9f70..ec37e4d897449 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/speech2text.py @@ -5,7 +5,6 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.azure_cognitive_services.utils import ( @@ -13,6 +12,7 @@ download_audio_from_url, ) from langchain.tools.base import BaseTool +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py b/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py index a344ea0b51c01..3ee671dbffc2c 100644 --- a/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py +++ b/libs/langchain/langchain/tools/azure_cognitive_services/text2speech.py @@ -5,10 +5,10 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/tools/edenai/edenai_base_tool.py b/libs/langchain/langchain/tools/edenai/edenai_base_tool.py index 8eabad2347f2f..eb4903d03b4fc 100644 --- a/libs/langchain/langchain/tools/edenai/edenai_base_tool.py +++ b/libs/langchain/langchain/tools/edenai/edenai_base_tool.py @@ -6,10 +6,10 @@ import requests from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/tools/eleven_labs/text2speech.py b/libs/langchain/langchain/tools/eleven_labs/text2speech.py index fec647f5f69b0..455ec0afc125d 100644 --- a/libs/langchain/langchain/tools/eleven_labs/text2speech.py +++ b/libs/langchain/langchain/tools/eleven_labs/text2speech.py @@ -3,10 +3,10 @@ from typing import Any, Dict, Optional, Union from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools.base import BaseTool +from langchain.utils import get_from_dict_or_env def _import_elevenlabs() -> Any: diff --git a/libs/langchain/langchain/tools/steamship_image_generation/tool.py b/libs/langchain/langchain/tools/steamship_image_generation/tool.py index 1ed89032b8867..0f25d2ee2a375 100644 --- a/libs/langchain/langchain/tools/steamship_image_generation/tool.py +++ b/libs/langchain/langchain/tools/steamship_image_generation/tool.py @@ -17,11 +17,11 @@ from typing import TYPE_CHECKING, Dict, Optional from langchain_core.pydantic_v1 import root_validator -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForToolRun from langchain.tools import BaseTool from langchain.tools.steamship_image_generation.utils import make_image_public +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from steamship import Steamship diff --git a/libs/langchain/langchain/utilities/alpha_vantage.py b/libs/langchain/langchain/utilities/alpha_vantage.py index db51abf96da92..31f8f12a465f7 100644 --- a/libs/langchain/langchain/utilities/alpha_vantage.py +++ b/libs/langchain/langchain/utilities/alpha_vantage.py @@ -3,7 +3,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class AlphaVantageAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/apify.py b/libs/langchain/langchain/utilities/apify.py index 505f20392b7e2..7a2d04680f898 100644 --- a/libs/langchain/langchain/utilities/apify.py +++ b/libs/langchain/langchain/utilities/apify.py @@ -2,7 +2,8 @@ from langchain_core.pydantic_v1 import BaseModel, root_validator from langchain_core.schema.document import Document -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from langchain.document_loaders import ApifyDatasetLoader diff --git a/libs/langchain/langchain/utilities/bing_search.py b/libs/langchain/langchain/utilities/bing_search.py index 8166f1dfa0c9c..2783118a5c4fc 100644 --- a/libs/langchain/langchain/utilities/bing_search.py +++ b/libs/langchain/langchain/utilities/bing_search.py @@ -7,7 +7,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class BingSearchAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/clickup.py b/libs/langchain/langchain/utilities/clickup.py index ed81e7fc72bee..375d47693c3ab 100644 --- a/libs/langchain/langchain/utilities/clickup.py +++ b/libs/langchain/langchain/utilities/clickup.py @@ -6,7 +6,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env DEFAULT_URL = "https://api.clickup.com/api/v2" diff --git a/libs/langchain/langchain/utilities/dalle_image_generator.py b/libs/langchain/langchain/utilities/dalle_image_generator.py index c5733eb4e7d87..cd8c98bd33ef7 100644 --- a/libs/langchain/langchain/utilities/dalle_image_generator.py +++ b/libs/langchain/langchain/utilities/dalle_image_generator.py @@ -2,7 +2,8 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class DallEAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/dataforseo_api_search.py b/libs/langchain/langchain/utilities/dataforseo_api_search.py index 16c90fc4ff6ea..cb29e5c3da11a 100644 --- a/libs/langchain/langchain/utilities/dataforseo_api_search.py +++ b/libs/langchain/langchain/utilities/dataforseo_api_search.py @@ -5,7 +5,8 @@ import aiohttp import requests from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class DataForSeoAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/github.py b/libs/langchain/langchain/utilities/github.py index 6e83a6107d8f0..234ec87b1e979 100644 --- a/libs/langchain/langchain/utilities/github.py +++ b/libs/langchain/langchain/utilities/github.py @@ -5,7 +5,8 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from github.Issue import Issue diff --git a/libs/langchain/langchain/utilities/gitlab.py b/libs/langchain/langchain/utilities/gitlab.py index 7c9f1b62b7562..78765637c716d 100644 --- a/libs/langchain/langchain/utilities/gitlab.py +++ b/libs/langchain/langchain/utilities/gitlab.py @@ -5,7 +5,8 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from gitlab.v4.objects import Issue diff --git a/libs/langchain/langchain/utilities/golden_query.py b/libs/langchain/langchain/utilities/golden_query.py index baeb3ddf96a22..965a218ec79d9 100644 --- a/libs/langchain/langchain/utilities/golden_query.py +++ b/libs/langchain/langchain/utilities/golden_query.py @@ -4,7 +4,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env GOLDEN_BASE_URL = "https://golden.com" GOLDEN_TIMEOUT = 5000 diff --git a/libs/langchain/langchain/utilities/google_places_api.py b/libs/langchain/langchain/utilities/google_places_api.py index 88cc585d760c3..290b48853dded 100644 --- a/libs/langchain/langchain/utilities/google_places_api.py +++ b/libs/langchain/langchain/utilities/google_places_api.py @@ -5,7 +5,8 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class GooglePlacesAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/google_scholar.py b/libs/langchain/langchain/utilities/google_scholar.py index 0d731441b8936..9c9232b7cf9a8 100644 --- a/libs/langchain/langchain/utilities/google_scholar.py +++ b/libs/langchain/langchain/utilities/google_scholar.py @@ -2,7 +2,8 @@ from typing import Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class GoogleScholarAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/google_search.py b/libs/langchain/langchain/utilities/google_search.py index 5229f59cb3ac9..d6db48d8a7d4f 100644 --- a/libs/langchain/langchain/utilities/google_search.py +++ b/libs/langchain/langchain/utilities/google_search.py @@ -2,7 +2,8 @@ from typing import Any, Dict, List, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class GoogleSearchAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/google_serper.py b/libs/langchain/langchain/utilities/google_serper.py index 11db75094bb02..9efa3bf28e19d 100644 --- a/libs/langchain/langchain/utilities/google_serper.py +++ b/libs/langchain/langchain/utilities/google_serper.py @@ -4,9 +4,10 @@ import aiohttp import requests from langchain_core.pydantic_v1 import BaseModel, root_validator -from langchain_core.utils import get_from_dict_or_env from typing_extensions import Literal +from langchain.utils import get_from_dict_or_env + class GoogleSerperAPIWrapper(BaseModel): """Wrapper around the Serper.dev Google Search API. diff --git a/libs/langchain/langchain/utilities/jira.py b/libs/langchain/langchain/utilities/jira.py index 4d6522d7fd9d9..c08c9a9a5f1e2 100644 --- a/libs/langchain/langchain/utilities/jira.py +++ b/libs/langchain/langchain/utilities/jira.py @@ -2,7 +2,8 @@ from typing import Any, Dict, List, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env # TODO: think about error handling, more specific api specs, and jql/project limits diff --git a/libs/langchain/langchain/utilities/max_compute.py b/libs/langchain/langchain/utilities/max_compute.py index 3f6441803e021..b54c322eaece4 100644 --- a/libs/langchain/langchain/utilities/max_compute.py +++ b/libs/langchain/langchain/utilities/max_compute.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, Iterator, List, Optional -from langchain_core.utils import get_from_env +from langchain.utils import get_from_env if TYPE_CHECKING: from odps import ODPS diff --git a/libs/langchain/langchain/utilities/metaphor_search.py b/libs/langchain/langchain/utilities/metaphor_search.py index 270ce8a5e4361..7b2aaa5773145 100644 --- a/libs/langchain/langchain/utilities/metaphor_search.py +++ b/libs/langchain/langchain/utilities/metaphor_search.py @@ -8,7 +8,8 @@ import aiohttp import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env METAPHOR_API_URL = "https://api.metaphor.systems" diff --git a/libs/langchain/langchain/utilities/openweathermap.py b/libs/langchain/langchain/utilities/openweathermap.py index f79149a1be45c..a8aa5e7406d22 100644 --- a/libs/langchain/langchain/utilities/openweathermap.py +++ b/libs/langchain/langchain/utilities/openweathermap.py @@ -2,7 +2,8 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class OpenWeatherMapAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/scenexplain.py b/libs/langchain/langchain/utilities/scenexplain.py index f8ffcb41e13b8..7b181e4d5c3ad 100644 --- a/libs/langchain/langchain/utilities/scenexplain.py +++ b/libs/langchain/langchain/utilities/scenexplain.py @@ -9,7 +9,8 @@ import requests from langchain_core.pydantic_v1 import BaseModel, BaseSettings, Field, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class SceneXplainAPIWrapper(BaseSettings, BaseModel): diff --git a/libs/langchain/langchain/utilities/searchapi.py b/libs/langchain/langchain/utilities/searchapi.py index 4d3d20d3918ba..e89552096e448 100644 --- a/libs/langchain/langchain/utilities/searchapi.py +++ b/libs/langchain/langchain/utilities/searchapi.py @@ -3,7 +3,8 @@ import aiohttp import requests from langchain_core.pydantic_v1 import BaseModel, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class SearchApiAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/searx_search.py b/libs/langchain/langchain/utilities/searx_search.py index ff6805f86cbbe..6d43f5bf7d0f7 100644 --- a/libs/langchain/langchain/utilities/searx_search.py +++ b/libs/langchain/langchain/utilities/searx_search.py @@ -140,7 +140,8 @@ root_validator, validator, ) -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env def _get_default_params() -> dict: diff --git a/libs/langchain/langchain/utilities/serpapi.py b/libs/langchain/langchain/utilities/serpapi.py index be9d78744585e..8a74701f49d32 100644 --- a/libs/langchain/langchain/utilities/serpapi.py +++ b/libs/langchain/langchain/utilities/serpapi.py @@ -8,7 +8,8 @@ import aiohttp from langchain_core.pydantic_v1 import BaseModel, Extra, Field, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class HiddenPrints: diff --git a/libs/langchain/langchain/utilities/sql_database.py b/libs/langchain/langchain/utilities/sql_database.py index 969d682a5410e..b5b4aab6bc6e0 100644 --- a/libs/langchain/langchain/utilities/sql_database.py +++ b/libs/langchain/langchain/utilities/sql_database.py @@ -5,13 +5,14 @@ from typing import Any, Dict, Iterable, List, Literal, Optional, Sequence, Union import sqlalchemy -from langchain_core.utils import get_from_env from sqlalchemy import MetaData, Table, create_engine, inspect, select, text from sqlalchemy.engine import Engine from sqlalchemy.exc import ProgrammingError, SQLAlchemyError from sqlalchemy.schema import CreateTable from sqlalchemy.types import NullType +from langchain.utils import get_from_env + def _format_index(index: sqlalchemy.engine.interfaces.ReflectedIndex) -> str: return ( diff --git a/libs/langchain/langchain/utilities/tavily_search.py b/libs/langchain/langchain/utilities/tavily_search.py index 54cd0810cc265..d16135db65ee2 100644 --- a/libs/langchain/langchain/utilities/tavily_search.py +++ b/libs/langchain/langchain/utilities/tavily_search.py @@ -8,7 +8,8 @@ import aiohttp import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env TAVILY_API_URL = "https://api.tavily.com" diff --git a/libs/langchain/langchain/utilities/twilio.py b/libs/langchain/langchain/utilities/twilio.py index a4baeb5016890..0798195dfffeb 100644 --- a/libs/langchain/langchain/utilities/twilio.py +++ b/libs/langchain/langchain/utilities/twilio.py @@ -2,7 +2,8 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class TwilioAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/wolfram_alpha.py b/libs/langchain/langchain/utilities/wolfram_alpha.py index 079453a0cb3ad..e599511f38fda 100644 --- a/libs/langchain/langchain/utilities/wolfram_alpha.py +++ b/libs/langchain/langchain/utilities/wolfram_alpha.py @@ -2,7 +2,8 @@ from typing import Any, Dict, Optional from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env + +from langchain.utils import get_from_dict_or_env class WolframAlphaAPIWrapper(BaseModel): diff --git a/libs/langchain/langchain/utilities/zapier.py b/libs/langchain/langchain/utilities/zapier.py index adf0a68f46b1a..d5edb76059443 100644 --- a/libs/langchain/langchain/utilities/zapier.py +++ b/libs/langchain/langchain/utilities/zapier.py @@ -17,9 +17,10 @@ import aiohttp import requests from langchain_core.pydantic_v1 import BaseModel, Extra, root_validator -from langchain_core.utils import get_from_dict_or_env from requests import Request, Session +from langchain.utils import get_from_dict_or_env + class ZapierNLAWrapper(BaseModel): """Wrapper for Zapier NLA. diff --git a/libs/langchain/langchain/utils/__init__.py b/libs/langchain/langchain/utils/__init__.py index 9681ac3826bcd..48d3523e5f721 100644 --- a/libs/langchain/langchain/utils/__init__.py +++ b/libs/langchain/langchain/utils/__init__.py @@ -12,7 +12,6 @@ get_colored_text, print_text, ) -from langchain_core.utils.strings import comma_list, stringify_dict, stringify_value from langchain_core.utils.utils import ( check_package_version, convert_to_secret_str, @@ -24,6 +23,7 @@ ) from langchain.utils.math import cosine_similarity, cosine_similarity_top_k +from langchain.utils.strings import comma_list, stringify_dict, stringify_value __all__ = [ "StrictFormatter", diff --git a/libs/langchain/langchain/utils/env.py b/libs/langchain/langchain/utils/env.py index b1e212d22e0c4..f9ac5aba926f7 100644 --- a/libs/langchain/langchain/utils/env.py +++ b/libs/langchain/langchain/utils/env.py @@ -1,3 +1,26 @@ -from langchain_core.utils.env import get_from_dict_or_env, get_from_env +import os +from typing import Any, Dict, Optional -__all__ = ["get_from_dict_or_env", "get_from_env"] + +def get_from_dict_or_env( + data: Dict[str, Any], key: str, env_key: str, default: Optional[str] = None +) -> str: + """Get a value from a dictionary or an environment variable.""" + if key in data and data[key]: + return data[key] + else: + return get_from_env(key, env_key, default=default) + + +def get_from_env(key: str, env_key: str, default: Optional[str] = None) -> str: + """Get a value from a dictionary or an environment variable.""" + if env_key in os.environ and os.environ[env_key]: + return os.environ[env_key] + elif default is not None: + return default + else: + raise ValueError( + f"Did not find {key}, please add an environment variable" + f" `{env_key}` which contains it, or pass" + f" `{key}` as a named parameter." + ) diff --git a/libs/langchain/langchain/utils/openai_functions.py b/libs/langchain/langchain/utils/openai_functions.py index a014ca72ac14e..6380d197649f7 100644 --- a/libs/langchain/langchain/utils/openai_functions.py +++ b/libs/langchain/langchain/utils/openai_functions.py @@ -1,6 +1,7 @@ from typing import Literal, Optional, Type, TypedDict from langchain_core.pydantic_v1 import BaseModel + from langchain.utils.json_schema import dereference_refs diff --git a/libs/langchain/langchain/utils/strings.py b/libs/langchain/langchain/utils/strings.py index f8e88564213ac..3e866f059ffe2 100644 --- a/libs/langchain/langchain/utils/strings.py +++ b/libs/langchain/langchain/utils/strings.py @@ -1,3 +1,40 @@ -from langchain_core.utils.strings import comma_list, stringify_dict, stringify_value +from typing import Any, List -__all__ = ["stringify_value", "stringify_dict", "comma_list"] + +def stringify_value(val: Any) -> str: + """Stringify a value. + + Args: + val: The value to stringify. + + Returns: + str: The stringified value. + """ + if isinstance(val, str): + return val + elif isinstance(val, dict): + return "\n" + stringify_dict(val) + elif isinstance(val, list): + return "\n".join(stringify_value(v) for v in val) + else: + return str(val) + + +def stringify_dict(data: dict) -> str: + """Stringify a dictionary. + + Args: + data: The dictionary to stringify. + + Returns: + str: The stringified dictionary. + """ + text = "" + for key, value in data.items(): + text += key + ": " + stringify_value(value) + "\n" + return text + + +def comma_list(items: List[Any]) -> str: + """Convert a list to a comma-separated string.""" + return ", ".join(str(item) for item in items) diff --git a/libs/langchain/langchain/vectorstores/analyticdb.py b/libs/langchain/langchain/vectorstores/analyticdb.py index 597561f6d448b..c27ee0ac98e00 100644 --- a/libs/langchain/langchain/vectorstores/analyticdb.py +++ b/libs/langchain/langchain/vectorstores/analyticdb.py @@ -14,9 +14,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document +from langchain.utils import get_from_dict_or_env _LANGCHAIN_DEFAULT_EMBEDDING_DIM = 1536 _LANGCHAIN_DEFAULT_COLLECTION_NAME = "langchain_document" diff --git a/libs/langchain/langchain/vectorstores/azuresearch.py b/libs/langchain/langchain/vectorstores/azuresearch.py index a7dbd3c8cadb8..4fbd766bc8473 100644 --- a/libs/langchain/langchain/vectorstores/azuresearch.py +++ b/libs/langchain/langchain/vectorstores/azuresearch.py @@ -21,13 +21,13 @@ from langchain_core.schema import BaseRetriever from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_env from langchain.callbacks.manager import ( AsyncCallbackManagerForRetrieverRun, CallbackManagerForRetrieverRun, ) from langchain.docstore.document import Document +from langchain.utils import get_from_env logger = logging.getLogger() diff --git a/libs/langchain/langchain/vectorstores/dashvector.py b/libs/langchain/langchain/vectorstores/dashvector.py index ab75968ac1636..e151798a15d74 100644 --- a/libs/langchain/langchain/vectorstores/dashvector.py +++ b/libs/langchain/langchain/vectorstores/dashvector.py @@ -13,9 +13,9 @@ import numpy as np from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_env from langchain.docstore.document import Document +from langchain.utils import get_from_env from langchain.vectorstores.utils import maximal_marginal_relevance logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/vectorstores/elastic_vector_search.py b/libs/langchain/langchain/vectorstores/elastic_vector_search.py index c9355f3304486..dd5ef4aef145a 100644 --- a/libs/langchain/langchain/vectorstores/elastic_vector_search.py +++ b/libs/langchain/langchain/vectorstores/elastic_vector_search.py @@ -17,9 +17,9 @@ from langchain_core._api import deprecated from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document +from langchain.utils import get_from_dict_or_env if TYPE_CHECKING: from elasticsearch import Elasticsearch diff --git a/libs/langchain/langchain/vectorstores/hologres.py b/libs/langchain/langchain/vectorstores/hologres.py index 743441f4c6206..93504adfb41b4 100644 --- a/libs/langchain/langchain/vectorstores/hologres.py +++ b/libs/langchain/langchain/vectorstores/hologres.py @@ -7,9 +7,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document +from langchain.utils import get_from_dict_or_env ADA_TOKEN_COUNT = 1536 _LANGCHAIN_DEFAULT_TABLE_NAME = "langchain_pg_embedding" diff --git a/libs/langchain/langchain/vectorstores/meilisearch.py b/libs/langchain/langchain/vectorstores/meilisearch.py index e954e4d98ffee..80f24241522f3 100644 --- a/libs/langchain/langchain/vectorstores/meilisearch.py +++ b/libs/langchain/langchain/vectorstores/meilisearch.py @@ -5,9 +5,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_env from langchain.docstore.document import Document +from langchain.utils import get_from_env if TYPE_CHECKING: from meilisearch import Client diff --git a/libs/langchain/langchain/vectorstores/momento_vector_index.py b/libs/langchain/langchain/vectorstores/momento_vector_index.py index a0ce7ee66f5c2..db30d9251c713 100644 --- a/libs/langchain/langchain/vectorstores/momento_vector_index.py +++ b/libs/langchain/langchain/vectorstores/momento_vector_index.py @@ -13,9 +13,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_env from langchain.docstore.document import Document +from langchain.utils import get_from_env from langchain.vectorstores.utils import DistanceStrategy VST = TypeVar("VST", bound="VectorStore") diff --git a/libs/langchain/langchain/vectorstores/neo4j_vector.py b/libs/langchain/langchain/vectorstores/neo4j_vector.py index a544ba619a3e7..595656083cdbe 100644 --- a/libs/langchain/langchain/vectorstores/neo4j_vector.py +++ b/libs/langchain/langchain/vectorstores/neo4j_vector.py @@ -17,9 +17,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_env from langchain.docstore.document import Document +from langchain.utils import get_from_env from langchain.vectorstores.utils import DistanceStrategy DEFAULT_DISTANCE_STRATEGY = DistanceStrategy.COSINE diff --git a/libs/langchain/langchain/vectorstores/opensearch_vector_search.py b/libs/langchain/langchain/vectorstores/opensearch_vector_search.py index 5e427d117020f..b2cc55c7e8ce6 100644 --- a/libs/langchain/langchain/vectorstores/opensearch_vector_search.py +++ b/libs/langchain/langchain/vectorstores/opensearch_vector_search.py @@ -8,8 +8,8 @@ from langchain_core.schema import Document from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env +from langchain.utils import get_from_dict_or_env from langchain.vectorstores.utils import maximal_marginal_relevance IMPORT_OPENSEARCH_PY_ERROR = ( diff --git a/libs/langchain/langchain/vectorstores/pgembedding.py b/libs/langchain/langchain/vectorstores/pgembedding.py index bb2e81b9622d3..db2f67b927a14 100644 --- a/libs/langchain/langchain/vectorstores/pgembedding.py +++ b/libs/langchain/langchain/vectorstores/pgembedding.py @@ -16,9 +16,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document +from langchain.utils import get_from_dict_or_env Base = declarative_base() # type: Any diff --git a/libs/langchain/langchain/vectorstores/pgvector.py b/libs/langchain/langchain/vectorstores/pgvector.py index 93741a2cddfc0..db8122e0f6763 100644 --- a/libs/langchain/langchain/vectorstores/pgvector.py +++ b/libs/langchain/langchain/vectorstores/pgvector.py @@ -32,9 +32,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document +from langchain.utils import get_from_dict_or_env from langchain.vectorstores.utils import maximal_marginal_relevance if TYPE_CHECKING: diff --git a/libs/langchain/langchain/vectorstores/redis/base.py b/libs/langchain/langchain/vectorstores/redis/base.py index b2b39f769d42d..13156ccc1387f 100644 --- a/libs/langchain/langchain/vectorstores/redis/base.py +++ b/libs/langchain/langchain/vectorstores/redis/base.py @@ -25,7 +25,6 @@ from langchain_core._api import deprecated from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore, VectorStoreRetriever -from langchain_core.utils import get_from_dict_or_env from langchain.callbacks.manager import CallbackManagerForRetrieverRun from langchain.docstore.document import Document @@ -35,6 +34,7 @@ check_redis_module_exist, get_client, ) +from langchain.utils import get_from_dict_or_env from langchain.vectorstores.redis.constants import ( REDIS_REQUIRED_MODULES, REDIS_TAG_SEPARATOR, diff --git a/libs/langchain/langchain/vectorstores/semadb.py b/libs/langchain/langchain/vectorstores/semadb.py index 020a6fa9c010e..c7aeab3150cd5 100644 --- a/libs/langchain/langchain/vectorstores/semadb.py +++ b/libs/langchain/langchain/vectorstores/semadb.py @@ -6,8 +6,8 @@ from langchain_core.schema.document import Document from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_env +from langchain.utils import get_from_env from langchain.vectorstores.utils import DistanceStrategy diff --git a/libs/langchain/langchain/vectorstores/tair.py b/libs/langchain/langchain/vectorstores/tair.py index d2e63d106f459..75a86ec8e6c13 100644 --- a/libs/langchain/langchain/vectorstores/tair.py +++ b/libs/langchain/langchain/vectorstores/tair.py @@ -7,9 +7,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env from langchain.docstore.document import Document +from langchain.utils import get_from_dict_or_env logger = logging.getLogger(__name__) diff --git a/libs/langchain/langchain/vectorstores/timescalevector.py b/libs/langchain/langchain/vectorstores/timescalevector.py index 1f8e9a69648c9..b7fcbe77ca8fd 100644 --- a/libs/langchain/langchain/vectorstores/timescalevector.py +++ b/libs/langchain/langchain/vectorstores/timescalevector.py @@ -21,8 +21,8 @@ from langchain_core.schema.document import Document from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_dict_or_env +from langchain.utils import get_from_dict_or_env from langchain.vectorstores.utils import DistanceStrategy if TYPE_CHECKING: diff --git a/libs/langchain/langchain/vectorstores/typesense.py b/libs/langchain/langchain/vectorstores/typesense.py index e0c6c2dd01059..bb37192670f16 100644 --- a/libs/langchain/langchain/vectorstores/typesense.py +++ b/libs/langchain/langchain/vectorstores/typesense.py @@ -5,9 +5,9 @@ from langchain_core.schema.embeddings import Embeddings from langchain_core.schema.vectorstore import VectorStore -from langchain_core.utils import get_from_env from langchain.docstore.document import Document +from langchain.utils import get_from_env if TYPE_CHECKING: from typesense.client import Client diff --git a/libs/langchain/tests/integration_tests/agent/test_powerbi_agent.py b/libs/langchain/tests/integration_tests/agent/test_powerbi_agent.py index 732cd4cbc2f4c..f59d4273efb37 100644 --- a/libs/langchain/tests/integration_tests/agent/test_powerbi_agent.py +++ b/libs/langchain/tests/integration_tests/agent/test_powerbi_agent.py @@ -1,9 +1,9 @@ import pytest -from langchain_core.utils import get_from_env from langchain.agents.agent_toolkits import PowerBIToolkit, create_pbi_agent from langchain.chat_models import ChatOpenAI from langchain.utilities.powerbi import PowerBIDataset +from langchain.utils import get_from_env def azure_installed() -> bool: diff --git a/libs/langchain/tests/integration_tests/utilities/test_powerbi_api.py b/libs/langchain/tests/integration_tests/utilities/test_powerbi_api.py index 43bb14f91a1d8..8d7a6114022e2 100644 --- a/libs/langchain/tests/integration_tests/utilities/test_powerbi_api.py +++ b/libs/langchain/tests/integration_tests/utilities/test_powerbi_api.py @@ -1,8 +1,8 @@ """Integration test for POWERBI API Wrapper.""" import pytest -from langchain_core.utils import get_from_env from langchain.utilities.powerbi import PowerBIDataset +from langchain.utils import get_from_env def azure_installed() -> bool: diff --git a/libs/langchain/tests/unit_tests/utils/test_json_schema.py b/libs/langchain/tests/unit_tests/utils/test_json_schema.py index ffbf0c1353b58..233c46727297f 100644 --- a/libs/langchain/tests/unit_tests/utils/test_json_schema.py +++ b/libs/langchain/tests/unit_tests/utils/test_json_schema.py @@ -1,4 +1,5 @@ import pytest + from langchain.utils.json_schema import dereference_refs