-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simple agent and maketool * forgot to change prompt, oops * renamed prompt * maketool module issue
- Loading branch information
Showing
5 changed files
with
65 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from agent import SanCloneAgent | ||
|
||
__all__ = ["SanCloneAgent"] |
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,41 @@ | ||
from langchain.agents import AgentExecutor, ZeroShotAgent | ||
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent | ||
from langchain.chat_models import ChatOpenAI | ||
|
||
from ..tools import make_tools | ||
from .prompt import prompt_template | ||
|
||
|
||
class AgentType: | ||
valid_models = { | ||
"ReactAgent": ZeroShotAgent, | ||
"OpenAIFunctionsAgent": OpenAIFunctionsAgent, | ||
} | ||
|
||
@classmethod | ||
def get_agent(cls, model_name: str = "ReactAgent"): | ||
return cls.valid_models[model_name] | ||
|
||
|
||
class SanCloneAgent: | ||
def __init__( | ||
self, | ||
tools=None, | ||
llm=None, | ||
openai_api_key=None, | ||
temp=0.1, | ||
agent_type: str = "OpenAIFunctionsAgent", | ||
verbose=True, | ||
): | ||
llm = ChatOpenAI(temperature=0.0, model="gpt-4", client=None) | ||
|
||
tools = make_tools(llm) | ||
self.agent_instance = AgentExecutor.from_agent_and_tools( | ||
tools=tools, | ||
agent=AgentType.get_agent(agent_type).from_llm_and_tools(llm, tools), | ||
return_intermediate_steps=True, | ||
handle_parsing_errors=True, | ||
) | ||
|
||
def run(self, prompt: str): | ||
return self.agent_instance.run(prompt_template.format(input=prompt)) |
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,8 @@ | ||
# flake8: noqa | ||
prompt_template = """ | ||
You are an expert in molecular cloning. | ||
You have a set of tools at your disposal. | ||
Your task is to respond to the question or | ||
solve the problem to the best of your ability using the provided tools. | ||
Here is the question: {input} | ||
""" |
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,3 +1,4 @@ | ||
from .echo import EchoTool | ||
from .maketools import make_tools | ||
|
||
__all__ = ["EchoTool"] | ||
__all__ = ["EchoTool", "make_tools"] |
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,11 @@ | ||
from langchain import agents | ||
from langchain.llms.base import BaseLanguageModel | ||
|
||
|
||
def make_tools(llm: BaseLanguageModel): | ||
# add human input tool | ||
tools = agents.load_tools(["human"], llm) | ||
|
||
# append tools here | ||
tools += [] | ||
return tools |