Skip to content

Commit 67808ba

Browse files
authored
expose more serpapi parameters (#609)
1 parent b7225fd commit 67808ba

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

langchain/serpapi.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from typing import Any, Dict, Optional
88

9-
from pydantic import BaseModel, Extra, root_validator
9+
from pydantic import BaseModel, Extra, Field, root_validator
1010

1111
from langchain.utils import get_from_dict_or_env
1212

@@ -25,6 +25,15 @@ def __exit__(self, *_: Any) -> None:
2525
sys.stdout = self._original_stdout
2626

2727

28+
def _get_default_params() -> dict:
29+
return {
30+
"engine": "google",
31+
"google_domain": "google.com",
32+
"gl": "us",
33+
"hl": "en",
34+
}
35+
36+
2837
class SerpAPIWrapper(BaseModel):
2938
"""Wrapper around SerpAPI.
3039
@@ -40,7 +49,7 @@ class SerpAPIWrapper(BaseModel):
4049
"""
4150

4251
search_engine: Any #: :meta private:
43-
52+
params: dict = Field(default_factory=_get_default_params)
4453
serpapi_api_key: Optional[str] = None
4554

4655
class Config:
@@ -68,14 +77,11 @@ def validate_environment(cls, values: Dict) -> Dict:
6877

6978
def run(self, query: str) -> str:
7079
"""Run query through SerpAPI and parse result."""
71-
params = {
80+
_params = {
7281
"api_key": self.serpapi_api_key,
73-
"engine": "google",
7482
"q": query,
75-
"google_domain": "google.com",
76-
"gl": "us",
77-
"hl": "en",
7883
}
84+
params = {**self.params, **_params}
7985
with HiddenPrints():
8086
search = self.search_engine(params)
8187
res = search.get_dict()

0 commit comments

Comments
 (0)