mirror of
https://github.com/hwchase17/langchain
synced 2024-11-11 19:11:02 +00:00
e1c2cd7a28
- **Description:** Tool now supports querying over 200 million scientific articles, vastly expanding its reach beyond the 2 million articles accessible through Arxiv. This update significantly broadens access to the entire scope of scientific literature. - **Dependencies:** semantischolar https://github.com/danielnsilva/semanticscholar - **Twitter handle:** @shauryr --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Tool for the SemanticScholar API."""
|
|
|
|
from typing import Optional, Type
|
|
|
|
from langchain_core.callbacks import CallbackManagerForToolRun
|
|
from langchain_core.pydantic_v1 import BaseModel, Field
|
|
from langchain_core.tools import BaseTool
|
|
|
|
from langchain_community.utilities.semanticscholar import SemanticScholarAPIWrapper
|
|
|
|
|
|
class SemantscholarInput(BaseModel):
|
|
"""Input for the SemanticScholar tool."""
|
|
|
|
query: str = Field(description="search query to look up")
|
|
|
|
|
|
class SemanticScholarQueryRun(BaseTool):
|
|
"""Tool that searches the semanticscholar API."""
|
|
|
|
name: str = "semanticscholar"
|
|
description: str = (
|
|
"A wrapper around semantischolar.org "
|
|
"Useful for when you need to answer to questions"
|
|
"from research papers."
|
|
"Input should be a search query."
|
|
)
|
|
api_wrapper: SemanticScholarAPIWrapper = Field(
|
|
default_factory=SemanticScholarAPIWrapper
|
|
)
|
|
args_schema: Type[BaseModel] = SemantscholarInput
|
|
|
|
def _run(
|
|
self,
|
|
query: str,
|
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
) -> str:
|
|
"""Use the Semantic Scholar tool."""
|
|
return self.api_wrapper.run(query)
|