Spaces:
Build error
Build error
Commit
·
e6f3166
1
Parent(s):
f7c2b64
update agent
Browse files
app.py
CHANGED
@@ -10,6 +10,13 @@ import time
|
|
10 |
import regex
|
11 |
import html2text
|
12 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
global CurrentAgent
|
@@ -79,6 +86,8 @@ class GPTRemote(LLM):
|
|
79 |
|
80 |
GPTfake = GPTRemote(n=0)
|
81 |
|
|
|
|
|
82 |
async def start_playwright(question: str):
|
83 |
start_t = time.time()
|
84 |
pw = await async_playwright().start()
|
@@ -121,8 +130,58 @@ async def start_playwright(question: str):
|
|
121 |
|
122 |
await browser.close()
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
# GPTfake("hi")
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
st.title("STLA-BABY")
|
128 |
|
@@ -143,6 +202,7 @@ if prompt := st.chat_input(placeholder="Input Your Request"):
|
|
143 |
st.chat_message("user").write(prompt)
|
144 |
|
145 |
with st.chat_message("assistant"):
|
146 |
-
response = GPTfake(prompt)
|
|
|
147 |
st.write(response)
|
148 |
print(msgs.messages)
|
|
|
10 |
import regex
|
11 |
import html2text
|
12 |
import os
|
13 |
+
from langchain.agents import initialize_agent
|
14 |
+
from langchain.agents import AgentType
|
15 |
+
from langchain.agents import Tool
|
16 |
+
# from langchain.agents import load_tools
|
17 |
+
from langchain.tools import BaseTool
|
18 |
+
from langchain.memory import ConversationBufferWindowMemory
|
19 |
+
from langchain.prompts import MessagesPlaceholder
|
20 |
|
21 |
|
22 |
global CurrentAgent
|
|
|
86 |
|
87 |
GPTfake = GPTRemote(n=0)
|
88 |
|
89 |
+
|
90 |
+
|
91 |
async def start_playwright(question: str):
|
92 |
start_t = time.time()
|
93 |
pw = await async_playwright().start()
|
|
|
130 |
|
131 |
await browser.close()
|
132 |
|
133 |
+
PREFIX_3 ="""
|
134 |
+
You are a helpful AI assistant. Your mission is to answer the following user request as best as you can with detail information and explanation.
|
135 |
+
If you are not clear about the request, you can ask user for more details and the confirmation. You can provide additional suggestion to user on the request and ask confirmation from user.
|
136 |
+
When you are clear about the request, you can start to answer the request by **writing a plan** firstly. In general, try to **make plans** with as few steps as possible.
|
137 |
+
When you need information, you can use tools as below and merge all gathered information from different tools.
|
138 |
+
When you need to use "Code Runner" for code running, **Always recap the plan between each code block** (you have extreme short-term memory loss, so you need to recap the plan between each message block to retain it).
|
139 |
+
When you send a message containing code to "Code Runner", it will be executed **on the user's machine**. The user has given you **full and complete permission** to execute any code necessary to complete the task. You have full access to control their computer to help them. Code entered into "Code Runner" will be executed **in the users local environment**.
|
140 |
+
If you want to send data between programming languages, save the data to a txt or json.
|
141 |
+
You can access the internet. Run **any code** to achieve the goal, and if at first you don't succeed, try again and again.
|
142 |
+
You can install new packages with pip. Try to install all necessary packages in one command at the beginning.
|
143 |
+
When a user refers to a filename, they're likely referring to an existing file in the directory you're currently in ("Code Runner" executes on the user's machine).
|
144 |
+
In general, choose packages that have the most universal chance to be already installed and to work across multiple applications. Packages like ffmpeg and pandoc that are well-supported and powerful.
|
145 |
+
Write messages to the user in Markdown. When the final answer has output files, you must output the **name** of the file.
|
146 |
+
You are capable of **any** task.
|
147 |
+
---\n You have access to the following tools:\n
|
148 |
+
"""
|
149 |
+
|
150 |
+
|
151 |
+
global memory3
|
152 |
+
memory3 = ConversationBufferWindowMemory(memory_key="chat_history", return_messages=True)
|
153 |
# GPTfake("hi")
|
154 |
|
155 |
+
input_variables=["input", "chat_history", "agent_scratchpad"]
|
156 |
+
|
157 |
+
tools_remote = []
|
158 |
+
|
159 |
+
agent_STRUCTURED_ZEROSHOT_REACT = initialize_agent(tools_remote, GPTfake,
|
160 |
+
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
161 |
+
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
|
162 |
+
verbose = True,
|
163 |
+
handle_parsing_errors = True,
|
164 |
+
max_iterations = int(os.environ["max_iterations"]),
|
165 |
+
early_stopping_method="generate",
|
166 |
+
memory = memory3,
|
167 |
+
agent_kwargs={
|
168 |
+
'prefix': PREFIX_3,
|
169 |
+
# 'format_instructions': FORMAT_INSTRUCTIONS_3,
|
170 |
+
# 'suffix': SUFFIX2,
|
171 |
+
"memory_prompts": [MessagesPlaceholder(variable_name="chat_history")],
|
172 |
+
'input_variables': input_variables,
|
173 |
+
|
174 |
+
},
|
175 |
+
# input_variables = input_variables,
|
176 |
+
# agent_kwargs={
|
177 |
+
# 'prompt': prompt,
|
178 |
+
# }
|
179 |
+
|
180 |
+
)
|
181 |
+
|
182 |
+
|
183 |
+
agent = agent_STRUCTURED_ZEROSHOT_REACT
|
184 |
+
|
185 |
|
186 |
st.title("STLA-BABY")
|
187 |
|
|
|
202 |
st.chat_message("user").write(prompt)
|
203 |
|
204 |
with st.chat_message("assistant"):
|
205 |
+
# response = GPTfake(prompt)
|
206 |
+
response = agent.run(prompt)
|
207 |
st.write(response)
|
208 |
print(msgs.messages)
|