mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-13 05:25:07 +00:00
exa[patch]: ruff fixes and rules (#31902)
* bump ruff deps * add more thorough ruff rules * fix said rules
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from exa_py.api import ( # type: ignore # type: ignore[import-not-found, import-not-found]
|
||||
from exa_py.api import (
|
||||
HighlightsContentsOptions,
|
||||
TextContentsOptions,
|
||||
)
|
||||
@@ -7,9 +7,9 @@ from langchain_exa.retrievers import ExaSearchRetriever
|
||||
from langchain_exa.tools import ExaFindSimilarResults, ExaSearchResults
|
||||
|
||||
__all__ = [
|
||||
"ExaFindSimilarResults",
|
||||
"ExaSearchResults",
|
||||
"ExaSearchRetriever",
|
||||
"HighlightsContentsOptions",
|
||||
"TextContentsOptions",
|
||||
"ExaFindSimilarResults",
|
||||
]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import os # type: ignore[import-not-found]
|
||||
|
||||
from exa_py import Exa # type: ignore
|
||||
from exa_py import Exa
|
||||
from langchain_core.utils import convert_to_secret_str
|
||||
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal, Optional, Union
|
||||
|
||||
from exa_py import Exa # type: ignore[untyped-import]
|
||||
@@ -75,17 +77,16 @@ class ExaSearchRetriever(BaseRetriever):
|
||||
@classmethod
|
||||
def validate_environment(cls, values: dict) -> Any:
|
||||
"""Validate the environment."""
|
||||
values = initialize_client(values)
|
||||
return values
|
||||
return initialize_client(values)
|
||||
|
||||
def _get_relevant_documents(
|
||||
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
|
||||
) -> list[Document]:
|
||||
response = self.client.search_and_contents( # type: ignore[misc]
|
||||
response = self.client.search_and_contents( # type: ignore[call-overload]
|
||||
query,
|
||||
num_results=self.k,
|
||||
text=self.text_contents_options,
|
||||
highlights=self.highlights, # type: ignore
|
||||
highlights=self.highlights,
|
||||
include_domains=self.include_domains,
|
||||
exclude_domains=self.exclude_domains,
|
||||
start_crawl_date=self.start_crawl_date,
|
||||
@@ -96,7 +97,7 @@ class ExaSearchRetriever(BaseRetriever):
|
||||
livecrawl=self.livecrawl,
|
||||
summary=self.summary,
|
||||
type=self.type,
|
||||
)
|
||||
) # type: ignore[call-overload, misc]
|
||||
|
||||
results = response.results
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
"""Tool for the Exa Search API."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal, Optional, Union
|
||||
|
||||
from exa_py import Exa # type: ignore[untyped-import]
|
||||
@@ -17,7 +19,7 @@ from langchain_exa._utilities import initialize_client
|
||||
|
||||
|
||||
class ExaSearchResults(BaseTool): # type: ignore[override]
|
||||
"""Exa Search tool.
|
||||
r"""Exa Search tool.
|
||||
|
||||
Setup:
|
||||
Install ``langchain-exa`` and set environment variable ``EXA_API_KEY``.
|
||||
@@ -68,8 +70,7 @@ class ExaSearchResults(BaseTool): # type: ignore[override]
|
||||
@classmethod
|
||||
def validate_environment(cls, values: dict) -> Any:
|
||||
"""Validate the environment."""
|
||||
values = initialize_client(values)
|
||||
return values
|
||||
return initialize_client(values)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
@@ -88,9 +89,10 @@ class ExaSearchResults(BaseTool): # type: ignore[override]
|
||||
use_autoprompt: Optional[bool] = None,
|
||||
livecrawl: Optional[Literal["always", "fallback", "never"]] = None,
|
||||
summary: Optional[Union[bool, dict[str, str]]] = None,
|
||||
type: Optional[Literal["neural", "keyword", "auto"]] = None,
|
||||
type: Optional[Literal["neural", "keyword", "auto"]] = None, # noqa: A002
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> Union[list[dict], str]:
|
||||
# TODO: rename `type` to something else, as it is a reserved keyword
|
||||
"""Use the tool.
|
||||
|
||||
Args:
|
||||
@@ -109,13 +111,14 @@ class ExaSearchResults(BaseTool): # type: ignore[override]
|
||||
summary: Whether to include a summary of the content. Can be a boolean or a dict with a custom query.
|
||||
type: The type of search, 'keyword', 'neural', or 'auto'.
|
||||
run_manager: The run manager for callbacks.
|
||||
|
||||
""" # noqa: E501
|
||||
try:
|
||||
return self.client.search_and_contents(
|
||||
query,
|
||||
num_results=num_results,
|
||||
text=text_contents_options, # type: ignore
|
||||
highlights=highlights, # type: ignore
|
||||
text=text_contents_options,
|
||||
highlights=highlights,
|
||||
include_domains=include_domains,
|
||||
exclude_domains=exclude_domains,
|
||||
start_crawl_date=start_crawl_date,
|
||||
@@ -126,7 +129,7 @@ class ExaSearchResults(BaseTool): # type: ignore[override]
|
||||
livecrawl=livecrawl,
|
||||
summary=summary,
|
||||
type=type,
|
||||
) # type: ignore
|
||||
) # type: ignore[call-overload, misc]
|
||||
except Exception as e:
|
||||
return repr(e)
|
||||
|
||||
@@ -148,8 +151,7 @@ class ExaFindSimilarResults(BaseTool): # type: ignore[override]
|
||||
@classmethod
|
||||
def validate_environment(cls, values: dict) -> Any:
|
||||
"""Validate the environment."""
|
||||
values = initialize_client(values)
|
||||
return values
|
||||
return initialize_client(values)
|
||||
|
||||
def _run(
|
||||
self,
|
||||
@@ -189,13 +191,14 @@ class ExaFindSimilarResults(BaseTool): # type: ignore[override]
|
||||
livecrawl: Option to crawl live webpages if content is not in the index. Options: "always", "fallback", "never"
|
||||
summary: Whether to include a summary of the content. Can be a boolean or a dict with a custom query.
|
||||
run_manager: The run manager for callbacks.
|
||||
|
||||
""" # noqa: E501
|
||||
try:
|
||||
return self.client.find_similar_and_contents(
|
||||
url,
|
||||
num_results=num_results,
|
||||
text=text_contents_options, # type: ignore
|
||||
highlights=highlights, # type: ignore
|
||||
text=text_contents_options,
|
||||
highlights=highlights,
|
||||
include_domains=include_domains,
|
||||
exclude_domains=exclude_domains,
|
||||
start_crawl_date=start_crawl_date,
|
||||
@@ -206,6 +209,6 @@ class ExaFindSimilarResults(BaseTool): # type: ignore[override]
|
||||
category=category,
|
||||
livecrawl=livecrawl,
|
||||
summary=summary,
|
||||
) # type: ignore
|
||||
) # type: ignore[call-overload, misc]
|
||||
except Exception as e:
|
||||
return repr(e)
|
||||
|
Reference in New Issue
Block a user