community: fix Google Scholar tool errors (#29371)

Resolve https://github.com/langchain-ai/langchain/issues/27557
This commit is contained in:
Terry Tan 2025-01-23 23:03:01 +08:00 committed by GitHub
parent a1e62070d0
commit ec0ebb76f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,7 @@ class GoogleScholarAPIWrapper(BaseModel):
hl: str = "en"
lr: str = "lang_en"
serp_api_key: Optional[str] = None
google_scholar_engine: Any = None
model_config = ConfigDict(
extra="forbid",
@ -55,7 +56,7 @@ class GoogleScholarAPIWrapper(BaseModel):
def validate_environment(cls, values: Dict) -> Any:
"""Validate that api key and python package exists in environment."""
serp_api_key = get_from_dict_or_env(values, "serp_api_key", "SERP_API_KEY")
values["SERP_API_KEY"] = serp_api_key
values["serp_api_key"] = serp_api_key
try:
from serpapi import GoogleScholarSearch