mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-16 06:53:16 +00:00
experimental: docstrings update (#18048)
Added missed docstrings. Formatted docsctrings to the consistent format.
This commit is contained in:
@@ -15,6 +15,8 @@ from langchain_experimental.autonomous_agents.hugginggpt.task_planner import (
|
||||
|
||||
|
||||
class HuggingGPT:
|
||||
"""Agent for interacting with HuggingGPT."""
|
||||
|
||||
def __init__(self, llm: BaseLanguageModel, tools: List[BaseTool]):
|
||||
self.llm = llm
|
||||
self.tools = tools
|
||||
|
@@ -25,6 +25,8 @@ class ResponseGenerationChain(LLMChain):
|
||||
|
||||
|
||||
class ResponseGenerator:
|
||||
"""Generates a response based on the input."""
|
||||
|
||||
def __init__(self, llm_chain: LLMChain, stop: Optional[List] = None):
|
||||
self.llm_chain = llm_chain
|
||||
self.stop = stop
|
||||
@@ -36,6 +38,8 @@ class ResponseGenerator:
|
||||
|
||||
|
||||
def load_response_generator(llm: BaseLanguageModel) -> ResponseGenerator:
|
||||
"""Load the ResponseGenerator."""
|
||||
|
||||
llm_chain = ResponseGenerationChain.from_llm(llm)
|
||||
return ResponseGenerator(
|
||||
llm_chain=llm_chain,
|
||||
|
@@ -9,6 +9,8 @@ from langchain_experimental.autonomous_agents.hugginggpt.task_planner import Pla
|
||||
|
||||
|
||||
class Task:
|
||||
"""Task to be executed."""
|
||||
|
||||
def __init__(self, task: str, id: int, dep: List[int], args: Dict, tool: BaseTool):
|
||||
self.task = task
|
||||
self.id = id
|
||||
@@ -74,7 +76,7 @@ class Task:
|
||||
|
||||
|
||||
class TaskExecutor:
|
||||
"""Load tools to execute tasks."""
|
||||
"""Load tools and execute tasks."""
|
||||
|
||||
def __init__(self, plan: Plan):
|
||||
self.plan = plan
|
||||
|
@@ -76,6 +76,8 @@ class TaskPlaningChain(LLMChain):
|
||||
|
||||
|
||||
class Step:
|
||||
"""A step in the plan."""
|
||||
|
||||
def __init__(
|
||||
self, task: str, id: int, dep: List[int], args: Dict[str, str], tool: BaseTool
|
||||
):
|
||||
@@ -87,6 +89,8 @@ class Step:
|
||||
|
||||
|
||||
class Plan:
|
||||
"""A plan to execute."""
|
||||
|
||||
def __init__(self, steps: List[Step]):
|
||||
self.steps = steps
|
||||
|
||||
@@ -98,6 +102,8 @@ class Plan:
|
||||
|
||||
|
||||
class BasePlanner(BaseModel):
|
||||
"""Base class for a planner."""
|
||||
|
||||
@abstractmethod
|
||||
def plan(self, inputs: dict, callbacks: Callbacks = None, **kwargs: Any) -> Plan:
|
||||
"""Given input, decide what to do."""
|
||||
@@ -106,11 +112,22 @@ class BasePlanner(BaseModel):
|
||||
async def aplan(
|
||||
self, inputs: dict, callbacks: Callbacks = None, **kwargs: Any
|
||||
) -> Plan:
|
||||
"""Given input, decide what to do."""
|
||||
"""Asynchronous Given input, decide what to do."""
|
||||
|
||||
|
||||
class PlanningOutputParser(BaseModel):
|
||||
"""Parses the output of the planning stage."""
|
||||
|
||||
def parse(self, text: str, hf_tools: List[BaseTool]) -> Plan:
|
||||
"""Parse the output of the planning stage.
|
||||
|
||||
Args:
|
||||
text: The output of the planning stage.
|
||||
hf_tools: The tools available.
|
||||
|
||||
Returns:
|
||||
The plan.
|
||||
"""
|
||||
steps = []
|
||||
for v in json.loads(re.findall(r"\[.*\]", text)[0]):
|
||||
choose_tool = None
|
||||
@@ -124,6 +141,8 @@ class PlanningOutputParser(BaseModel):
|
||||
|
||||
|
||||
class TaskPlanner(BasePlanner):
|
||||
"""Planner for tasks."""
|
||||
|
||||
llm_chain: LLMChain
|
||||
output_parser: PlanningOutputParser
|
||||
stop: Optional[List] = None
|
||||
@@ -139,7 +158,7 @@ class TaskPlanner(BasePlanner):
|
||||
async def aplan(
|
||||
self, inputs: dict, callbacks: Callbacks = None, **kwargs: Any
|
||||
) -> Plan:
|
||||
"""Given input, decided what to do."""
|
||||
"""Asynchronous Given input, decided what to do."""
|
||||
inputs["hf_tools"] = [
|
||||
f"{tool.name}: {tool.description}" for tool in inputs["hf_tools"]
|
||||
]
|
||||
@@ -150,5 +169,7 @@ class TaskPlanner(BasePlanner):
|
||||
|
||||
|
||||
def load_chat_planner(llm: BaseLanguageModel) -> TaskPlanner:
|
||||
"""Load the chat planner."""
|
||||
|
||||
llm_chain = TaskPlaningChain.from_llm(llm)
|
||||
return TaskPlanner(llm_chain=llm_chain, output_parser=PlanningOutputParser())
|
||||
|
Reference in New Issue
Block a user