-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from FacerAin/feat/agent
[#14] Add ExecutorAgent
- Loading branch information
Showing
7 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .agent import ChatAgent | ||
from .agent import ExecutorAgent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Union | ||
|
||
import re | ||
|
||
from langchain.agents import AgentOutputParser | ||
from langchain.schema import AgentAction, AgentFinish, OutputParserException | ||
|
||
|
||
class CustomAgentOutputParser(AgentOutputParser): | ||
def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]: | ||
# Check if agent should finish | ||
if "Final Answer:" in llm_output: | ||
return AgentFinish( | ||
# Return values is generally always a dictionary with a single `output` key | ||
# It is not recommended to try anything else at the moment :) | ||
return_values={"output": llm_output.split("Final Answer:")[-1].strip()}, | ||
log=llm_output, | ||
) | ||
# Parse out the action and action input | ||
regex = r"Action\s*\d*\s*:(.*?)\nAction\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)" | ||
match = re.search(regex, llm_output, re.DOTALL) | ||
if not match: | ||
raise OutputParserException(f"Could not parse LLM output: `{llm_output}`") | ||
action = match.group(1).strip() | ||
action_input = match.group(2) | ||
# Return the action and action input | ||
return AgentAction(tool=action, tool_input=action_input.strip(" ").strip('"'), log=llm_output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
langchain==0.0.310 | ||
langchain==0.0.346 | ||
fastapi==0.103.0 | ||
uvicorn==0.23.2 | ||
pinecone-client==2.2.4 | ||
|