Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,7 +113,7 @@ def load_rag_objects():
|
|
| 113 |
except Exception as e:
|
| 114 |
error_msg = f"[{region}] 로딩 실패: {str(e)}"
|
| 115 |
logger.info(error_msg)
|
| 116 |
-
#
|
| 117 |
traceback.logger.info_exc()
|
| 118 |
socketio.emit('message', {'message': error_msg})
|
| 119 |
|
|
@@ -174,7 +174,21 @@ def get_reg_list():
|
|
| 174 |
def handle_connect():
|
| 175 |
global connected_clients
|
| 176 |
connected_clients += 1
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
global rag_connection_status_info
|
| 180 |
socketio.emit('message', {'message': rag_connection_status_info})
|
|
@@ -203,8 +217,6 @@ def Gemma3_AI_analysis(query_txt, content_txt):
|
|
| 203 |
query_txt = str(query_txt)
|
| 204 |
prompt = lexi_prompts.use_prompt(lexi_prompts.AI_system_prompt, query_txt=query_txt, content_txt=content_txt)
|
| 205 |
|
| 206 |
-
logger.info(f"Gemma3_AI_analysis Prompt\n {prompt}")
|
| 207 |
-
|
| 208 |
try:
|
| 209 |
response = client.chat.completions.create(
|
| 210 |
#model="meta-llama/Llama-4-Scout-17B-16E-Instruct", #비용 효율 측면 최고
|
|
@@ -305,18 +317,18 @@ def RegAI(query, Rag_Results, ResultFile_FolderAddress):
|
|
| 305 |
gc.collect()
|
| 306 |
AI_Result = "검색 결과가 없습니다." if not Rag_Results else Gemma3_AI_analysis(query, Rag_Results)
|
| 307 |
|
| 308 |
-
with open(ResultFile_FolderAddress, 'w', encoding='utf-8') as f:
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
|
| 315 |
-
|
| 316 |
-
|
| 317 |
|
| 318 |
-
|
| 319 |
-
|
| 320 |
|
| 321 |
return AI_Result
|
| 322 |
|
|
|
|
| 113 |
except Exception as e:
|
| 114 |
error_msg = f"[{region}] 로딩 실패: {str(e)}"
|
| 115 |
logger.info(error_msg)
|
| 116 |
+
# [수정]: 상세한 에러 추적을 위해 traceback 추가
|
| 117 |
traceback.logger.info_exc()
|
| 118 |
socketio.emit('message', {'message': error_msg})
|
| 119 |
|
|
|
|
| 174 |
def handle_connect():
|
| 175 |
global connected_clients
|
| 176 |
connected_clients += 1
|
| 177 |
+
|
| 178 |
+
# 클라이언트 IP 가져오기
|
| 179 |
+
client_ip = request.remote_addr
|
| 180 |
+
|
| 181 |
+
# 프록시(Nginx, Cloudflare 등)를 거치는 경우 실제 IP는 헤더에 들어있을 수 있음
|
| 182 |
+
if request.headers.get('X-Forwarded-For'):
|
| 183 |
+
# X-Forwarded-For 는 "client, proxy1, proxy2" 형태로 여러 IP가 있을 수 있음
|
| 184 |
+
client_ip = request.headers.get('X-Forwarded-For').split(',')[0].strip()
|
| 185 |
+
elif request.headers.get('X-Real-IP'):
|
| 186 |
+
client_ip = request.headers.get('X-Real-IP')
|
| 187 |
+
# Cloudflare의 경우
|
| 188 |
+
elif request.headers.get('CF-Connecting-IP'):
|
| 189 |
+
client_ip = request.headers.get('CF-Connecting-IP')
|
| 190 |
+
|
| 191 |
+
logger.info(f"클라이언트 연결 | IP: {client_ip} | 현재 접속자: {connected_clients}명")
|
| 192 |
|
| 193 |
global rag_connection_status_info
|
| 194 |
socketio.emit('message', {'message': rag_connection_status_info})
|
|
|
|
| 217 |
query_txt = str(query_txt)
|
| 218 |
prompt = lexi_prompts.use_prompt(lexi_prompts.AI_system_prompt, query_txt=query_txt, content_txt=content_txt)
|
| 219 |
|
|
|
|
|
|
|
| 220 |
try:
|
| 221 |
response = client.chat.completions.create(
|
| 222 |
#model="meta-llama/Llama-4-Scout-17B-16E-Instruct", #비용 효율 측면 최고
|
|
|
|
| 317 |
gc.collect()
|
| 318 |
AI_Result = "검색 결과가 없습니다." if not Rag_Results else Gemma3_AI_analysis(query, Rag_Results)
|
| 319 |
|
| 320 |
+
#with open(ResultFile_FolderAddress, 'w', encoding='utf-8') as f:
|
| 321 |
+
# print("검색된 문서:", file=f)
|
| 322 |
+
# logger.info("검색된 문서:")
|
| 323 |
+
# for i, doc in enumerate(Rag_Results):
|
| 324 |
+
# print(f"문서 {i+1}: {doc.page_content[:200]}... (메타: {doc.metadata})", file=f)
|
| 325 |
+
# logger.info(f"문서 {i+1}: {doc.page_content[:200]}... (메타: {doc.metadata})")
|
| 326 |
|
| 327 |
+
# print("\n답변:", file=f)
|
| 328 |
+
# logger.info("\n답변:")
|
| 329 |
|
| 330 |
+
# print(AI_Result, file=f)
|
| 331 |
+
# logger.info(AI_Result)
|
| 332 |
|
| 333 |
return AI_Result
|
| 334 |
|