Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions langchain_linkup/search_retriever.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import date
from typing import Literal, Optional, cast

from langchain_core.callbacks import (
Expand Down Expand Up @@ -31,6 +32,18 @@ class LinkupSearchRetriever(BaseRetriever):
linkup_api_key: Optional[str] = None
The API key for the Linkup API. If None (the default), the API key will be read from
the environment variable `LINKUP_API_KEY`.
from_date: Optional[date] = None
The start date for the search
in datetime.date object, e.g. date(2025, 01, 01).
to_date: Optional[date] = None
The end date for the search
in datetime.date object, e.g. date(2025, 01, 01).
include_domains: Optional[list[str]] = None
The list of domains to search on (only those domains).
exclude_domains: Optional[list[str]] = None
The list of domains to exclude from the search.
include_image: bool = False
If set to True, image results will be included alongside text results.


Instantiate:
Expand Down Expand Up @@ -117,6 +130,18 @@ def format_docs(docs):
linkup_api_key: Optional[str] = None
"""The API key for the Linkup API. If None, the API key will be read from the environment
variable `LINKUP_API_KEY`."""
from_date: Optional[date] = None
"""The start date for the search
in datetime.date object, e.g. date(2025, 01, 01)."""
to_date: Optional[date] = None
"""The end date for the search
in datetime.date object, e.g. date(2025, 01, 01)."""
include_domains: Optional[list[str]] = None
"""The list of domains to search on (only those domains)."""
exclude_domains: Optional[list[str]] = None
"""The list of domains to exclude from the search."""
include_image: bool = False
"""If set to True, image results will be included alongside text results."""

def _get_relevant_documents(
self,
Expand All @@ -129,7 +154,11 @@ def _get_relevant_documents(
query=query,
depth=self.depth,
output_type="searchResults",
include_images=False,
include_images=self.include_image,
from_date=self.from_date,
to_date=self.to_date,
include_domains=self.include_domains,
exclude_domains=self.exclude_domains,
)

return [
Expand All @@ -154,7 +183,11 @@ async def _aget_relevant_documents(
query=query,
depth=self.depth,
output_type="searchResults",
include_images=False,
include_images=self.include_image,
from_date=self.from_date,
to_date=self.to_date,
include_domains=self.include_domains,
exclude_domains=self.exclude_domains,
)

return [
Expand Down
35 changes: 35 additions & 0 deletions langchain_linkup/search_tool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import date
from typing import Any, Literal, Optional, Type, Union

from langchain_core.callbacks import (
Expand Down Expand Up @@ -43,6 +44,18 @@ class LinkupSearchTool(BaseTool):
structured_output_schema: Union[Type[BaseModel], str, None] = None
If output_type is "structured", specify the schema of the output. Supported formats are
a pydantic.BaseModel or a string representing a valid object JSON schema.
from_date: Optional[date] = None
The start date for the search
in datetime.date object, e.g. date(2025, 01, 01).
to_date: Optional[date] = None
The end date for the search
in datetime.date object, e.g. date(2025, 01, 01).
include_domains: Optional[list[str]] = None
The list of domains to search on (only those domains).
exclude_domains: Optional[list[str]] = None
The list of domains to exclude from the search.
include_image: bool = False
If set to True, image results will be included alongside text results.

Instantiate:
.. code-block:: python
Expand Down Expand Up @@ -120,6 +133,18 @@ class LinkupSearchTool(BaseTool):
"""If output_type is "structured", specify the schema of the
output. Supported formats are a pydantic.BaseModel or a string representing a
valid object JSON schema."""
from_date: Optional[date] = None
"""The start date for the search
in datetime.date object, e.g. date(2025, 01, 01)."""
to_date: Optional[date] = None
"""The end date for the search
in datetime.date object, e.g. date(2025, 01, 01)."""
include_domains: Optional[list[str]] = None
"""The list of domains to search on (only those domains)."""
exclude_domains: Optional[list[str]] = None
"""The list of domains to exclude from the search."""
include_image: bool = False
"""If set to True, image results will be included alongside text results."""

# Fields used by the agent to describe how to use the tool under the hood
name: str = "linkup"
Expand All @@ -141,6 +166,11 @@ def _run(
depth=self.depth,
output_type=self.output_type,
structured_output_schema=self.structured_output_schema,
from_date=self.from_date,
to_date=self.to_date,
include_domains=self.include_domains,
exclude_domains=self.exclude_domains,
include_images=self.include_image,
)

async def _arun(
Expand All @@ -154,4 +184,9 @@ async def _arun(
depth=self.depth,
output_type=self.output_type,
structured_output_schema=self.structured_output_schema,
from_date=self.from_date,
to_date=self.to_date,
include_domains=self.include_domains,
exclude_domains=self.exclude_domains,
include_images=self.include_image,
)