Update app.py
Browse files29 unmodified lines30313233343536373839404142434445461 unmodified line48495051525354555629 unmodified lines# 回應生成函數def response(message, history):global chat# 增加問題篩選邏輯:僅回應與面試流程或建議相關的問題if not ("面試" in message or "建議" in message):yield "螃蟹小助理只能回答面試流程或面試建議的問題喔!"return# 將 Gradio 的歷史紀錄轉換為 Gemini 的格式chat.history = transform_history(history)# 發送訊息到 Gemini APIresponse = chat.send_message(message)response.resolve()# 逐字回傳生成的文字,實現打字機效果1 unmodified linetime.sleep(0.05) # 每個字符間隔 0.05 秒yield response.text[: i+1]# 建立 Gradio 聊天界面,更新標題與設定gr.ChatInterface(response,title='瑞昱面試小助手🦀',textbox=gr.Textbox(placeholder="請問螃蟹小助理有關面試流程或建議的問題")).launch(share=True)29 unmodified lines30313233343536373839404142434445461 unmodified line4849505152535429 unmodified lines# 回應生成函數def response(message, history):global chat# 將 Gradio 的歷史紀錄轉換為 Gemini 的格式chat.history = transform_history(history)# 自訂 Prompt:限縮為與求職面試相關的回答prompt = "你是瑞昱公司的招募小助理,名為小螃蟹。你負責協助求職者了解瑞昱公司的面試流程及面試問題,請只回答與求職面試相關的問題,回答語氣需要溫柔且有耐心,且所有回答一律使用繁體中文。"# 合併Prompt與使用者訊息final_message = prompt + "\n" + message# 發送訊息到 Gemini APIresponse = chat.send_message(final_message)response.resolve()# 逐字回傳生成的文字,實現打字機效果1 unmodified linetime.sleep(0.05) # 每個字符間隔 0.05 秒yield response.text[: i+1]# 建立 Gradio 聊天界面gr.ChatInterface(response,title='Gemini Chat - 瑞昱面試小助手🦀',textbox=gr.Textbox(placeholder="請輸入與求職面試相關的問題")).launch(share=True)
app.py+11-13