mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 06:23:20 +00:00
community[minor]: Add Datahareld tool (#19680)
**Description:** Integrate [dataherald](https://www.dataherald.com) tool, It is a natural language-to-SQL tool. **Dependencies:** Install dataherald sdk to use it, ``` pip install dataherald ``` --------- Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: Christophe Bornet <cbornet@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
ece008f117
commit
450c458f8f
36
libs/community/langchain_community/tools/dataherald/tool.py
Normal file
36
libs/community/langchain_community/tools/dataherald/tool.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Tool for the Dataherald Hosted 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.dataherald import DataheraldAPIWrapper
|
||||
|
||||
|
||||
class DataheraldTextToSQLInput(BaseModel):
|
||||
prompt: str = Field(
|
||||
description="Natural language query to be translated to a SQL query."
|
||||
)
|
||||
|
||||
|
||||
class DataheraldTextToSQL(BaseTool):
|
||||
"""Tool that queries using the Dataherald SDK."""
|
||||
|
||||
name: str = "dataherald"
|
||||
description: str = (
|
||||
"A wrapper around Dataherald. "
|
||||
"Text to SQL. "
|
||||
"Input should be a prompt and an existing db_connection_id"
|
||||
)
|
||||
api_wrapper: DataheraldAPIWrapper
|
||||
args_schema: Type[BaseModel] = DataheraldTextToSQLInput
|
||||
|
||||
def _run(
|
||||
self,
|
||||
prompt: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Dataherald tool."""
|
||||
return self.api_wrapper.run(prompt)
|
Reference in New Issue
Block a user