Introduce search_kwargs for Custom Parameters in BingSearchAPIWrapper (#13525)

Added a `search_kwargs` field to BingSearchAPIWrapper in
`bing_search.py,` enabling users to include extra keyword arguments in
Bing search queries. This update, like specifying language preferences,
adds more customization to searches. The `search_kwargs` seamlessly
merge with standard parameters in `_bing_search_results` method.

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
shumpei 2023-11-20 10:51:02 +09:00 committed by GitHub
parent ad0c3b9479
commit 7100d586ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ from typing import Dict, List
import requests
from langchain.pydantic_v1 import BaseModel, Extra, root_validator
from langchain.pydantic_v1 import BaseModel, Extra, Field, root_validator
from langchain.utils import get_from_dict_or_env
@ -21,6 +21,8 @@ class BingSearchAPIWrapper(BaseModel):
bing_subscription_key: str
bing_search_url: str
k: int = 10
search_kwargs: dict = Field(default_factory=dict)
"""Additional keyword arguments to pass to the search request."""
class Config:
"""Configuration for this pydantic object."""
@ -34,6 +36,7 @@ class BingSearchAPIWrapper(BaseModel):
"count": count,
"textDecorations": True,
"textFormat": "HTML",
**self.search_kwargs,
}
response = requests.get(
self.bing_search_url,