langchain.utilities.metaphor_search.MetaphorSearchAPIWrapper¶

class langchain.utilities.metaphor_search.MetaphorSearchAPIWrapper(*, metaphor_api_key: str, k: int = 10)[source]¶

Bases: BaseModel

Wrapper for Metaphor Search API.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param k: int = 10¶
param metaphor_api_key: str [Required]¶
results(query: str, num_results: int, include_domains: Optional[List[str]] = None, exclude_domains: Optional[List[str]] = None, start_crawl_date: Optional[str] = None, end_crawl_date: Optional[str] = None, start_published_date: Optional[str] = None, end_published_date: Optional[str] = None, use_autoprompt: Optional[bool] = None) List[Dict][source]¶

Run query through Metaphor Search and return metadata.

Parameters
  • query – The query to search for.

  • num_results – The number of results to return.

  • include_domains – A list of domains to include in the search. Only one of include_domains and exclude_domains should be defined.

  • exclude_domains – A list of domains to exclude from the search. Only one of include_domains and exclude_domains should be defined.

  • start_crawl_date – If specified, only pages we crawled after start_crawl_date will be returned.

  • end_crawl_date – If specified, only pages we crawled before end_crawl_date will be returned.

  • start_published_date – If specified, only pages published after start_published_date will be returned.

  • end_published_date – If specified, only pages published before end_published_date will be returned.

  • use_autoprompt – If true, we turn your query into a more Metaphor-friendly query. Adds latency.

Returns

title - The title of the page url - The url author - Author of the content, if applicable. Otherwise, None. published_date - Estimated date published

in YYYY-MM-DD format. Otherwise, None.

Return type

A list of dictionaries with the following keys

async results_async(query: str, num_results: int, include_domains: Optional[List[str]] = None, exclude_domains: Optional[List[str]] = None, start_crawl_date: Optional[str] = None, end_crawl_date: Optional[str] = None, start_published_date: Optional[str] = None, end_published_date: Optional[str] = None, use_autoprompt: Optional[bool] = None) List[Dict][source]¶

Get results from the Metaphor Search API asynchronously.

validator validate_environment  »  all fields[source]¶

Validate that api key and endpoint exists in environment.

model Config[source]¶

Bases: object

Configuration for this pydantic object.

extra = 'forbid'¶

Examples using MetaphorSearchAPIWrapper¶