seawolf2357 commited on
Commit
9422d39
ยท
verified ยท
1 Parent(s): d8f9dd5

Update routes.py

Browse files
Files changed (1) hide show
  1. routes.py +4 -27
routes.py CHANGED
@@ -111,7 +111,7 @@ def get_report_details(report_name):
111
 
112
  @main_bp.route('/explain', methods=['POST'])
113
  def explain_sentence():
114
- """base64๋กœ ์ธ์ฝ”๋”ฉ๋œ ์ด๋ฏธ์ง€์™€ ํ•จ๊ป˜ LLM API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค๋ช… ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค."""
115
  if not llm_is_initialized():
116
  logger.error("LLM ํด๋ผ์ด์–ธํŠธ(REST API)๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
117
  return jsonify({"error": "LLM ํด๋ผ์ด์–ธํŠธ(REST API)๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. API ํ‚ค์™€ ๋ฒ ์ด์Šค URL์„ ํ™•์ธํ•˜์„ธ์š”."}), 500
@@ -140,22 +140,6 @@ def explain_sentence():
140
  logger.error(f"๋ณด๊ณ ์„œ '{report_name}'์˜ ์„ค์ •์—์„œ ์ด๋ฏธ์ง€ ๋˜๋Š” ๋ณด๊ณ ์„œ ํŒŒ์ผ ๊ฒฝ๋กœ(static ๊ธฐ์ค€ ์ƒ๋Œ€๊ฒฝ๋กœ)๊ฐ€ ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
141
  return jsonify({"error": f"๋ณด๊ณ ์„œ '{report_name}'์˜ ํŒŒ์ผ ์„ค์ •์ด ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."}), 500
142
 
143
- # Construct absolute server paths using BASE_DIR as image_file and report_file include "static/"
144
- server_image_path = config.BASE_DIR / image_file
145
-
146
-
147
- # --- Prepare Base64 Image for API ---
148
- if not server_image_path.is_file():
149
- logger.error(f"์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {server_image_path}")
150
- return jsonify({"error": f"๋ณด๊ณ ์„œ '{report_name}'์˜ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์„œ๋ฒ„์—์„œ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."}), 500
151
-
152
- base64_image_data_url = utils.image_to_base64_data_url(str(server_image_path))
153
- if not base64_image_data_url:
154
- logger.error("์ด๋ฏธ์ง€๋ฅผ base64๋กœ ์ธ์ฝ”๋”ฉํ•˜๋Š”๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
155
- return jsonify({"error": "API ์š”์ฒญ์„ ์œ„ํ•œ ์ด๋ฏธ์ง€ ์ธ์ฝ”๋”ฉ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค"}), 500
156
-
157
- logger.info("API๋ฅผ ์œ„ํ•œ base64 ๋ฐ์ดํ„ฐ URL๋กœ ์ด๋ฏธ์ง€๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์ธ์ฝ”๋”ฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
158
-
159
  full_report_text = ""
160
  if report_file: # Only attempt to read if a report file is configured
161
  server_report_path = config.BASE_DIR / report_file
@@ -187,13 +171,9 @@ def explain_sentence():
187
  )
188
  user_prompt_text = f"๋ฐฉ์‚ฌ์„  ๋ณด๊ณ ์„œ์˜ ์ด ๋ฌธ์žฅ์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”: '{selected_sentence}'"
189
 
190
- # API๋Š” ์ด๋ฏธ์ง€๋ฅผ ์ง์ ‘ ๋ฐ›์ง€ ๋ชปํ•˜๋ฏ€๋กœ ํ…์ŠคํŠธ๋งŒ ์ „์†ก
191
  messages_for_api = [
192
  {"role": "system", "content": system_prompt},
193
- {
194
- "role": "user",
195
- "content": user_prompt_text # ํ…์ŠคํŠธ๋งŒ ์ „์†ก
196
- }
197
  ]
198
 
199
  # ํ•œ๊ธ€ ์‘๋‹ต์„ ์œ„ํ•ด ์บ์‹œ ํ‚ค์— ์–ธ์–ด ์ •๋ณด ์ถ”๊ฐ€
@@ -204,7 +184,7 @@ def explain_sentence():
204
  return jsonify({"explanation": cached_result})
205
 
206
  try:
207
- logger.info("base64 ์ด๋ฏธ์ง€์™€ ํ•จ๊ป˜ LLM API(REST)๋กœ ์š”์ฒญ์„ ์ „์†ก ์ค‘...")
208
  response = make_chat_completion_request(
209
  model="tgi",
210
  messages=messages_for_api,
@@ -298,10 +278,7 @@ def upload_and_analyze():
298
 
299
  messages_for_api = [
300
  {"role": "system", "content": system_prompt},
301
- {
302
- "role": "user",
303
- "content": user_prompt_text # ํ…์ŠคํŠธ๋งŒ ์ „์†ก
304
- }
305
  ]
306
 
307
  # ์บ์‹œ ํ‚ค ์ƒ์„ฑ (ํŒŒ์ผ๋ช…๊ณผ ์ปจํ…์ŠคํŠธ ๊ธฐ๋ฐ˜)
 
111
 
112
  @main_bp.route('/explain', methods=['POST'])
113
  def explain_sentence():
114
+ """LLM API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ค๋ช… ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค."""
115
  if not llm_is_initialized():
116
  logger.error("LLM ํด๋ผ์ด์–ธํŠธ(REST API)๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
117
  return jsonify({"error": "LLM ํด๋ผ์ด์–ธํŠธ(REST API)๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. API ํ‚ค์™€ ๋ฒ ์ด์Šค URL์„ ํ™•์ธํ•˜์„ธ์š”."}), 500
 
140
  logger.error(f"๋ณด๊ณ ์„œ '{report_name}'์˜ ์„ค์ •์—์„œ ์ด๋ฏธ์ง€ ๋˜๋Š” ๋ณด๊ณ ์„œ ํŒŒ์ผ ๊ฒฝ๋กœ(static ๊ธฐ์ค€ ์ƒ๋Œ€๊ฒฝ๋กœ)๊ฐ€ ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
141
  return jsonify({"error": f"๋ณด๊ณ ์„œ '{report_name}'์˜ ํŒŒ์ผ ์„ค์ •์ด ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."}), 500
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  full_report_text = ""
144
  if report_file: # Only attempt to read if a report file is configured
145
  server_report_path = config.BASE_DIR / report_file
 
171
  )
172
  user_prompt_text = f"๋ฐฉ์‚ฌ์„  ๋ณด๊ณ ์„œ์˜ ์ด ๋ฌธ์žฅ์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”: '{selected_sentence}'"
173
 
 
174
  messages_for_api = [
175
  {"role": "system", "content": system_prompt},
176
+ {"role": "user", "content": user_prompt_text}
 
 
 
177
  ]
178
 
179
  # ํ•œ๊ธ€ ์‘๋‹ต์„ ์œ„ํ•ด ์บ์‹œ ํ‚ค์— ์–ธ์–ด ์ •๋ณด ์ถ”๊ฐ€
 
184
  return jsonify({"explanation": cached_result})
185
 
186
  try:
187
+ logger.info("LLM API(REST)๋กœ ์š”์ฒญ์„ ์ „์†ก ์ค‘...")
188
  response = make_chat_completion_request(
189
  model="tgi",
190
  messages=messages_for_api,
 
278
 
279
  messages_for_api = [
280
  {"role": "system", "content": system_prompt},
281
+ {"role": "user", "content": user_prompt_text}
 
 
 
282
  ]
283
 
284
  # ์บ์‹œ ํ‚ค ์ƒ์„ฑ (ํŒŒ์ผ๋ช…๊ณผ ์ปจํ…์ŠคํŠธ ๊ธฐ๋ฐ˜)