mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-07 22:11:51 +00:00
community: callbacks
guard_imports (#21173)
Issue: we have several helper functions to import third-party libraries like import_uptrain in [community.callbacks](https://api.python.langchain.com/en/latest/callbacks/langchain_community.callbacks.uptrain_callback.import_uptrain.html#langchain_community.callbacks.uptrain_callback.import_uptrain). And we have core.utils.utils.guard_import that works exactly for this purpose. The import_<package> functions work inconsistently and rather be private functions. Change: replaced these functions with the guard_import function. Related to #21133
This commit is contained in:
@@ -4,6 +4,7 @@ from uuid import UUID
|
||||
|
||||
from langchain_core.callbacks import BaseCallbackHandler
|
||||
from langchain_core.outputs import LLMResult
|
||||
from langchain_core.utils import guard_import
|
||||
|
||||
from langchain_community.callbacks.utils import import_pandas
|
||||
|
||||
@@ -54,14 +55,7 @@ _dataset_dict = {
|
||||
|
||||
def import_fiddler() -> Any:
|
||||
"""Import the fiddler python package and raise an error if it is not installed."""
|
||||
try:
|
||||
import fiddler
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"To use fiddler callback handler you need to have `fiddler-client`"
|
||||
"package installed. Please install it with `pip install fiddler-client`"
|
||||
)
|
||||
return fiddler
|
||||
return guard_import("fiddler", pip_name="fiddler-client")
|
||||
|
||||
|
||||
# First, define custom callback handler implementations
|
||||
|
Reference in New Issue
Block a user