tsengiii commited on
Commit
d1844cd
·
verified ·
1 Parent(s): 943166c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -30,17 +30,17 @@ def transform_history(history):
30
  # 回應生成函數
31
  def response(message, history):
32
  global chat
33
-
34
- # 增加問題篩選邏輯:僅回應與面試流程或建議相關的問題
35
- if not ("面試" in message or "建議" in message):
36
- yield "螃蟹小助理只能回答面試流程或面試建議的問題喔!"
37
- return
38
-
39
  # 將 Gradio 的歷史紀錄轉換為 Gemini 的格式
40
  chat.history = transform_history(history)
41
 
 
 
 
 
 
 
42
  # 發送訊息到 Gemini API
43
- response = chat.send_message(message)
44
  response.resolve()
45
 
46
  # 逐字回傳生成的文字,實現打字機效果
@@ -48,9 +48,7 @@ def response(message, history):
48
  time.sleep(0.05) # 每個字符間隔 0.05 秒
49
  yield response.text[: i+1]
50
 
51
- # 建立 Gradio 聊天界面,更新標題與設定
52
- gr.ChatInterface(
53
- response,
54
- title='瑞昱面試小助手🦀',
55
- textbox=gr.Textbox(placeholder="請問螃蟹小助理有關面試流程或建議的問題")
56
- ).launch(share=True)
 
30
  # 回應生成函數
31
  def response(message, history):
32
  global chat
 
 
 
 
 
 
33
  # 將 Gradio 的歷史紀錄轉換為 Gemini 的格式
34
  chat.history = transform_history(history)
35
 
36
+ # 自訂 Prompt:限縮為與求職面試相關的回答
37
+ prompt = "你是瑞昱公司的招募小助理,名為小螃蟹。你負責協助求職者了解瑞昱公司的面試流程及面試問題,請只回答與求職面試相關的問題,回答語氣需要溫柔且有耐心,且所有回答一律使用繁體中文。"
38
+
39
+ # 合併Prompt與使用者訊息
40
+ final_message = prompt + "\n" + message
41
+
42
  # 發送訊息到 Gemini API
43
+ response = chat.send_message(final_message)
44
  response.resolve()
45
 
46
  # 逐字回傳生成的文字,實現打字機效果
 
48
  time.sleep(0.05) # 每個字符間隔 0.05 秒
49
  yield response.text[: i+1]
50
 
51
+ # 建立 Gradio 聊天界面
52
+ gr.ChatInterface(response,
53
+ title='Gemini Chat - 瑞昱面試小助手🦀',
54
+ textbox=gr.Textbox(placeholder="請輸入與求職面試相關的問題")).launch(share=True)