chore: update something
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ import SelfExtend
|
|
| 23 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 24 |
from bs4 import BeautifulSoup
|
| 25 |
from functools import lru_cache
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
MAX_MAX_NEW_TOKENS = 8192
|
|
@@ -403,6 +404,7 @@ def generate(
|
|
| 403 |
top_p: float = 0.95,
|
| 404 |
top_k: int = 50,
|
| 405 |
repetition_penalty: float = 1.0,
|
|
|
|
| 406 |
) -> Iterator[str]:
|
| 407 |
# print()
|
| 408 |
# print("allow_used_tools:\n", allow_used_tools)
|
|
@@ -412,13 +414,19 @@ def generate(
|
|
| 412 |
|
| 413 |
def build_input_ids(
|
| 414 |
apply_tools: bool = None,
|
| 415 |
-
references
|
| 416 |
):
|
| 417 |
conversation = []
|
| 418 |
if system_prompt:
|
| 419 |
conversation.append({"role": "system", "content": system_prompt})
|
| 420 |
if apply_tools is True:
|
| 421 |
conversation.append({"role": "tools", "content": supported_tools})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
if (
|
| 423 |
references is not None
|
| 424 |
and isinstance(references, list)
|
|
@@ -484,14 +492,20 @@ def generate(
|
|
| 484 |
search_type = scheduled_tools_runs["arguments"]["type"]
|
| 485 |
language = scheduled_tools_runs["arguments"]["language"]
|
| 486 |
if search_type == "wikipedia":
|
| 487 |
-
gr.Info(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
document_references.extend(
|
| 489 |
search_with_wikipedia(query=keyword, language=language)
|
| 490 |
)
|
| 491 |
|
| 492 |
-
gr.Info(
|
| 493 |
-
|
| 494 |
-
|
|
|
|
|
|
|
| 495 |
)
|
| 496 |
print(
|
| 497 |
"scheduled_tools_runs:", scheduled_tools_runs, document_references
|
|
@@ -555,6 +569,8 @@ chatbot = gr.Chatbot(
|
|
| 555 |
height=500, placeholder=PLACEHOLDER, label="Ghost 8B Beta", show_copy_button=True
|
| 556 |
)
|
| 557 |
|
|
|
|
|
|
|
| 558 |
chat_interface = gr.ChatInterface(
|
| 559 |
fn=generate,
|
| 560 |
chatbot=chatbot,
|
|
@@ -599,6 +615,14 @@ chat_interface = gr.ChatInterface(
|
|
| 599 |
step=0.05,
|
| 600 |
value=1.0,
|
| 601 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
],
|
| 603 |
stop_btn="Stop",
|
| 604 |
cache_examples=False,
|
|
|
|
| 23 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 24 |
from bs4 import BeautifulSoup
|
| 25 |
from functools import lru_cache
|
| 26 |
+
from datetime import datetime, timezone
|
| 27 |
|
| 28 |
|
| 29 |
MAX_MAX_NEW_TOKENS = 8192
|
|
|
|
| 404 |
top_p: float = 0.95,
|
| 405 |
top_k: int = 50,
|
| 406 |
repetition_penalty: float = 1.0,
|
| 407 |
+
local_date_time: str = None,
|
| 408 |
) -> Iterator[str]:
|
| 409 |
# print()
|
| 410 |
# print("allow_used_tools:\n", allow_used_tools)
|
|
|
|
| 414 |
|
| 415 |
def build_input_ids(
|
| 416 |
apply_tools: bool = None,
|
| 417 |
+
references = None,
|
| 418 |
):
|
| 419 |
conversation = []
|
| 420 |
if system_prompt:
|
| 421 |
conversation.append({"role": "system", "content": system_prompt})
|
| 422 |
if apply_tools is True:
|
| 423 |
conversation.append({"role": "tools", "content": supported_tools})
|
| 424 |
+
|
| 425 |
+
if references is None:
|
| 426 |
+
references = [local_date_time]
|
| 427 |
+
else:
|
| 428 |
+
references.insert(0, local_date_time)
|
| 429 |
+
|
| 430 |
if (
|
| 431 |
references is not None
|
| 432 |
and isinstance(references, list)
|
|
|
|
| 492 |
search_type = scheduled_tools_runs["arguments"]["type"]
|
| 493 |
language = scheduled_tools_runs["arguments"]["language"]
|
| 494 |
if search_type == "wikipedia":
|
| 495 |
+
gr.Info(
|
| 496 |
+
"Searching for information on the Wikipedia.",
|
| 497 |
+
duration=5,
|
| 498 |
+
visible=True,
|
| 499 |
+
)
|
| 500 |
document_references.extend(
|
| 501 |
search_with_wikipedia(query=keyword, language=language)
|
| 502 |
)
|
| 503 |
|
| 504 |
+
gr.Info(
|
| 505 |
+
"Searching for information on the Google.", duration=5, visible=True
|
| 506 |
+
)
|
| 507 |
+
document_references.extend(
|
| 508 |
+
search_with_google(query=keyword, language=language)
|
| 509 |
)
|
| 510 |
print(
|
| 511 |
"scheduled_tools_runs:", scheduled_tools_runs, document_references
|
|
|
|
| 569 |
height=500, placeholder=PLACEHOLDER, label="Ghost 8B Beta", show_copy_button=True
|
| 570 |
)
|
| 571 |
|
| 572 |
+
utc_dt = datetime.now(timezone.utc)
|
| 573 |
+
|
| 574 |
chat_interface = gr.ChatInterface(
|
| 575 |
fn=generate,
|
| 576 |
chatbot=chatbot,
|
|
|
|
| 615 |
step=0.05,
|
| 616 |
value=1.0,
|
| 617 |
),
|
| 618 |
+
gr.Textbox(
|
| 619 |
+
label="This user's current time",
|
| 620 |
+
lines=1,
|
| 621 |
+
value="This user's current time: {}".format(
|
| 622 |
+
utc_dt.astimezone().isoformat()
|
| 623 |
+
),
|
| 624 |
+
visible=True,
|
| 625 |
+
),
|
| 626 |
],
|
| 627 |
stop_btn="Stop",
|
| 628 |
cache_examples=False,
|