mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 08:33:49 +00:00
langchain[patch]: Upgrade prompts to optional imports (#21078)
Upgrades prompts module to use optional imports. This code was generated with a migration script, but had to be adjusted manually a bit. Testing in preparation for applying this code modification across the rest of the modules in langchain package to reverse the dependency between langchain community and langchain.
This commit is contained in:
parent
9b6d04a187
commit
8658d52587
@ -27,9 +27,8 @@ from multiple components. Prompt classes and functions make constructing
|
||||
ChatPromptValue
|
||||
|
||||
""" # noqa: E501
|
||||
from langchain_community.example_selectors.ngram_overlap import (
|
||||
NGramOverlapExampleSelector,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_core.example_selectors import (
|
||||
LengthBasedExampleSelector,
|
||||
MaxMarginalRelevanceExampleSelector,
|
||||
@ -53,8 +52,29 @@ from langchain_core.prompts import (
|
||||
load_prompt,
|
||||
)
|
||||
|
||||
from langchain._api import create_importer
|
||||
from langchain.prompts.prompt import Prompt
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.example_selectors.ngram_overlap import (
|
||||
NGramOverlapExampleSelector,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
MODULE_LOOKUP = {
|
||||
"NGramOverlapExampleSelector": "langchain_community.example_selectors.ngram_overlap"
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__file__, module_lookup=MODULE_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AIMessagePromptTemplate",
|
||||
"BaseChatPromptTemplate",
|
||||
|
@ -1,7 +1,6 @@
|
||||
"""Logic for selecting examples to include in prompts."""
|
||||
from langchain_community.example_selectors.ngram_overlap import (
|
||||
NGramOverlapExampleSelector,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain_core.example_selectors.length_based import (
|
||||
LengthBasedExampleSelector,
|
||||
)
|
||||
@ -10,6 +9,28 @@ from langchain_core.example_selectors.semantic_similarity import (
|
||||
SemanticSimilarityExampleSelector,
|
||||
)
|
||||
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.example_selectors.ngram_overlap import (
|
||||
NGramOverlapExampleSelector,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
DEPRECATED_LOOKUPS = {
|
||||
"NGramOverlapExampleSelector": "langchain_community.example_selectors.ngram_overlap"
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__file__, deprecated_lookups=DEPRECATED_LOOKUPS)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"LengthBasedExampleSelector",
|
||||
"MaxMarginalRelevanceExampleSelector",
|
||||
|
@ -1,7 +1,30 @@
|
||||
from langchain_community.example_selectors.ngram_overlap import (
|
||||
NGramOverlapExampleSelector,
|
||||
ngram_overlap_score,
|
||||
)
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from langchain._api import create_importer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_community.example_selectors.ngram_overlap import (
|
||||
NGramOverlapExampleSelector,
|
||||
ngram_overlap_score,
|
||||
)
|
||||
|
||||
# Create a way to dynamically look up deprecated imports.
|
||||
# Used to consolidate logic for raising deprecation warnings and
|
||||
# handling optional imports.
|
||||
MODULE_LOOKUP = {
|
||||
"NGramOverlapExampleSelector": (
|
||||
"langchain_community.example_selectors.ngram_overlap"
|
||||
),
|
||||
"ngram_overlap_score": "langchain_community.example_selectors.ngram_overlap",
|
||||
}
|
||||
|
||||
_import_attribute = create_importer(__file__, deprecated_lookups=MODULE_LOOKUP)
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""Look up attributes dynamically."""
|
||||
return _import_attribute(name)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"NGramOverlapExampleSelector",
|
||||
|
Loading…
Reference in New Issue
Block a user