Spaces:
Paused
Paused
chore: update something
Browse files
app.py
CHANGED
@@ -293,6 +293,12 @@ supported_tools = json.dumps(
|
|
293 |
"default": "google",
|
294 |
"required": True,
|
295 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
},
|
297 |
},
|
298 |
},
|
@@ -311,10 +317,16 @@ def extract_text_from_webpage(html_content):
|
|
311 |
return visible_text
|
312 |
|
313 |
|
314 |
-
def search_with_wikipedia(
|
|
|
|
|
|
|
315 |
all_results = []
|
316 |
try:
|
317 |
-
|
|
|
|
|
|
|
318 |
except Exception as e:
|
319 |
pass
|
320 |
return all_results
|
@@ -324,6 +336,7 @@ def search_with_google(
|
|
324 |
query: str,
|
325 |
num_results: int = 3,
|
326 |
timeout: int = 5,
|
|
|
327 |
ssl_verify: bool = None,
|
328 |
):
|
329 |
all_results = []
|
@@ -338,6 +351,7 @@ def search_with_google(
|
|
338 |
"q": query,
|
339 |
"num": num_results,
|
340 |
"udm": 14,
|
|
|
341 |
},
|
342 |
timeout=timeout,
|
343 |
verify=ssl_verify,
|
@@ -452,12 +466,20 @@ def generate(
|
|
452 |
):
|
453 |
keyword = scheduled_tools_runs["arguments"]["keyword"]
|
454 |
search_type = scheduled_tools_runs["arguments"]["type"]
|
|
|
455 |
if search_type == "wikipedia":
|
456 |
gr.Info("Searching for information on the Wikipedia.")
|
457 |
-
document_references = search_with_wikipedia(
|
|
|
|
|
458 |
else:
|
459 |
gr.Info("Searching for information on the Google.")
|
460 |
-
document_references = search_with_google(
|
|
|
|
|
|
|
|
|
|
|
461 |
|
462 |
apply_tools = (
|
463 |
True if allow_used_tools is True and previous_response is None else False
|
@@ -507,7 +529,6 @@ def generate(
|
|
507 |
and state["respond"] is False
|
508 |
and state["mark"] + waiting_tools_timeout > time.time()
|
509 |
):
|
510 |
-
gr.Info("Searching for information on the internet.")
|
511 |
previous_response = "".join(outputs)
|
512 |
yield from generate_chat_responses(previous_response=previous_response)
|
513 |
|
|
|
293 |
"default": "google",
|
294 |
"required": True,
|
295 |
},
|
296 |
+
"language": {
|
297 |
+
"type": "string",
|
298 |
+
"description": "Search language, is the user language code with 2 letters, e.g: vi = vietnamese, en = english.",
|
299 |
+
"default": "en",
|
300 |
+
"required": True,
|
301 |
+
},
|
302 |
},
|
303 |
},
|
304 |
},
|
|
|
317 |
return visible_text
|
318 |
|
319 |
|
320 |
+
def search_with_wikipedia(
|
321 |
+
query: str,
|
322 |
+
language: str = "en",
|
323 |
+
):
|
324 |
all_results = []
|
325 |
try:
|
326 |
+
wikipedia.set_lang(language)
|
327 |
+
page = wikipedia.page(query)
|
328 |
+
content = page.content[:5120]
|
329 |
+
all_results.append(content)
|
330 |
except Exception as e:
|
331 |
pass
|
332 |
return all_results
|
|
|
336 |
query: str,
|
337 |
num_results: int = 3,
|
338 |
timeout: int = 5,
|
339 |
+
language: str = "en",
|
340 |
ssl_verify: bool = None,
|
341 |
):
|
342 |
all_results = []
|
|
|
351 |
"q": query,
|
352 |
"num": num_results,
|
353 |
"udm": 14,
|
354 |
+
"hl": language,
|
355 |
},
|
356 |
timeout=timeout,
|
357 |
verify=ssl_verify,
|
|
|
466 |
):
|
467 |
keyword = scheduled_tools_runs["arguments"]["keyword"]
|
468 |
search_type = scheduled_tools_runs["arguments"]["type"]
|
469 |
+
language = scheduled_tools_runs["arguments"]["language"]
|
470 |
if search_type == "wikipedia":
|
471 |
gr.Info("Searching for information on the Wikipedia.")
|
472 |
+
document_references = search_with_wikipedia(
|
473 |
+
query=keyword, language=language
|
474 |
+
)
|
475 |
else:
|
476 |
gr.Info("Searching for information on the Google.")
|
477 |
+
document_references = search_with_google(
|
478 |
+
query=keyword, language=language
|
479 |
+
)
|
480 |
+
print(
|
481 |
+
"scheduled_tools_runs:", scheduled_tools_runs, document_references
|
482 |
+
)
|
483 |
|
484 |
apply_tools = (
|
485 |
True if allow_used_tools is True and previous_response is None else False
|
|
|
529 |
and state["respond"] is False
|
530 |
and state["mark"] + waiting_tools_timeout > time.time()
|
531 |
):
|
|
|
532 |
previous_response = "".join(outputs)
|
533 |
yield from generate_chat_responses(previous_response=previous_response)
|
534 |
|