GitHub Actions
commited on
Commit
ยท
9ae9702
1
Parent(s):
68e25b1
Auto-deploy from GitHub Actions - 2025-12-12 07:34:05
Browse files- app/routes.py +20 -4
app/routes.py
CHANGED
|
@@ -1720,16 +1720,21 @@ def search_relevant_chunks(query, file_ids=None, model_name=None, top_k=5, min_s
|
|
| 1720 |
expanded_file_ids.extend([child.id for child in child_files])
|
| 1721 |
|
| 1722 |
# ๋ชจ๋ธ ํํฐ๋ง์ด ํ์ํ ๊ฒฝ์ฐ ํ์ผ ID ํํฐ๋ง
|
| 1723 |
-
|
|
|
|
| 1724 |
filtered_files = UploadedFile.query.filter(
|
| 1725 |
UploadedFile.id.in_(expanded_file_ids),
|
| 1726 |
UploadedFile.model_name == model_name
|
| 1727 |
).all()
|
| 1728 |
expanded_file_ids = [f.id for f in filtered_files]
|
| 1729 |
-
elif model_name and not expanded_file_ids:
|
| 1730 |
# ํ์ผ ID๊ฐ ์์ผ๋ฉด ๋ชจ๋ธ ์ด๋ฆ์ผ๋ก๋ง ํํฐ๋ง
|
| 1731 |
filtered_files = UploadedFile.query.filter_by(model_name=model_name).all()
|
| 1732 |
expanded_file_ids = [f.id for f in filtered_files]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1733 |
|
| 1734 |
# 1๋จ๊ณ: ๋ฒกํฐ ๊ฒ์์ผ๋ก ์ด๊ธฐ 30๊ฐ ๋ฌธ์ ๊ฒ์
|
| 1735 |
print(f"[๋ฒกํฐ ๊ฒ์] ์ฟผ๋ฆฌ: {query[:50]}..., ํ์ผ ID: {expanded_file_ids if expanded_file_ids else '๋ชจ๋ ํ์ผ'}")
|
|
@@ -3382,6 +3387,17 @@ def chat():
|
|
| 3382 |
if not answer_model:
|
| 3383 |
answer_model = analysis_model
|
| 3384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3385 |
# ๋ต๋ณ์ฉ ๋ชจ๋ธ์ด ์ฌ์ ํ ์์ผ๋ฉด ์๋ฌ ๋ฐํ
|
| 3386 |
if not answer_model:
|
| 3387 |
return jsonify({'error': '๋ต๋ณ์ ์์ฑํ AI ๋ชจ๋ธ์ด ์ ํ๋์ง ์์์ต๋๋ค. "์ฌ์ฉ ๊ฐ๋ฅํ AI ๋ชฉ๋ก"์์ ๋ต๋ณ์ ์์ฑํ AI ๋ชจ๋ธ์ ์ ํํด์ฃผ์ธ์.'}), 400
|
|
@@ -3415,11 +3431,11 @@ def chat():
|
|
| 3415 |
print(f"[RAG ๊ฒ์ 2๋จ๊ณ] GraphRAG ๋ฐ์ดํฐ ์กฐํ ์๋ฃ: ์ํฐํฐ {len(graph_data['entities'])}๊ฐ, ๊ด๊ณ {len(graph_data['relationships'])}๊ฐ, ์ฌ๊ฑด {len(graph_data['events'])}๊ฐ")
|
| 3416 |
|
| 3417 |
# 3๋จ๊ณ: ๋ฒกํฐ ๊ฒ์ + ๋ฆฌ๋ญํน์ผ๋ก Child Chunk ์ ๋ฐ ๊ฒ์ (๋ถ์ ๋ชจ๋ธ ์ฌ์ฉ)
|
| 3418 |
-
print(f"[RAG ๊ฒ์ 3๋จ๊ณ] ๋ฒกํฐ ๊ฒ์ + ๋ฆฌ๋ญํน ์์ (
|
| 3419 |
relevant_chunks = search_relevant_chunks(
|
| 3420 |
query=message,
|
| 3421 |
file_ids=file_ids if file_ids else None,
|
| 3422 |
-
model_name=
|
| 3423 |
top_k=5, # ๋ฆฌ๋ญํน ํ ์์ 5๊ฐ๋ง ์ ํ
|
| 3424 |
min_score=0.5 # ์ต์ ์ ์ ์๊ณ๊ฐ
|
| 3425 |
)
|
|
|
|
| 1720 |
expanded_file_ids.extend([child.id for child in child_files])
|
| 1721 |
|
| 1722 |
# ๋ชจ๋ธ ํํฐ๋ง์ด ํ์ํ ๊ฒฝ์ฐ ํ์ผ ID ํํฐ๋ง
|
| 1723 |
+
# model_name์ด 'all'์ธ ๊ฒฝ์ฐ ํํฐ๋ง์ ๊ฑด๋๋ (์ ์ฒด ๋ชจ๋ธ ๊ฒ์)
|
| 1724 |
+
if model_name and model_name != 'all' and expanded_file_ids:
|
| 1725 |
filtered_files = UploadedFile.query.filter(
|
| 1726 |
UploadedFile.id.in_(expanded_file_ids),
|
| 1727 |
UploadedFile.model_name == model_name
|
| 1728 |
).all()
|
| 1729 |
expanded_file_ids = [f.id for f in filtered_files]
|
| 1730 |
+
elif model_name and model_name != 'all' and not expanded_file_ids:
|
| 1731 |
# ํ์ผ ID๊ฐ ์์ผ๋ฉด ๋ชจ๋ธ ์ด๋ฆ์ผ๋ก๋ง ํํฐ๋ง
|
| 1732 |
filtered_files = UploadedFile.query.filter_by(model_name=model_name).all()
|
| 1733 |
expanded_file_ids = [f.id for f in filtered_files]
|
| 1734 |
+
elif model_name == 'all' and not expanded_file_ids:
|
| 1735 |
+
# 'all'์ด๊ณ ํ์ผ ID๊ฐ ์์ผ๋ฉด ๋ชจ๋ ํ์ผ ๊ฒ์ (ํ์ง๋ง ๋ณดํต์ ํ์ผ ID๊ฐ ์ ๋ฌ๋จ)
|
| 1736 |
+
# ์ฌ๊ธฐ์๋ ์๋ฌด๊ฒ๋ ํ์ง ์์ (expanded_file_ids๊ฐ None์ด๋ฉด ๋ชจ๋ ํ์ผ ๊ฒ์ํ๋ฏ๋ก)
|
| 1737 |
+
pass
|
| 1738 |
|
| 1739 |
# 1๋จ๊ณ: ๋ฒกํฐ ๊ฒ์์ผ๋ก ์ด๊ธฐ 30๊ฐ ๋ฌธ์ ๊ฒ์
|
| 1740 |
print(f"[๋ฒกํฐ ๊ฒ์] ์ฟผ๋ฆฌ: {query[:50]}..., ํ์ผ ID: {expanded_file_ids if expanded_file_ids else '๋ชจ๋ ํ์ผ'}")
|
|
|
|
| 3387 |
if not answer_model:
|
| 3388 |
answer_model = analysis_model
|
| 3389 |
|
| 3390 |
+
# 'all' ๋ชจ๋ธ ์ฒ๋ฆฌ: ์ค์ LLM ํธ์ถ์ฉ ๋ชจ๋ธ๊ณผ ๊ฒ์ ํํฐ์ฉ ๋ชจ๋ธ ๊ตฌ๋ถ
|
| 3391 |
+
search_model_filter = analysis_model
|
| 3392 |
+
|
| 3393 |
+
if analysis_model == 'all':
|
| 3394 |
+
# ๋ถ์์ฉ ๋ชจ๋ธ์ ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ (Gemini Flash ๊ถ์ฅ)
|
| 3395 |
+
analysis_model = 'gemini:gemini-1.5-flash'
|
| 3396 |
+
|
| 3397 |
+
if answer_model == 'all':
|
| 3398 |
+
# ๋ต๋ณ์ฉ ๋ชจ๋ธ๋ ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ
|
| 3399 |
+
answer_model = 'gemini:gemini-1.5-flash'
|
| 3400 |
+
|
| 3401 |
# ๋ต๋ณ์ฉ ๋ชจ๋ธ์ด ์ฌ์ ํ ์์ผ๋ฉด ์๋ฌ ๋ฐํ
|
| 3402 |
if not answer_model:
|
| 3403 |
return jsonify({'error': '๋ต๋ณ์ ์์ฑํ AI ๋ชจ๋ธ์ด ์ ํ๋์ง ์์์ต๋๋ค. "์ฌ์ฉ ๊ฐ๋ฅํ AI ๋ชฉ๋ก"์์ ๋ต๋ณ์ ์์ฑํ AI ๋ชจ๋ธ์ ์ ํํด์ฃผ์ธ์.'}), 400
|
|
|
|
| 3431 |
print(f"[RAG ๊ฒ์ 2๋จ๊ณ] GraphRAG ๋ฐ์ดํฐ ์กฐํ ์๋ฃ: ์ํฐํฐ {len(graph_data['entities'])}๊ฐ, ๊ด๊ณ {len(graph_data['relationships'])}๊ฐ, ์ฌ๊ฑด {len(graph_data['events'])}๊ฐ")
|
| 3432 |
|
| 3433 |
# 3๋จ๊ณ: ๋ฒกํฐ ๊ฒ์ + ๋ฆฌ๋ญํน์ผ๋ก Child Chunk ์ ๋ฐ ๊ฒ์ (๋ถ์ ๋ชจ๋ธ ์ฌ์ฉ)
|
| 3434 |
+
print(f"[RAG ๊ฒ์ 3๋จ๊ณ] ๋ฒกํฐ ๊ฒ์ + ๋ฆฌ๋ญํน ์์ (๊ฒ์ ํํฐ: {search_model_filter})...")
|
| 3435 |
relevant_chunks = search_relevant_chunks(
|
| 3436 |
query=message,
|
| 3437 |
file_ids=file_ids if file_ids else None,
|
| 3438 |
+
model_name=search_model_filter, # 'all'์ด๋ฉด ๋ชจ๋ ๋ชจ๋ธ ๊ฒ์
|
| 3439 |
top_k=5, # ๋ฆฌ๋ญํน ํ ์์ 5๊ฐ๋ง ์ ํ
|
| 3440 |
min_score=0.5 # ์ต์ ์ ์ ์๊ณ๊ฐ
|
| 3441 |
)
|