MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / build_runner

Method build_runner

bmtools/agent/tools_controller.py:74–114  ·  view source on GitHub ↗
(self, )

Source from the content-addressed store, hash-verified

72 self.tools_pool.append(tool)
73
74 def build_runner(self, ):
75 from langchain.vectorstores import FAISS
76 from langchain.docstore import InMemoryDocstore
77 from langchain.embeddings import OpenAIEmbeddings
78 embeddings_model = OpenAIEmbeddings()
79 import faiss
80 embedding_size = 1536
81 index = faiss.IndexFlatL2(embedding_size)
82 vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {})
83
84 from .autogptmulti.agent import AutoGPT
85 from langchain.chat_models import ChatOpenAI
86 agent_executor = AutoGPT.from_llm_and_tools(
87 ai_name="Tom",
88 ai_role="Assistant",
89 tools=self.tools_pool,
90 llm=ChatOpenAI(temperature=0),
91 memory=vectorstore.as_retriever()
92 )
93 '''
94 # 可以修改prompt来让模型表现更好,也可以修改tool的doc
95 prefix = """Answer the following questions as best you can. In this level, you are calling the tools in natural language format, since the tools are actually an intelligent agent like you, but they expert only in one area. Several things to remember. (1) Remember to follow the format of passing natural language as the Action Input. (2) DO NOT use your imagination, only use concrete information given by the tools. (3) If the observation contains images or urls which has useful information, YOU MUST INCLUDE ALL USEFUL IMAGES and links in your Answer and Final Answers using format ![img](url). BUT DO NOT provide any imaginary links. (4) The information in your Final Answer should include ALL the informations returned by the tools. (5) If a user's query is a language other than English, please translate it to English without tools, and translate it back to the source language in Final Answer. You have access to the following tools (Only use these tools we provide you):"""
96 suffix = """\nBegin! Remember to . \nQuestion: {input}\n{agent_scratchpad}"""
97
98
99 prompt = ZeroShotAgent.create_prompt(
100 self.tools_pool,
101 prefix=prefix,
102 suffix=suffix,
103 input_variables=["input", "agent_scratchpad"]
104 )
105 llm_chain = LLMChain(llm=self.llm, prompt=prompt)
106 logger.info("Full Prompt Template:\n {}".format(prompt.template))
107 tool_names = [tool.name for tool in self.tools_pool]
108 agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names)
109 if self.stream_output:
110 agent_executor = Executor.from_agent_and_tools(agent=agent, tools=self.tools_pool, verbose=True, return_intermediate_steps=True)
111 else:
112 agent_executor = AgentExecutorWithTranslation.from_agent_and_tools(agent=agent, tools=self.tools_pool, verbose=True, return_intermediate_steps=True)
113 '''
114 return agent_executor
115
116
117

Callers 4

answer_by_toolsFunction · 0.95
multi_test.pyFile · 0.80
test_multi.pyFile · 0.80

Calls 1

from_llm_and_toolsMethod · 0.45

Tested by

no test coverage detected