Skip to content

Commit

Permalink
simple agent and maketool (#3)
Browse files Browse the repository at this point in the history
* simple agent and maketool

* forgot to change prompt, oops

* renamed prompt

* maketool module issue
  • Loading branch information
SamCox822 authored Oct 6, 2023
1 parent 5619393 commit a453236
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sanclone/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from agent import SanCloneAgent

__all__ = ["SanCloneAgent"]
41 changes: 41 additions & 0 deletions sanclone/agent/agent.py
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))
8 changes: 8 additions & 0 deletions sanclone/agent/prompt.py
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}
"""
3 changes: 2 additions & 1 deletion sanclone/tools/__init__.py
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"]
11 changes: 11 additions & 0 deletions sanclone/tools/maketools.py
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

0 comments on commit a453236

Please sign in to comment.