alanchen1115 commited on
Commit
8ee1f49
·
verified ·
1 Parent(s): d832585

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -14
main.py CHANGED
@@ -82,7 +82,7 @@ def handle_message(event):
82
 
83
  # 檢查是否正在與使用者交談
84
  elif working_status:
85
- # try:
86
  # 取得使用者輸入的文字
87
  question = event.message.text
88
  doc_url = "https://www.twse.com.tw/pdf/ch/"+question+"_ch.pdf"
@@ -94,8 +94,7 @@ def handle_message(event):
94
  temp_file.write(doc_data.content)
95
  temp_file_path = temp_file.name
96
  sample_doc = client.files.upload(file=temp_file_path)
97
- prompt = "你是投信分析師,請使用繁體中文3000字以內,分項說明公司股市價量表現、融資融卷、內外資進出及財務資訊,並分析近期公司股市展望給投資人具體的專業建議!"
98
-
99
  # gemini-2.5-flash
100
  completion = client.models.generate_content(
101
  model="gemini-2.5-flash",
@@ -103,18 +102,14 @@ def handle_message(event):
103
  config=generation_config).text
104
  # 取得生成結果
105
  out = completion
106
- # except:
107
- # # 處理錯誤
108
- # out = "Gemini執行出錯!請換個說法!"
109
 
110
- # # 回覆生成結果
111
- # line_bot_api.reply_message(
112
- # event.reply_token,
113
- # TextSendMessage(text=out))
114
-
115
- line_bot_api.reply_message(
116
- event.reply_token,
117
- TextSendMessage(text=out))
118
 
119
  if __name__ == "__main__":
120
  # 啟動 FastAPI 應用程式
 
82
 
83
  # 檢查是否正在與使用者交談
84
  elif working_status:
85
+ try:
86
  # 取得使用者輸入的文字
87
  question = event.message.text
88
  doc_url = "https://www.twse.com.tw/pdf/ch/"+question+"_ch.pdf"
 
94
  temp_file.write(doc_data.content)
95
  temp_file_path = temp_file.name
96
  sample_doc = client.files.upload(file=temp_file_path)
97
+
 
98
  # gemini-2.5-flash
99
  completion = client.models.generate_content(
100
  model="gemini-2.5-flash",
 
102
  config=generation_config).text
103
  # 取得生成結果
104
  out = completion
105
+ except:
106
+ # 處理錯誤
107
+ out = "Gemini執行出錯!請換個說法!"
108
 
109
+ # 回覆生成結果
110
+ line_bot_api.reply_message(
111
+ event.reply_token,
112
+ TextSendMessage(text=out))
 
 
 
 
113
 
114
  if __name__ == "__main__":
115
  # 啟動 FastAPI 應用程式