-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainold.py
More file actions
72 lines (59 loc) · 1.77 KB
/
mainold.py
File metadata and controls
72 lines (59 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 加载环境变量
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
from Agent.AutoGPT import AutoGPT
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_community.vectorstores import Chroma
from langchain.schema import Document
from Tools import *
from Tools.PythonTool import ExcelAnalyser
def launch_agent(agent: AutoGPT):
human_icon = "\U0001F468"
ai_icon = "\U0001F916"
while True:
task = input(f"{ai_icon}:有什么可以帮您?\n{human_icon}:")
if task.strip().lower() == "quit":
break
reply = agent.run(task, verbose=True)
print(f"{ai_icon}:{reply}\n")
def main():
# 语言模型
llm = ChatOpenAI(
model="gpt-4-1106-preview",
temperature=0,
model_kwargs={
"seed": 42
},
)
# 存储长时记忆的向量数据库
db = Chroma.from_documents([Document(page_content="")], OpenAIEmbeddings(model="text-embedding-ada-002"))
retriever = db.as_retriever(
search_kwargs={"k": 1}
)
# 自定义工具集
tools = [
document_qa_tool,
document_generation_tool,
email_tool,
excel_inspection_tool,
directory_inspection_tool,
finish_placeholder,
ExcelAnalyser(
prompt_file="./prompts/tools/excel_analyser.txt",
verbose=True
).as_tool()
]
# 定义智能体
agent = AutoGPT(
llm=llm,
tools=tools,
work_dir="./data",
main_prompt_file="./prompts/main/main.txt",
final_prompt_file="./prompts/main/final_step.txt",
max_thought_steps=20,
memery_retriever=retriever
)
# 运行智能体
launch_agent(agent)
if __name__ == "__main__":
main()