Spaces:
Sleeping
Sleeping
Auto commit at 22-2025-08 23:59:11
Browse files
lily_llm_api/app_v2.py
CHANGED
|
@@ -553,20 +553,131 @@ def generate_sync(prompt: str, image_data_list: Optional[List[bytes]], max_lengt
|
|
| 553 |
# --- 2. ํ๋กฌํํธ ๊ตฌ์ฑ ---
|
| 554 |
print(f"๐ [DEBUG] ํ๋กฌํํธ ๊ตฌ์ฑ ์์")
|
| 555 |
|
| 556 |
-
# ์ปจํ
์คํธ ํตํฉ (๋ํ ๊ธฐ๋ก ํฌํจ) - ๋ชจ๋ธ๋ณ ์ต์ ํ
|
| 557 |
context_prompt = ""
|
| 558 |
if use_context and session_id:
|
| 559 |
try:
|
| 560 |
-
#
|
| 561 |
context = context_manager.get_context_for_model(
|
| 562 |
current_profile.model_name,
|
| 563 |
session_id
|
| 564 |
)
|
| 565 |
if context and len(context.strip()) > 0:
|
| 566 |
context_prompt = context + "\n\n"
|
| 567 |
-
print(f"๐ [DEBUG] ์ปจํ
์คํธ ํฌํจ๋จ - ๊ธธ์ด: {len(context_prompt)} (์ธ์
: {session_id})")
|
| 568 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
print(f"๐ [DEBUG] ์ปจํ
์คํธ ์์ ๋๋ ๋น์ด์์ (์ธ์
: {session_id})")
|
|
|
|
| 570 |
except Exception as e:
|
| 571 |
print(f"โ ๏ธ [DEBUG] ์ปจํ
์คํธ ๋ก๋ ์คํจ: {e} (์ธ์
: {session_id})")
|
| 572 |
context_prompt = ""
|
|
@@ -1223,6 +1334,8 @@ def generate_sync(prompt: str, image_data_list: Optional[List[bytes]], max_lengt
|
|
| 1223 |
response = full_text.replace(formatted_prompt, "").strip() if formatted_prompt else full_text
|
| 1224 |
print(f"๐ [DEBUG] ๊ธฐ๋ณธ ์๋ต ์ถ์ถ ์ฌ์ฉ")
|
| 1225 |
|
|
|
|
|
|
|
| 1226 |
print(f"๐ [DEBUG] ์ถ์ถ๋ ์๋ต ๊ธธ์ด: {len(response)}")
|
| 1227 |
print(f"๐ [DEBUG] ์ต์ข
์๋ต: {response}")
|
| 1228 |
|
|
@@ -1641,18 +1754,65 @@ async def upload_document(
|
|
| 1641 |
|
| 1642 |
logger.info(f"๐ค ๋ฌธ์ ์
๋ก๋ ํ AI ์๋ต ์์ฑ ์์...")
|
| 1643 |
|
| 1644 |
-
|
| 1645 |
-
|
| 1646 |
-
|
| 1647 |
-
|
| 1648 |
-
|
| 1649 |
-
|
| 1650 |
-
|
| 1651 |
-
|
| 1652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1653 |
|
| 1654 |
except Exception as e:
|
| 1655 |
logger.error(f"โ ์๋ AI ์๋ต ์์ฑ ์ค ์ค๋ฅ: {e}")
|
|
|
|
| 1656 |
|
| 1657 |
return DocumentUploadResponse(
|
| 1658 |
success=result["success"],
|
|
|
|
| 553 |
# --- 2. ํ๋กฌํํธ ๊ตฌ์ฑ ---
|
| 554 |
print(f"๐ [DEBUG] ํ๋กฌํํธ ๊ตฌ์ฑ ์์")
|
| 555 |
|
| 556 |
+
# ์ปจํ
์คํธ ํตํฉ (๋ํ ๊ธฐ๋ก + RAG ๊ฒ์ ๊ฒฐ๊ณผ ํฌํจ) - ๋ชจ๋ธ๋ณ ์ต์ ํ
|
| 557 |
context_prompt = ""
|
| 558 |
if use_context and session_id:
|
| 559 |
try:
|
| 560 |
+
# 1. ๋ํ ๊ธฐ๋ก ์ปจํ
์คํธ
|
| 561 |
context = context_manager.get_context_for_model(
|
| 562 |
current_profile.model_name,
|
| 563 |
session_id
|
| 564 |
)
|
| 565 |
if context and len(context.strip()) > 0:
|
| 566 |
context_prompt = context + "\n\n"
|
| 567 |
+
print(f"๐ [DEBUG] ๋ํ ์ปจํ
์คํธ ํฌํจ๋จ - ๊ธธ์ด: {len(context_prompt)} (์ธ์
: {session_id})")
|
| 568 |
+
|
| 569 |
+
# 2. RAG ๊ฒ์ ๊ฒฐ๊ณผ ์ปจํ
์คํธ (PDF ๋ด์ฉ ํฌํจ)
|
| 570 |
+
try:
|
| 571 |
+
# ๐ ๊ฐ๋จํ๊ณ ์ง์ ์ ์ธ RAG ์ปจํ
์คํธ ๋ก๋
|
| 572 |
+
rag_context = ""
|
| 573 |
+
|
| 574 |
+
# ๐ ๊ฐ๋จํ ํ์ผ ๊ธฐ๋ฐ RAG ์ปจํ
์คํธ ๋ก๋
|
| 575 |
+
try:
|
| 576 |
+
# vector_stores ๋๋ ํ ๋ฆฌ์์ ์ต๊ทผ ๋ฌธ์ ๋ด์ฉ ์ง์ ์ฝ๊ธฐ
|
| 577 |
+
import os
|
| 578 |
+
import json
|
| 579 |
+
|
| 580 |
+
vector_store_dir = "vector_stores"
|
| 581 |
+
if os.path.exists(vector_store_dir):
|
| 582 |
+
user_dirs = [d for d in os.listdir(vector_store_dir) if os.path.isdir(os.path.join(vector_store_dir, d))]
|
| 583 |
+
if user_dirs:
|
| 584 |
+
user_dir = user_dirs[0] # ์ฒซ ๋ฒ์งธ ์ฌ์ฉ์
|
| 585 |
+
user_path = os.path.join(vector_store_dir, user_dir)
|
| 586 |
+
|
| 587 |
+
if os.path.exists(user_path):
|
| 588 |
+
doc_dirs = [d for d in os.listdir(user_path) if os.path.isdir(os.path.join(user_path, d))]
|
| 589 |
+
if doc_dirs:
|
| 590 |
+
# ์ต๊ทผ ๋ฌธ์ ID ์ฌ์ฉ
|
| 591 |
+
recent_doc_id = doc_dirs[-1]
|
| 592 |
+
print(f"๐ [DEBUG] RAG ์ปจํ
์คํธ ๊ฒ์: ์ฌ์ฉ์={user_dir}, ๋ฌธ์={recent_doc_id}")
|
| 593 |
+
|
| 594 |
+
# ๋ฌธ์ ๋ด์ฉ ํ์ผ ์ง์ ์ฝ๊ธฐ (pickle ํ์ผ ์ง์)
|
| 595 |
+
doc_path = os.path.join(user_path, recent_doc_id)
|
| 596 |
+
if os.path.exists(doc_path):
|
| 597 |
+
# ๐ pickle ํ์ผ์์ ๋ด์ฉ ์ฝ๊ธฐ (์ฐ์ )
|
| 598 |
+
pickle_file = os.path.join(doc_path, "simple_vector_store.pkl")
|
| 599 |
+
if os.path.exists(pickle_file):
|
| 600 |
+
try:
|
| 601 |
+
import pickle
|
| 602 |
+
with open(pickle_file, 'rb') as f:
|
| 603 |
+
vector_store_data = pickle.load(f)
|
| 604 |
+
|
| 605 |
+
# vector store์์ ๋ฌธ์ ๋ด์ฉ ์ถ์ถ (dict ๊ตฌ์กฐ)
|
| 606 |
+
if isinstance(vector_store_data, dict) and 'documents' in vector_store_data:
|
| 607 |
+
documents_data = vector_store_data['documents']
|
| 608 |
+
if documents_data and len(documents_data) > 0:
|
| 609 |
+
rag_context = "\n\n๐ ์
๋ก๋๋ ๋ฌธ์ ๋ด์ฉ:\n"
|
| 610 |
+
for i, doc in enumerate(documents_data[:2]): # ์ต๋ 2๊ฐ ์ฒญํฌ
|
| 611 |
+
if hasattr(doc, 'page_content'):
|
| 612 |
+
content = doc.page_content.strip()
|
| 613 |
+
if content and len(content) > 30:
|
| 614 |
+
# ๋ด์ฉ์ 200์๋ก ์ ํ
|
| 615 |
+
truncated_content = content[:200] + "..." if len(content) > 200 else content
|
| 616 |
+
rag_context += f"--- ์ฒญํฌ {i+1} ---\n{truncated_content}\n\n"
|
| 617 |
+
|
| 618 |
+
if len(rag_context) > 30:
|
| 619 |
+
context_prompt += rag_context
|
| 620 |
+
print(f"๐ [DEBUG] RAG ์ปจํ
์คํธ ํฌํจ๋จ - ๊ธธ์ด: {len(rag_context)}")
|
| 621 |
+
print(f"๐ [DEBUG] RAG ์ปจํ
์คํธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: {rag_context[:100]}...")
|
| 622 |
+
else:
|
| 623 |
+
print(f"โ ๏ธ [DEBUG] RAG ์ปจํ
์คํธ๊ฐ ๋๋ฌด ์งง์: {len(rag_context)}")
|
| 624 |
+
else:
|
| 625 |
+
print(f"โ ๏ธ [DEBUG] pickle ํ์ผ์ ๋ฌธ์ ๋ฐ์ดํฐ ์์")
|
| 626 |
+
else:
|
| 627 |
+
print(f"โ ๏ธ [DEBUG] pickle ํ์ผ์ documents ํค ์์: {list(vector_store_data.keys()) if isinstance(vector_store_data, dict) else 'Not a dict'}")
|
| 628 |
+
except Exception as e:
|
| 629 |
+
print(f"โ ๏ธ [DEBUG] pickle ํ์ผ ์ฝ๊ธฐ ์คํจ: {e}")
|
| 630 |
+
|
| 631 |
+
# ๐ fallback: documents.json ํ์ผ ์๋
|
| 632 |
+
docs_file = os.path.join(doc_path, "documents.json")
|
| 633 |
+
if os.path.exists(docs_file):
|
| 634 |
+
try:
|
| 635 |
+
with open(docs_file, 'r', encoding='utf-8') as f:
|
| 636 |
+
documents_data = json.load(f)
|
| 637 |
+
|
| 638 |
+
if documents_data and len(documents_data) > 0:
|
| 639 |
+
rag_context = "\n\n๐ ์
๋ก๋๋ ๋ฌธ์ ๋ด์ฉ:\n"
|
| 640 |
+
for i, doc in enumerate(documents_data[:2]): # ์ต๋ 2๊ฐ ์ฒญํฌ
|
| 641 |
+
if 'page_content' in doc:
|
| 642 |
+
content = doc['page_content'].strip()
|
| 643 |
+
if content and len(content) > 30:
|
| 644 |
+
# ๋ด์ฉ์ 200์๋ก ์ ํ
|
| 645 |
+
truncated_content = content[:200] + "..." if len(content) > 200 else content
|
| 646 |
+
rag_context += f"--- ์ฒญํฌ {i+1} ---\n{truncated_content}\n\n"
|
| 647 |
+
|
| 648 |
+
if len(rag_context) > 30:
|
| 649 |
+
context_prompt += rag_context
|
| 650 |
+
print(f"๐ [DEBUG] RAG ์ปจํ
์คํธ ํฌํจ๋จ (JSON fallback) - ๊ธธ์ด: {len(rag_context)}")
|
| 651 |
+
print(f"๐ [DEBUG] RAG ์ปจํ
์คํธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ: {rag_context[:100]}...")
|
| 652 |
+
else:
|
| 653 |
+
print(f"โ ๏ธ [DEBUG] RAG ์ปจํ
์คํธ๊ฐ ๋๋ฌด ์งง์: {len(rag_context)}")
|
| 654 |
+
else:
|
| 655 |
+
print(f"โ ๏ธ [DEBUG] documents.json ๋ฐ์ดํฐ ์์")
|
| 656 |
+
except Exception as e:
|
| 657 |
+
print(f"โ ๏ธ [DEBUG] documents.json ์ฝ๊ธฐ ์คํจ: {e}")
|
| 658 |
+
else:
|
| 659 |
+
print(f"โ ๏ธ [DEBUG] documents.json ํ์ผ ์์: {docs_file}")
|
| 660 |
+
else:
|
| 661 |
+
print(f"โ ๏ธ [DEBUG] pickle ํ์ผ ์์: {pickle_file}")
|
| 662 |
+
else:
|
| 663 |
+
print(f"โ ๏ธ [DEBUG] ๋ฌธ์ ๊ฒฝ๋ก ์์: {doc_path}")
|
| 664 |
+
else:
|
| 665 |
+
print(f"โ ๏ธ [DEBUG] ๋ฌธ์ ๋๋ ํ ๋ฆฌ ์์: {user_path}")
|
| 666 |
+
else:
|
| 667 |
+
print(f"โ ๏ธ [DEBUG] ์ฌ์ฉ์ ๊ฒฝ๋ก ์์: {user_path}")
|
| 668 |
+
else:
|
| 669 |
+
print(f"โ ๏ธ [DEBUG] ์ฌ์ฉ์ ๋๋ ํ ๋ฆฌ ์์: {vector_store_dir}")
|
| 670 |
+
else:
|
| 671 |
+
print(f"โ ๏ธ [DEBUG] vector_stores ๋๋ ํ ๋ฆฌ ์์")
|
| 672 |
+
except Exception as e:
|
| 673 |
+
print(f"โ ๏ธ [DEBUG] RAG ์ปจํ
์คํธ ํ์ผ ์ฝ๊ธฐ ์คํจ: {e}")
|
| 674 |
+
|
| 675 |
+
except Exception as e:
|
| 676 |
+
print(f"โ ๏ธ [DEBUG] RAG ์ปจํ
์คํธ ์ฒ๋ฆฌ ์คํจ: {e}")
|
| 677 |
+
|
| 678 |
+
if not context_prompt:
|
| 679 |
print(f"๐ [DEBUG] ์ปจํ
์คํธ ์์ ๋๋ ๋น์ด์์ (์ธ์
: {session_id})")
|
| 680 |
+
|
| 681 |
except Exception as e:
|
| 682 |
print(f"โ ๏ธ [DEBUG] ์ปจํ
์คํธ ๋ก๋ ์คํจ: {e} (์ธ์
: {session_id})")
|
| 683 |
context_prompt = ""
|
|
|
|
| 1334 |
response = full_text.replace(formatted_prompt, "").strip() if formatted_prompt else full_text
|
| 1335 |
print(f"๐ [DEBUG] ๊ธฐ๋ณธ ์๋ต ์ถ์ถ ์ฌ์ฉ")
|
| 1336 |
|
| 1337 |
+
|
| 1338 |
+
|
| 1339 |
print(f"๐ [DEBUG] ์ถ์ถ๋ ์๋ต ๊ธธ์ด: {len(response)}")
|
| 1340 |
print(f"๐ [DEBUG] ์ต์ข
์๋ต: {response}")
|
| 1341 |
|
|
|
|
| 1754 |
|
| 1755 |
logger.info(f"๐ค ๋ฌธ์ ์
๋ก๋ ํ AI ์๋ต ์์ฑ ์์...")
|
| 1756 |
|
| 1757 |
+
# ๐ RAG ์์คํ
์ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ด์ฉ ๊ธฐ๋ฐ ์๋ต ์์ฑ
|
| 1758 |
+
try:
|
| 1759 |
+
# RAG ๊ฒ์์ ํตํด ๋ฌธ์ ๋ด์ฉ์ ํฌํจํ ํ๋กฌํํธ ์์ฑ
|
| 1760 |
+
summary_query = f"์
๋ก๋๋ ๋ฌธ์ '{file.filename}'์ ์ฃผ์ ๋ด์ฉ์ ์์ฝํด์ฃผ์ธ์."
|
| 1761 |
+
|
| 1762 |
+
# RAG ์๋ต ์์ฑ (๋ฌธ์ ๋ด์ฉ ํฌํจ)
|
| 1763 |
+
rag_result = rag_processor.generate_rag_response(
|
| 1764 |
+
user_id, document_id, summary_query, llm_model=model
|
| 1765 |
+
)
|
| 1766 |
+
|
| 1767 |
+
if rag_result["success"]:
|
| 1768 |
+
logger.info(f"โ
์๋ AI ์๋ต ์์ฑ ์๋ฃ: {len(rag_result['response'])} ๋ฌธ์")
|
| 1769 |
+
result["auto_response"] = rag_result["response"]
|
| 1770 |
+
else:
|
| 1771 |
+
logger.warning(f"โ ๏ธ ์๋ AI ์๋ต ์์ฑ ์คํจ: {rag_result.get('error', 'Unknown error')}")
|
| 1772 |
+
# ๐ RAG ์คํจ ์ generate_sync ์ฌ์ฉ (fallback)
|
| 1773 |
+
if model and hasattr(model, 'generate'):
|
| 1774 |
+
try:
|
| 1775 |
+
from .app_v2 import generate_sync
|
| 1776 |
+
|
| 1777 |
+
# ๋ฌธ์ ๋ด์ฉ์ ํฌํจํ ํ๋กฌํํธ ์์ฑ
|
| 1778 |
+
context_prompt = f"""
|
| 1779 |
+
๋ค์ ๋ฌธ์์ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ์์ฝํด์ฃผ์ธ์:
|
| 1780 |
+
|
| 1781 |
+
๋ฌธ์๋ช
: {file.filename}
|
| 1782 |
+
๋ฌธ์ ID: {document_id}
|
| 1783 |
+
|
| 1784 |
+
๋ฌธ์ ๋ด์ฉ:
|
| 1785 |
+
{result.get('chunks', [])}
|
| 1786 |
+
|
| 1787 |
+
์ ๋ฌธ์์ ์ฃผ์ ๋ด์ฉ์ ์์ฝํด์ฃผ์ธ์.
|
| 1788 |
+
"""
|
| 1789 |
+
|
| 1790 |
+
response = generate_sync(
|
| 1791 |
+
prompt=context_prompt,
|
| 1792 |
+
image_data_list=None,
|
| 1793 |
+
session_id=None
|
| 1794 |
+
)
|
| 1795 |
+
|
| 1796 |
+
if response and "response" in response:
|
| 1797 |
+
result["auto_response"] = response["response"]
|
| 1798 |
+
logger.info(f"โ
fallback AI ์๋ต ์์ฑ ์๋ฃ: {len(response['response'])} ๋ฌธ์")
|
| 1799 |
+
else:
|
| 1800 |
+
result["auto_response"] = "๋ฌธ์ ์์ฝ์ ์์ฑํ ์ ์์ต๋๋ค."
|
| 1801 |
+
logger.warning(f"โ ๏ธ generate_sync ์๋ต ํ์ ์ค๋ฅ")
|
| 1802 |
+
|
| 1803 |
+
except Exception as e:
|
| 1804 |
+
logger.error(f"โ fallback generate_sync ํธ์ถ ์คํจ: {e}")
|
| 1805 |
+
result["auto_response"] = "๋ฌธ์ ์์ฝ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."
|
| 1806 |
+
else:
|
| 1807 |
+
result["auto_response"] = "๋ฌธ์ ์์ฝ์ ์์ฑํ ์ ์์ต๋๋ค."
|
| 1808 |
+
|
| 1809 |
+
except Exception as e:
|
| 1810 |
+
logger.error(f"โ RAG ์๋ต ์์ฑ ์ค ์ค๋ฅ: {e}")
|
| 1811 |
+
result["auto_response"] = "๋ฌธ์ ์์ฝ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."
|
| 1812 |
|
| 1813 |
except Exception as e:
|
| 1814 |
logger.error(f"โ ์๋ AI ์๋ต ์์ฑ ์ค ์ค๋ฅ: {e}")
|
| 1815 |
+
result["auto_response"] = "๋ฌธ์ ์์ฝ ์์ฑ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค."
|
| 1816 |
|
| 1817 |
return DocumentUploadResponse(
|
| 1818 |
success=result["success"],
|
lily_llm_api/models/kanana_1_5_v_3b_instruct.py
CHANGED
|
@@ -243,6 +243,7 @@ class Kanana15V3bInstructProfile:
|
|
| 243 |
"<|im_start|>assistant\n",
|
| 244 |
"<|im_end|>",
|
| 245 |
"<|im_in_end|>",
|
|
|
|
| 246 |
"<image>",
|
| 247 |
"user\n",
|
| 248 |
"assistant\n"
|
|
|
|
| 243 |
"<|im_start|>assistant\n",
|
| 244 |
"<|im_end|>",
|
| 245 |
"<|im_in_end|>",
|
| 246 |
+
"<|-im_end|>", # ๐ ์๋ชป๋ ํ ํฐ ์ถ๊ฐ
|
| 247 |
"<image>",
|
| 248 |
"user\n",
|
| 249 |
"assistant\n"
|
lily_llm_api/models/polyglot_ko_1_3b_chat.py
CHANGED
|
@@ -184,6 +184,7 @@ class PolyglotKo13bChatProfile:
|
|
| 184 |
"user:",
|
| 185 |
"<|im_start|>user",
|
| 186 |
"<|im_end|>",
|
|
|
|
| 187 |
"<|im_start|>assistant",
|
| 188 |
"<|im_start|>system"
|
| 189 |
]
|
|
|
|
| 184 |
"user:",
|
| 185 |
"<|im_start|>user",
|
| 186 |
"<|im_end|>",
|
| 187 |
+
"<|-im_end|>", # ๐ ์๋ชป๋ ํ ํฐ ์ถ๊ฐ
|
| 188 |
"<|im_start|>assistant",
|
| 189 |
"<|im_start|>system"
|
| 190 |
]
|
lily_llm_api/models/polyglot_ko_5_8b_chat.py
CHANGED
|
@@ -139,6 +139,17 @@ class PolyglotKo58bChatProfile:
|
|
| 139 |
|
| 140 |
logger.info(f"์ถ์ถ๋ ์๋ต: {response}")
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
# ์๋ต ํ์ง ๊ฒ์ฆ ๋ฐ ๊ฐ์
|
| 143 |
if not self._validate_response_quality(response):
|
| 144 |
logger.warning(f"โ ๏ธ ์๋ต ํ์ง์ด ๋ฎ์ต๋๋ค. ํ์ง ๊ฐ์ ์ ์์ ์ถ๊ฐํฉ๋๋ค.")
|
|
|
|
| 139 |
|
| 140 |
logger.info(f"์ถ์ถ๋ ์๋ต: {response}")
|
| 141 |
|
| 142 |
+
# ๐ ์๋ชป๋ ํ ํฐ ์ ๊ฑฐ
|
| 143 |
+
if response:
|
| 144 |
+
# <|-im_end|> ๊ฐ์ ์๋ชป๋ ํ ํฐ ์ ๊ฑฐ
|
| 145 |
+
cleaned_response = response.replace('<|-im_end|>', '').replace('<|im_end|>', '')
|
| 146 |
+
# ์๋ค ๊ณต๋ฐฑ ์ ๊ฑฐ
|
| 147 |
+
cleaned_response = cleaned_response.strip()
|
| 148 |
+
|
| 149 |
+
if cleaned_response != response:
|
| 150 |
+
logger.info(f"๐ง ์๋ชป๋ ํ ํฐ ์ ๊ฑฐ๋จ: {len(response)} โ {len(cleaned_response)}")
|
| 151 |
+
response = cleaned_response
|
| 152 |
+
|
| 153 |
# ์๋ต ํ์ง ๊ฒ์ฆ ๋ฐ ๊ฐ์
|
| 154 |
if not self._validate_response_quality(response):
|
| 155 |
logger.warning(f"โ ๏ธ ์๋ต ํ์ง์ด ๋ฎ์ต๋๋ค. ํ์ง ๊ฐ์ ์ ์์ ์ถ๊ฐํฉ๋๋ค.")
|
lily_llm_core/document_processor.py
CHANGED
|
@@ -112,8 +112,10 @@ class DocumentProcessor:
|
|
| 112 |
extension = path_obj.suffix.lower()
|
| 113 |
|
| 114 |
if extension:
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
else:
|
| 118 |
logger.warning(f"โ ๏ธ ํ์ผ ํ์ฅ์๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค: {file_path}")
|
| 119 |
return None
|
|
|
|
| 112 |
extension = path_obj.suffix.lower()
|
| 113 |
|
| 114 |
if extension:
|
| 115 |
+
# ๐ ํ์ฅ์ ์์ ์ (.) ์ ๊ฑฐํ์ฌ ๋ฐํ
|
| 116 |
+
file_type = extension[1:] if extension.startswith('.') else extension
|
| 117 |
+
logger.info(f"๐ ํ์ผ ํ์ฅ์ ์ธ์: {extension} -> {file_type}")
|
| 118 |
+
return file_type
|
| 119 |
else:
|
| 120 |
logger.warning(f"โ ๏ธ ํ์ผ ํ์ฅ์๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค: {file_path}")
|
| 121 |
return None
|
lily_llm_core/rag_processor.py
CHANGED
|
@@ -329,6 +329,26 @@ class RAGProcessor:
|
|
| 329 |
if hasattr(llm_model, 'generate'):
|
| 330 |
# ์ค์ LLM ๋ชจ๋ธ ์ฌ์ฉ
|
| 331 |
response = llm_model.generate(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
else:
|
| 333 |
# ๋ชจ์ ์๋ต (ํ
์คํธ์ฉ)
|
| 334 |
response = f"RAG ๊ธฐ๋ฐ ์๋ต: {prompt[:100]}..."
|
|
|
|
| 329 |
if hasattr(llm_model, 'generate'):
|
| 330 |
# ์ค์ LLM ๋ชจ๋ธ ์ฌ์ฉ
|
| 331 |
response = llm_model.generate(prompt)
|
| 332 |
+
|
| 333 |
+
# ๐ tensor๋ฅผ ๋ฌธ์์ด๋ก ๋ณํ
|
| 334 |
+
if hasattr(response, 'tolist'):
|
| 335 |
+
# tensor์ธ ๊ฒฝ์ฐ ๋ฌธ์์ด๋ก ๋ณํ
|
| 336 |
+
import torch
|
| 337 |
+
if isinstance(response, torch.Tensor):
|
| 338 |
+
# ํ ํฐ ID๋ฅผ ํ
์คํธ๋ก ๋์ฝ๋ฉ
|
| 339 |
+
if hasattr(llm_model, 'tokenizer'):
|
| 340 |
+
try:
|
| 341 |
+
response = llm_model.tokenizer.decode(response[0], skip_special_tokens=True)
|
| 342 |
+
except:
|
| 343 |
+
response = str(response.tolist())
|
| 344 |
+
else:
|
| 345 |
+
response = str(response.tolist())
|
| 346 |
+
else:
|
| 347 |
+
response = str(response)
|
| 348 |
+
elif not isinstance(response, str):
|
| 349 |
+
# ๋ฌธ์์ด์ด ์๋ ๊ฒฝ์ฐ ๋ฌธ์์ด๋ก ๋ณํ
|
| 350 |
+
response = str(response)
|
| 351 |
+
|
| 352 |
else:
|
| 353 |
# ๋ชจ์ ์๋ต (ํ
์คํธ์ฉ)
|
| 354 |
response = f"RAG ๊ธฐ๋ฐ ์๋ต: {prompt[:100]}..."
|
requirements.txt
CHANGED
|
@@ -4,10 +4,8 @@
|
|
| 4 |
numpy==1.26.4
|
| 5 |
torch==2.3.1
|
| 6 |
torchvision==0.18.1
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
transformers
|
| 10 |
-
tokenizers
|
| 11 |
peft==0.10.0
|
| 12 |
accelerate==0.30.1
|
| 13 |
bitsandbytes
|
|
@@ -17,6 +15,10 @@ safetensors
|
|
| 17 |
easyocr
|
| 18 |
opencv-python-headless
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Web Framework & Parsers
|
| 21 |
fastapi
|
| 22 |
uvicorn[standard]
|
|
|
|
| 4 |
numpy==1.26.4
|
| 5 |
torch==2.3.1
|
| 6 |
torchvision==0.18.1
|
| 7 |
+
transformers==4.55.2
|
| 8 |
+
tokenizers==0.21.4
|
|
|
|
|
|
|
| 9 |
peft==0.10.0
|
| 10 |
accelerate==0.30.1
|
| 11 |
bitsandbytes
|
|
|
|
| 15 |
easyocr
|
| 16 |
opencv-python-headless
|
| 17 |
|
| 18 |
+
# DOC
|
| 19 |
+
langchain-community
|
| 20 |
+
langchain
|
| 21 |
+
|
| 22 |
# Web Framework & Parsers
|
| 23 |
fastapi
|
| 24 |
uvicorn[standard]
|