lamhieu commited on
Commit
f6e9614
1 Parent(s): 2d51976

chore: update something

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -325,7 +325,7 @@ def search_with_wikipedia(
325
  try:
326
  wikipedia.set_lang(language)
327
  page = wikipedia.page(query)
328
- content = page.content[:8192]
329
  all_results.append(content)
330
  except Exception as e:
331
  pass
@@ -334,7 +334,7 @@ def search_with_wikipedia(
334
 
335
  def search_with_google(
336
  query: str,
337
- num_results: int = 4,
338
  timeout: int = 5,
339
  language: str = "en",
340
  ssl_verify: bool = None,
@@ -394,6 +394,7 @@ def generate(
394
  top_p: float = 0.95,
395
  top_k: int = 50,
396
  repetition_penalty: float = 1.0,
 
397
  ) -> Iterator[str]:
398
  # print()
399
  # print("allow_used_tools:\n", allow_used_tools)
@@ -403,13 +404,19 @@ def generate(
403
 
404
  def build_input_ids(
405
  apply_tools: bool = None,
406
- references: list[str] = None,
407
  ):
408
  conversation = []
409
  if system_prompt:
410
  conversation.append({"role": "system", "content": system_prompt})
411
  if apply_tools is True:
412
  conversation.append({"role": "tools", "content": supported_tools})
 
 
 
 
 
 
413
  if (
414
  references is not None
415
  and isinstance(references, list)
@@ -475,15 +482,21 @@ def generate(
475
  search_type = scheduled_tools_runs["arguments"]["type"]
476
  language = scheduled_tools_runs["arguments"]["language"]
477
  if search_type == "wikipedia":
478
- gr.Info("Searching for information on the Wikipedia.")
479
- document_references = search_with_wikipedia(
480
- query=keyword, language=language
 
481
  )
482
- else:
483
- gr.Info("Searching for information on the Google.")
484
- document_references = search_with_google(
485
- query=keyword, language=language
486
  )
 
 
 
 
 
 
 
487
  print(
488
  "scheduled_tools_runs:", scheduled_tools_runs, document_references
489
  )
@@ -590,6 +603,12 @@ chat_interface = gr.ChatInterface(
590
  step=0.05,
591
  value=1.0,
592
  ),
 
 
 
 
 
 
593
  ],
594
  stop_btn="Stop",
595
  cache_examples=False,
 
325
  try:
326
  wikipedia.set_lang(language)
327
  page = wikipedia.page(query)
328
+ content = page.content[:4096]
329
  all_results.append(content)
330
  except Exception as e:
331
  pass
 
334
 
335
  def search_with_google(
336
  query: str,
337
+ num_results: int = 3,
338
  timeout: int = 5,
339
  language: str = "en",
340
  ssl_verify: bool = None,
 
394
  top_p: float = 0.95,
395
  top_k: int = 50,
396
  repetition_penalty: float = 1.0,
397
+ other_client_info: str = None,
398
  ) -> Iterator[str]:
399
  # print()
400
  # print("allow_used_tools:\n", allow_used_tools)
 
404
 
405
  def build_input_ids(
406
  apply_tools: bool = None,
407
+ references = None,
408
  ):
409
  conversation = []
410
  if system_prompt:
411
  conversation.append({"role": "system", "content": system_prompt})
412
  if apply_tools is True:
413
  conversation.append({"role": "tools", "content": supported_tools})
414
+
415
+ if references is None:
416
+ references = [other_client_info]
417
+ else:
418
+ references.insert(0, other_client_info)
419
+
420
  if (
421
  references is not None
422
  and isinstance(references, list)
 
482
  search_type = scheduled_tools_runs["arguments"]["type"]
483
  language = scheduled_tools_runs["arguments"]["language"]
484
  if search_type == "wikipedia":
485
+ gr.Info(
486
+ "Searching for information on the Wikipedia.",
487
+ duration=5,
488
+ visible=True,
489
  )
490
+ document_references.extend(
491
+ search_with_wikipedia(query=keyword, language=language)
 
 
492
  )
493
+
494
+ gr.Info(
495
+ "Searching for information on the Google.", duration=5, visible=True
496
+ )
497
+ document_references.extend(
498
+ search_with_google(query=keyword, language=language)
499
+ )
500
  print(
501
  "scheduled_tools_runs:", scheduled_tools_runs, document_references
502
  )
 
603
  step=0.05,
604
  value=1.0,
605
  ),
606
+ gr.Textbox(
607
+ label="Other client information",
608
+ lines=1,
609
+ value="This user's current time: {}".format(time.strftime("%Y-%m-%d")),
610
+ visible=False,
611
+ ),
612
  ],
613
  stop_btn="Stop",
614
  cache_examples=False,