Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis committed Jan 13, 2025
1 parent f78e5b8 commit 1457f2f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
3 changes: 1 addition & 2 deletions libs/langchain/langchain/chains/flare/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def _low_confidence_spans(
import numpy as np
except ImportError as e:
raise ImportError(
"Could not import numpy,"
"please install with `pip install numpy`."
"Could not import numpy," "please install with `pip install numpy`."
) from e
_low_idx = np.where(np.exp(log_probs) < min_prob)[0]
low_idx = [i for i in _low_idx if re.search(r"\w", tokens[i])]
Expand Down
3 changes: 1 addition & 2 deletions libs/langchain/langchain/chains/hyde/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def combine_embeddings(self, embeddings: List[List[float]]) -> List[float]:
import numpy as np
except ImportError as e:
raise ImportError(
"Could not import numpy,"
"please install with `pip install numpy`."
"Could not import numpy," "please install with `pip install numpy`."
) from e
return list(np.array(embeddings).mean(axis=0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@
if TYPE_CHECKING:
import numpy as np


def _import_numpy() -> Any:
try:
import numpy as np
return np

return np
except ImportError as e:
raise ImportError(
"Could not import numpy,"
"please install with `pip install numpy`."
"Could not import numpy," "please install with `pip install numpy`."
) from e


def _embedding_factory() -> Embeddings:
"""Create an Embeddings object.
Returns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ def compress_documents(
"To use please install langchain-community "
"with `pip install langchain-community`."
)

try:
import numpy as np
except ImportError as e:
raise ImportError(
"Could not import numpy,"
"please install with `pip install numpy`."
"Could not import numpy," "please install with `pip install numpy`."
) from e
stateful_documents = get_stateful_documents(documents)
embedded_documents = _get_embeddings_from_stateful_docs(
Expand Down Expand Up @@ -111,13 +110,12 @@ async def acompress_documents(
"To use please install langchain-community "
"with `pip install langchain-community`."
)

try:
import numpy as np
except ImportError as e:
raise ImportError(
"Could not import numpy,"
"please install with `pip install numpy`."
"Could not import numpy," "please install with `pip install numpy`."
) from e
stateful_documents = get_stateful_documents(documents)
embedded_documents = await _aget_embeddings_from_stateful_docs(
Expand Down

0 comments on commit 1457f2f

Please sign in to comment.