YC-Chen commited on
Commit
1ccecb7
1 Parent(s): 6fce2df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -48,6 +48,14 @@ FREQUENCY_PENALTY=0
48
  model_name = "MediaTek-Research/Breeze-7B-Instruct-v0.1"
49
  tokenizer = AutoTokenizer.from_pretrained(model_name)
50
 
 
 
 
 
 
 
 
 
51
  with gr.Blocks() as demo:
52
  gr.Markdown(DESCRIPTION)
53
 
@@ -113,6 +121,10 @@ with gr.Blocks() as demo:
113
  if assistant_msg is not None:
114
  chat_data.append({"role": "assistant", "content": assistant_msg})
115
 
 
 
 
 
116
  message = tokenizer.apply_chat_template(chat_data, tokenize=False)
117
  message = message[3:] # remove SOT token
118
 
 
48
  model_name = "MediaTek-Research/Breeze-7B-Instruct-v0.1"
49
  tokenizer = AutoTokenizer.from_pretrained(model_name)
50
 
51
+ def refusal_condition(query):
52
+ is_including_tw = '台灣' in query or '台湾' in query or 'taiwan' in query.lower() or 'tw' in query.lower()
53
+ is_including_cn = '中國' in query or '中国' in query or 'china' in query.lower() or 'cn' in query.lower()
54
+ if is_including_tw and is_including_cn:
55
+ return True
56
+
57
+ return False
58
+
59
  with gr.Blocks() as demo:
60
  gr.Markdown(DESCRIPTION)
61
 
 
121
  if assistant_msg is not None:
122
  chat_data.append({"role": "assistant", "content": assistant_msg})
123
 
124
+ if refusal_condition(history[-1][0]):
125
+ history[-1][1] = '抱歉,我無法回答您這個問題'
126
+ return history
127
+
128
  message = tokenizer.apply_chat_template(chat_data, tokenize=False)
129
  message = message[3:] # remove SOT token
130