Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -127,7 +127,7 @@ def compress_data(c,purpose, task, history, result):
|
|
| 127 |
resp = run_gpt(
|
| 128 |
COMPRESS_DATA_PROMPT,
|
| 129 |
stop_tokens=["observation:", "task:", "action:", "thought:"],
|
| 130 |
-
max_tokens=
|
| 131 |
seed=seed,
|
| 132 |
purpose=purpose,
|
| 133 |
task=task,
|
|
@@ -162,7 +162,7 @@ def compress_history(purpose, task, history):
|
|
| 162 |
resp = run_gpt(
|
| 163 |
COMPRESS_HISTORY_PROMPT,
|
| 164 |
stop_tokens=["observation:", "task:", "action:", "thought:"],
|
| 165 |
-
max_tokens=
|
| 166 |
seed=random.randint(1,1000000000),
|
| 167 |
purpose=purpose,
|
| 168 |
task=task,
|
|
@@ -176,7 +176,7 @@ def call_main(purpose, task, history, action_input, result):
|
|
| 176 |
resp = run_gpt(
|
| 177 |
FINDER,
|
| 178 |
stop_tokens=["observation:", "task:"],
|
| 179 |
-
max_tokens=
|
| 180 |
seed=random.randint(1,1000000000),
|
| 181 |
purpose=purpose,
|
| 182 |
task=task,
|
|
@@ -230,58 +230,47 @@ def search_all(url):
|
|
| 230 |
def find_all(purpose,task,history, url, result):
|
| 231 |
return_list=[]
|
| 232 |
print (url)
|
| 233 |
-
#if action_input in query.tasks:
|
| 234 |
print (f"trying URL:: {url}")
|
| 235 |
try:
|
| 236 |
if url != "" and url != None:
|
| 237 |
-
#rawp = []
|
| 238 |
out = []
|
| 239 |
source = requests.get(url)
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
c +=1
|
| 272 |
-
print (f'c:: {c}')
|
| 273 |
-
if c > MAX_HISTORY:
|
| 274 |
-
print("compressing...")
|
| 275 |
-
rawp = compress_data(c,purpose,task,out,result)
|
| 276 |
else:
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
print (f'out:: {out}')
|
| 282 |
-
history += "observation: the search results are:\n {}\n".format(rawp)
|
| 283 |
-
task = "compile report or complete?"
|
| 284 |
-
return "MAIN", None, history, task, result
|
| 285 |
else:
|
| 286 |
history += "observation: An Error occured\nI need to trigger a search using the following syntax:\naction: SCRAPE_WEBSITE action_input=URL\n"
|
| 287 |
return "MAIN", None, history, task, result
|
|
@@ -330,6 +319,7 @@ def run_action(purpose, task, history, action_name, action_input,result):
|
|
| 330 |
return "MAIN", None, history, task, result
|
| 331 |
|
| 332 |
def run(purpose,history):
|
|
|
|
| 333 |
task=None
|
| 334 |
result=""
|
| 335 |
#history = ""
|
|
@@ -357,7 +347,11 @@ def run(purpose,history):
|
|
| 357 |
action_input,
|
| 358 |
result
|
| 359 |
)
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
if action_name == "COMPLETE":
|
| 362 |
break
|
| 363 |
return result
|
|
@@ -401,5 +395,4 @@ with gr.Blocks() as app:
|
|
| 401 |
find_btn.click(find_it,[inp,q,num],[outp,outl])
|
| 402 |
|
| 403 |
app.launch()
|
| 404 |
-
|
| 405 |
'''
|
|
|
|
| 127 |
resp = run_gpt(
|
| 128 |
COMPRESS_DATA_PROMPT,
|
| 129 |
stop_tokens=["observation:", "task:", "action:", "thought:"],
|
| 130 |
+
max_tokens=2048,
|
| 131 |
seed=seed,
|
| 132 |
purpose=purpose,
|
| 133 |
task=task,
|
|
|
|
| 162 |
resp = run_gpt(
|
| 163 |
COMPRESS_HISTORY_PROMPT,
|
| 164 |
stop_tokens=["observation:", "task:", "action:", "thought:"],
|
| 165 |
+
max_tokens=1024,
|
| 166 |
seed=random.randint(1,1000000000),
|
| 167 |
purpose=purpose,
|
| 168 |
task=task,
|
|
|
|
| 176 |
resp = run_gpt(
|
| 177 |
FINDER,
|
| 178 |
stop_tokens=["observation:", "task:"],
|
| 179 |
+
max_tokens=2048,
|
| 180 |
seed=random.randint(1,1000000000),
|
| 181 |
purpose=purpose,
|
| 182 |
task=task,
|
|
|
|
| 230 |
def find_all(purpose,task,history, url, result):
|
| 231 |
return_list=[]
|
| 232 |
print (url)
|
|
|
|
| 233 |
print (f"trying URL:: {url}")
|
| 234 |
try:
|
| 235 |
if url != "" and url != None:
|
|
|
|
| 236 |
out = []
|
| 237 |
source = requests.get(url)
|
| 238 |
+
if source.status_code ==200:
|
| 239 |
+
soup = bs4.BeautifulSoup(source.content,'lxml')
|
| 240 |
+
|
| 241 |
+
rawp=(f'RAW TEXT RETURNED: {soup.text}')
|
| 242 |
+
cnt=0
|
| 243 |
+
cnt+=len(rawp)
|
| 244 |
+
out.append(rawp)
|
| 245 |
+
out.append("HTML fragments: ")
|
| 246 |
+
q=("a","p","span","content","article")
|
| 247 |
+
for p in soup.find_all("a"):
|
| 248 |
+
out.append([{"LINK TITLE":p.get('title'),"URL":p.get('href'),"STRING":p.string}])
|
| 249 |
+
c=0
|
| 250 |
+
out = str(out)
|
| 251 |
+
rl = len(out)
|
| 252 |
+
print(f'rl:: {rl}')
|
| 253 |
+
for i in str(out):
|
| 254 |
+
if i == " " or i=="," or i=="\n" or i=="/" or i=="." or i=="<":
|
| 255 |
+
c +=1
|
| 256 |
+
print (f'c:: {c}')
|
| 257 |
+
if c > MAX_HISTORY:
|
| 258 |
+
print("compressing...")
|
| 259 |
+
rawp = compress_data(c,purpose,task,out,result)
|
| 260 |
+
result += rawp
|
| 261 |
+
else:
|
| 262 |
+
rawp = out
|
| 263 |
+
|
| 264 |
+
#print (rawp)
|
| 265 |
+
#print (f'out:: {out}')
|
| 266 |
+
history += "observation: the search results are:\n {}\n".format(rawp)
|
| 267 |
+
task = "compile report or complete?"
|
| 268 |
+
return "MAIN", None, history, task, result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
else:
|
| 270 |
+
history += f"observation: That URL string returned an error: {source.status_code}, I should try a different URL string\n"
|
| 271 |
+
result="Still Working..."
|
| 272 |
+
return "MAIN", None, history, task, result
|
| 273 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
else:
|
| 275 |
history += "observation: An Error occured\nI need to trigger a search using the following syntax:\naction: SCRAPE_WEBSITE action_input=URL\n"
|
| 276 |
return "MAIN", None, history, task, result
|
|
|
|
| 319 |
return "MAIN", None, history, task, result
|
| 320 |
|
| 321 |
def run(purpose,history):
|
| 322 |
+
yield "Searching..."
|
| 323 |
task=None
|
| 324 |
result=""
|
| 325 |
#history = ""
|
|
|
|
| 347 |
action_input,
|
| 348 |
result
|
| 349 |
)
|
| 350 |
+
|
| 351 |
+
if not result:
|
| 352 |
+
yield "More Searching..."
|
| 353 |
+
else:
|
| 354 |
+
yield result
|
| 355 |
if action_name == "COMPLETE":
|
| 356 |
break
|
| 357 |
return result
|
|
|
|
| 395 |
find_btn.click(find_it,[inp,q,num],[outp,outl])
|
| 396 |
|
| 397 |
app.launch()
|
|
|
|
| 398 |
'''
|