-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serpapi的配置项中增加搜索引擎的相关配置,以支持更多的搜索引擎如:bing, baidu 等 #957
Comments
class SerpAPIWrapper(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
search_engine: Any = None #: :meta private:
params: dict = Field(
default_factory=lambda: {
"engine": "google",
"google_domain": "google.com",
"gl": "us",
"hl": "en",
}
)
# should add `validate_default=True` to check with default value
serpapi_api_key: Optional[str] = Field(default=None, validate_default=True)
aiosession: Optional[aiohttp.ClientSession] = None 配置上去会自动生效的,源代码在 async def results(self, query: str, max_results: int) -> dict:
"""Use aiohttp to run query through SerpAPI and return the results async."""
def construct_url_and_params() -> Tuple[str, Dict[str, str]]:
params = self.get_params(query)
params["source"] = "python"
params["num"] = max_results
params["output"] = "json"
url = "https://serpapi.com/search"
return url, params
url, params = construct_url_and_params()
if not self.aiosession:
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params) as response:
response.raise_for_status()
res = await response.json()
else:
async with self.aiosession.get(url, params=params) as response:
response.raise_for_status()
res = await response.json()
return res
def get_params(self, query: str) -> Dict[str, str]:
"""Get parameters for SerpAPI."""
_params = {
"api_key": self.serpapi_api_key,
"q": query,
}
params = {**self.params, **_params}
return params |
我可能没有表达清楚,我的意思是可以通过配置文件去修改这些参数。 |
@redlion99 I have added the corresponding configuration. Can you take a look at the relevant PR and test whether it solves your problem? |
Due to the lack of updates or replies by the user for a long time, we will close it. Please reopen it if necessary. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在serpapi的配置项中能否增加搜索引擎的配置,以支持更多的搜索引擎如:bing, baidu 等

配置项的效果如下:
search:
api_type: 'serpapi' # serpapi/google/serper/ddg
api_key: 'xxxxx'
params:
engine: 'baidu'
ct: 2
The text was updated successfully, but these errors were encountered: