mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-21 00:35:23 -04:00
82baecc892
This PR adds * `ZeroShotAgent.as_sql_agent`, which returns an agent for interacting with a sql database. This builds off of `SQLDatabaseChain`. The main advantages are 1) answering general questions about the db, 2) access to a tool for double checking queries, and 3) recovering from errors * `ZeroShotAgent.as_json_agent` which returns an agent for interacting with json blobs. * Several examples in notebooks --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
31 lines
927 B
Python
31 lines
927 B
Python
"""A tool for running python code in a REPL."""
|
|
|
|
from pydantic import Field
|
|
|
|
from langchain.python import PythonREPL
|
|
from langchain.tools.base import BaseTool
|
|
|
|
|
|
def _get_default_python_repl() -> PythonREPL:
|
|
return PythonREPL(_globals=globals(), _locals=None)
|
|
|
|
|
|
class PythonREPLTool(BaseTool):
|
|
"""A tool for running python code in a REPL."""
|
|
|
|
name = "Python REPL"
|
|
description = (
|
|
"A Python shell. Use this to execute python commands. "
|
|
"Input should be a valid python command. "
|
|
"If you expect output it should be printed out."
|
|
)
|
|
python_repl: PythonREPL = Field(default_factory=_get_default_python_repl)
|
|
|
|
def _run(self, query: str) -> str:
|
|
"""Use the tool."""
|
|
return self.python_repl.run(query)
|
|
|
|
async def _arun(self, query: str) -> str:
|
|
"""Use the tool asynchronously."""
|
|
raise NotImplementedError("PythonReplTool does not support async")
|