mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-15 01:13:48 +00:00
community[patch]: give reranker default client val (#17289)
This commit is contained in:
parent
841e5f514e
commit
22638e5927
@ -14,14 +14,15 @@ from langchain.utils import get_from_dict_or_env
|
|||||||
class CohereRerank(BaseDocumentCompressor):
|
class CohereRerank(BaseDocumentCompressor):
|
||||||
"""Document compressor that uses `Cohere Rerank API`."""
|
"""Document compressor that uses `Cohere Rerank API`."""
|
||||||
|
|
||||||
client: Any
|
client: Any = None
|
||||||
"""Cohere client to use for compressing documents."""
|
"""Cohere client to use for compressing documents."""
|
||||||
top_n: Optional[int] = 3
|
top_n: Optional[int] = 3
|
||||||
"""Number of documents to return."""
|
"""Number of documents to return."""
|
||||||
model: str = "rerank-english-v2.0"
|
model: str = "rerank-english-v2.0"
|
||||||
"""Model to use for reranking."""
|
"""Model to use for reranking."""
|
||||||
|
|
||||||
cohere_api_key: Optional[str] = None
|
cohere_api_key: Optional[str] = None
|
||||||
|
"""Cohere API key. Must be specified directly or via environment variable
|
||||||
|
COHERE_API_KEY."""
|
||||||
user_agent: str = "langchain"
|
user_agent: str = "langchain"
|
||||||
"""Identifier for the application making the request."""
|
"""Identifier for the application making the request."""
|
||||||
|
|
||||||
@ -34,6 +35,7 @@ class CohereRerank(BaseDocumentCompressor):
|
|||||||
@root_validator(pre=True)
|
@root_validator(pre=True)
|
||||||
def validate_environment(cls, values: Dict) -> Dict:
|
def validate_environment(cls, values: Dict) -> Dict:
|
||||||
"""Validate that api key and python package exists in environment."""
|
"""Validate that api key and python package exists in environment."""
|
||||||
|
if not values.get("client"):
|
||||||
try:
|
try:
|
||||||
import cohere
|
import cohere
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
Loading…
Reference in New Issue
Block a user