6
6
import sys
7
7
from typing import Any , Dict , Optional
8
8
9
- from pydantic import BaseModel , Extra , root_validator
9
+ from pydantic import BaseModel , Extra , Field , root_validator
10
10
11
11
from langchain .utils import get_from_dict_or_env
12
12
@@ -25,6 +25,15 @@ def __exit__(self, *_: Any) -> None:
25
25
sys .stdout = self ._original_stdout
26
26
27
27
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
+
28
37
class SerpAPIWrapper (BaseModel ):
29
38
"""Wrapper around SerpAPI.
30
39
@@ -40,7 +49,7 @@ class SerpAPIWrapper(BaseModel):
40
49
"""
41
50
42
51
search_engine : Any #: :meta private:
43
-
52
+ params : dict = Field ( default_factory = _get_default_params )
44
53
serpapi_api_key : Optional [str ] = None
45
54
46
55
class Config :
@@ -68,14 +77,11 @@ def validate_environment(cls, values: Dict) -> Dict:
68
77
69
78
def run (self , query : str ) -> str :
70
79
"""Run query through SerpAPI and parse result."""
71
- params = {
80
+ _params = {
72
81
"api_key" : self .serpapi_api_key ,
73
- "engine" : "google" ,
74
82
"q" : query ,
75
- "google_domain" : "google.com" ,
76
- "gl" : "us" ,
77
- "hl" : "en" ,
78
83
}
84
+ params = {** self .params , ** _params }
79
85
with HiddenPrints ():
80
86
search = self .search_engine (params )
81
87
res = search .get_dict ()
0 commit comments