Spaces:
Runtime error
Runtime error
File size: 12,806 Bytes
129cd69 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# ruff: noqa: E402
"""Main entrypoint into package."""
import warnings
from importlib import metadata
from typing import Any, Optional
from langchain_core._api.deprecation import surface_langchain_deprecation_warnings
try:
__version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
# Case where package metadata is not available.
__version__ = ""
del metadata # optional, avoids polluting the results of dir(__package__)
def _is_interactive_env() -> bool:
"""Determine if running within IPython or Jupyter."""
import sys
return hasattr(sys, "ps2")
def _warn_on_import(name: str, replacement: Optional[str] = None) -> None:
"""Warn on import of deprecated module."""
if _is_interactive_env():
# No warnings for interactive environments.
# This is done to avoid polluting the output of interactive environments
# where users rely on auto-complete and may trigger this warning
# even if they are not using any deprecated modules
return
if replacement:
warnings.warn(
f"Importing {name} from langchain root module is no longer supported. "
f"Please use {replacement} instead."
)
else:
warnings.warn(
f"Importing {name} from langchain root module is no longer supported."
)
# Surfaces Deprecation and Pending Deprecation warnings from langchain.
surface_langchain_deprecation_warnings()
def __getattr__(name: str) -> Any:
if name == "MRKLChain":
from langchain.agents import MRKLChain
_warn_on_import(name, replacement="langchain.agents.MRKLChain")
return MRKLChain
elif name == "ReActChain":
from langchain.agents import ReActChain
_warn_on_import(name, replacement="langchain.agents.ReActChain")
return ReActChain
elif name == "SelfAskWithSearchChain":
from langchain.agents import SelfAskWithSearchChain
_warn_on_import(name, replacement="langchain.agents.SelfAskWithSearchChain")
return SelfAskWithSearchChain
elif name == "ConversationChain":
from langchain.chains import ConversationChain
_warn_on_import(name, replacement="langchain.chains.ConversationChain")
return ConversationChain
elif name == "LLMBashChain":
raise ImportError(
"This module has been moved to langchain-experimental. "
"For more details: "
"https://github.com/langchain-ai/langchain/discussions/11352."
"To access this code, install it with `pip install langchain-experimental`."
"`from langchain_experimental.llm_bash.base "
"import LLMBashChain`"
)
elif name == "LLMChain":
from langchain.chains import LLMChain
_warn_on_import(name, replacement="langchain.chains.LLMChain")
return LLMChain
elif name == "LLMCheckerChain":
from langchain.chains import LLMCheckerChain
_warn_on_import(name, replacement="langchain.chains.LLMCheckerChain")
return LLMCheckerChain
elif name == "LLMMathChain":
from langchain.chains import LLMMathChain
_warn_on_import(name, replacement="langchain.chains.LLMMathChain")
return LLMMathChain
elif name == "QAWithSourcesChain":
from langchain.chains import QAWithSourcesChain
_warn_on_import(name, replacement="langchain.chains.QAWithSourcesChain")
return QAWithSourcesChain
elif name == "VectorDBQA":
from langchain.chains import VectorDBQA
_warn_on_import(name, replacement="langchain.chains.VectorDBQA")
return VectorDBQA
elif name == "VectorDBQAWithSourcesChain":
from langchain.chains import VectorDBQAWithSourcesChain
_warn_on_import(name, replacement="langchain.chains.VectorDBQAWithSourcesChain")
return VectorDBQAWithSourcesChain
elif name == "InMemoryDocstore":
from langchain.docstore import InMemoryDocstore
_warn_on_import(name, replacement="langchain.docstore.InMemoryDocstore")
return InMemoryDocstore
elif name == "Wikipedia":
from langchain.docstore import Wikipedia
_warn_on_import(name, replacement="langchain.docstore.Wikipedia")
return Wikipedia
elif name == "Anthropic":
from langchain.llms import Anthropic
_warn_on_import(name, replacement="langchain.llms.Anthropic")
return Anthropic
elif name == "Banana":
from langchain.llms import Banana
_warn_on_import(name, replacement="langchain.llms.Banana")
return Banana
elif name == "CerebriumAI":
from langchain.llms import CerebriumAI
_warn_on_import(name, replacement="langchain.llms.CerebriumAI")
return CerebriumAI
elif name == "Cohere":
from langchain.llms import Cohere
_warn_on_import(name, replacement="langchain.llms.Cohere")
return Cohere
elif name == "ForefrontAI":
from langchain.llms import ForefrontAI
_warn_on_import(name, replacement="langchain.llms.ForefrontAI")
return ForefrontAI
elif name == "GooseAI":
from langchain.llms import GooseAI
_warn_on_import(name, replacement="langchain.llms.GooseAI")
return GooseAI
elif name == "HuggingFaceHub":
from langchain.llms import HuggingFaceHub
_warn_on_import(name, replacement="langchain.llms.HuggingFaceHub")
return HuggingFaceHub
elif name == "HuggingFaceTextGenInference":
from langchain.llms import HuggingFaceTextGenInference
_warn_on_import(name, replacement="langchain.llms.HuggingFaceTextGenInference")
return HuggingFaceTextGenInference
elif name == "LlamaCpp":
from langchain.llms import LlamaCpp
_warn_on_import(name, replacement="langchain.llms.LlamaCpp")
return LlamaCpp
elif name == "Modal":
from langchain.llms import Modal
_warn_on_import(name, replacement="langchain.llms.Modal")
return Modal
elif name == "OpenAI":
from langchain.llms import OpenAI
_warn_on_import(name, replacement="langchain.llms.OpenAI")
return OpenAI
elif name == "Petals":
from langchain.llms import Petals
_warn_on_import(name, replacement="langchain.llms.Petals")
return Petals
elif name == "PipelineAI":
from langchain.llms import PipelineAI
_warn_on_import(name, replacement="langchain.llms.PipelineAI")
return PipelineAI
elif name == "SagemakerEndpoint":
from langchain.llms import SagemakerEndpoint
_warn_on_import(name, replacement="langchain.llms.SagemakerEndpoint")
return SagemakerEndpoint
elif name == "StochasticAI":
from langchain.llms import StochasticAI
_warn_on_import(name, replacement="langchain.llms.StochasticAI")
return StochasticAI
elif name == "Writer":
from langchain.llms import Writer
_warn_on_import(name, replacement="langchain.llms.Writer")
return Writer
elif name == "HuggingFacePipeline":
from langchain.llms.huggingface_pipeline import HuggingFacePipeline
_warn_on_import(
name, replacement="langchain.llms.huggingface_pipeline.HuggingFacePipeline"
)
return HuggingFacePipeline
elif name == "FewShotPromptTemplate":
from langchain_core.prompts import FewShotPromptTemplate
_warn_on_import(name, replacement="langchain.prompts.FewShotPromptTemplate")
return FewShotPromptTemplate
elif name == "Prompt":
from langchain_core.prompts import Prompt
_warn_on_import(name, replacement="langchain.prompts.Prompt")
return Prompt
elif name == "PromptTemplate":
from langchain_core.prompts import PromptTemplate
_warn_on_import(name, replacement="langchain.prompts.PromptTemplate")
return PromptTemplate
elif name == "BasePromptTemplate":
from langchain_core.prompts import BasePromptTemplate
_warn_on_import(
name, replacement="langchain.schema.prompt_template.BasePromptTemplate"
)
return BasePromptTemplate
elif name == "ArxivAPIWrapper":
from langchain.utilities import ArxivAPIWrapper
_warn_on_import(name, replacement="langchain.utilities.ArxivAPIWrapper")
return ArxivAPIWrapper
elif name == "GoldenQueryAPIWrapper":
from langchain.utilities import GoldenQueryAPIWrapper
_warn_on_import(name, replacement="langchain.utilities.GoldenQueryAPIWrapper")
return GoldenQueryAPIWrapper
elif name == "GoogleSearchAPIWrapper":
from langchain.utilities import GoogleSearchAPIWrapper
_warn_on_import(name, replacement="langchain.utilities.GoogleSearchAPIWrapper")
return GoogleSearchAPIWrapper
elif name == "GoogleSerperAPIWrapper":
from langchain.utilities import GoogleSerperAPIWrapper
_warn_on_import(name, replacement="langchain.utilities.GoogleSerperAPIWrapper")
return GoogleSerperAPIWrapper
elif name == "PowerBIDataset":
from langchain.utilities import PowerBIDataset
_warn_on_import(name, replacement="langchain.utilities.PowerBIDataset")
return PowerBIDataset
elif name == "SearxSearchWrapper":
from langchain.utilities import SearxSearchWrapper
_warn_on_import(name, replacement="langchain.utilities.SearxSearchWrapper")
return SearxSearchWrapper
elif name == "WikipediaAPIWrapper":
from langchain.utilities import WikipediaAPIWrapper
_warn_on_import(name, replacement="langchain.utilities.WikipediaAPIWrapper")
return WikipediaAPIWrapper
elif name == "WolframAlphaAPIWrapper":
from langchain.utilities import WolframAlphaAPIWrapper
_warn_on_import(name, replacement="langchain.utilities.WolframAlphaAPIWrapper")
return WolframAlphaAPIWrapper
elif name == "SQLDatabase":
from langchain.utilities import SQLDatabase
_warn_on_import(name, replacement="langchain.utilities.SQLDatabase")
return SQLDatabase
elif name == "FAISS":
from langchain.vectorstores import FAISS
_warn_on_import(name, replacement="langchain.vectorstores.FAISS")
return FAISS
elif name == "ElasticVectorSearch":
from langchain.vectorstores import ElasticVectorSearch
_warn_on_import(name, replacement="langchain.vectorstores.ElasticVectorSearch")
return ElasticVectorSearch
# For backwards compatibility
elif name == "SerpAPIChain" or name == "SerpAPIWrapper":
from langchain.utilities import SerpAPIWrapper
_warn_on_import(name, replacement="langchain.utilities.SerpAPIWrapper")
return SerpAPIWrapper
elif name == "verbose":
from langchain.globals import _verbose
_warn_on_import(
name,
replacement=(
"langchain.globals.set_verbose() / langchain.globals.get_verbose()"
),
)
return _verbose
elif name == "debug":
from langchain.globals import _debug
_warn_on_import(
name,
replacement=(
"langchain.globals.set_debug() / langchain.globals.get_debug()"
),
)
return _debug
elif name == "llm_cache":
from langchain.globals import _llm_cache
_warn_on_import(
name,
replacement=(
"langchain.globals.set_llm_cache() / langchain.globals.get_llm_cache()"
),
)
return _llm_cache
else:
raise AttributeError(f"Could not find: {name}")
__all__ = [
"LLMChain",
"LLMCheckerChain",
"LLMMathChain",
"ArxivAPIWrapper",
"GoldenQueryAPIWrapper",
"SelfAskWithSearchChain",
"SerpAPIWrapper",
"SerpAPIChain",
"SearxSearchWrapper",
"GoogleSearchAPIWrapper",
"GoogleSerperAPIWrapper",
"WolframAlphaAPIWrapper",
"WikipediaAPIWrapper",
"Anthropic",
"Banana",
"CerebriumAI",
"Cohere",
"ForefrontAI",
"GooseAI",
"Modal",
"OpenAI",
"Petals",
"PipelineAI",
"StochasticAI",
"Writer",
"BasePromptTemplate",
"Prompt",
"FewShotPromptTemplate",
"PromptTemplate",
"ReActChain",
"Wikipedia",
"HuggingFaceHub",
"SagemakerEndpoint",
"HuggingFacePipeline",
"SQLDatabase",
"PowerBIDataset",
"FAISS",
"MRKLChain",
"VectorDBQA",
"ElasticVectorSearch",
"InMemoryDocstore",
"ConversationChain",
"VectorDBQAWithSourcesChain",
"QAWithSourcesChain",
"LlamaCpp",
"HuggingFaceTextGenInference",
]
|