gbrabbit commited on
Commit
4def2a8
ยท
1 Parent(s): e3c60d5

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
- else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- rag_result = rag_processor.generate_rag_response(
1645
- user_id, document_id, summary_query, llm_model=model
1646
- )
1647
-
1648
- if rag_result["success"]:
1649
- logger.info(f"โœ… ์ž๋™ AI ์‘๋‹ต ์ƒ์„ฑ ์™„๋ฃŒ: {len(rag_result['response'])} ๋ฌธ์ž")
1650
- result["auto_response"] = rag_result["response"]
1651
- else:
1652
- logger.warning(f"โš ๏ธ ์ž๋™ AI ์‘๋‹ต ์ƒ์„ฑ ์‹คํŒจ: {rag_result.get('error', 'Unknown error')}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- logger.info(f"๐Ÿ“„ ํŒŒ์ผ ํ™•์žฅ์ž ์ธ์‹: {extension}")
116
- return extension
 
 
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
- # transformers==4.29.2
8
- # tokenizers==0.13.3
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]