EMMA commited on
Commit
c4b7689
·
1 Parent(s): 795a62f

update code

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -449,7 +449,7 @@ def predict_new(
449
  }
450
 
451
  if text == "":
452
- return history, history, "Empty context."
453
 
454
  if history is None:
455
  history = []
@@ -499,6 +499,9 @@ def predict_new(
499
  api_index=api_index,
500
  )
501
 
 
 
 
502
  torch.cuda.empty_cache()
503
 
504
  new_history = history + [
@@ -511,7 +514,7 @@ def predict_new(
511
  # همگام‌سازی بلافاصله با دیتاست Hugging Face
512
  sync_memory_to_hf()
513
 
514
- return new_history, new_history, "Generating..."
515
 
516
 
517
  def _build_session_choices(user_data: dict):
@@ -1026,7 +1029,7 @@ body:has(.progress-level)::before {
1026
  if crisis_level == CrisisLevel.CONCERN else ""
1027
  )
1028
 
1029
- new_history, _, status_msg = predict_new(
1030
  text=user_message,
1031
  history=current_history,
1032
  top_p=0.95,
@@ -1052,7 +1055,7 @@ body:has(.progress-level)::before {
1052
  if msg_item.get("role") == "assistant":
1053
  reply_text = msg_item.get("content", "")
1054
  break
1055
- prompt_tokens = count_tokens(user_message)
1056
  reply_tokens = count_tokens(reply_text)
1057
  perf_stats = (
1058
  f"⏱ Response time: {elapsed:.2f} s | "
 
449
  }
450
 
451
  if text == "":
452
+ return history, 0, "Empty context."
453
 
454
  if history is None:
455
  history = []
 
499
  api_index=api_index,
500
  )
501
 
502
+ total_prompt_str = system_prompt + "\n" + "\n".join([m.get("content", "") for m in current_history_for_llm]) + "\n" + text
503
+ actual_prompt_tokens = count_tokens(total_prompt_str)
504
+
505
  torch.cuda.empty_cache()
506
 
507
  new_history = history + [
 
514
  # همگام‌سازی بلافاصله با دیتاست Hugging Face
515
  sync_memory_to_hf()
516
 
517
+ return new_history, actual_prompt_tokens, "Generating..."
518
 
519
 
520
  def _build_session_choices(user_data: dict):
 
1029
  if crisis_level == CrisisLevel.CONCERN else ""
1030
  )
1031
 
1032
+ new_history, actual_prompt_tokens, status_msg = predict_new(
1033
  text=user_message,
1034
  history=current_history,
1035
  top_p=0.95,
 
1055
  if msg_item.get("role") == "assistant":
1056
  reply_text = msg_item.get("content", "")
1057
  break
1058
+ prompt_tokens = actual_prompt_tokens
1059
  reply_tokens = count_tokens(reply_text)
1060
  perf_stats = (
1061
  f"⏱ Response time: {elapsed:.2f} s | "