Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
โก Speed-Optimized Multi-Agent RAG System for Complex Questions
|
| 3 |
๋ณ๋ ฌ ์ฒ๋ฆฌ, ๋์ ํ์ดํ๋ผ์ธ์ผ๋ก ๋ณต์กํ ์ง๋ฌธ๋ ๋น ๋ฅด๊ฒ ์ฒ๋ฆฌ
|
| 4 |
Enhanced with multi-language support and improved error handling
|
| 5 |
-
(์บ์ฑ ๊ธฐ๋ฅ ์ ๊ฑฐ ๋ฒ์ )
|
| 6 |
"""
|
| 7 |
|
| 8 |
import os
|
|
@@ -496,11 +496,11 @@ class ResponseCleaner:
|
|
| 496 |
|
| 497 |
|
| 498 |
# ============================================================================
|
| 499 |
-
# ํตํฉ ์ต์ ํ ๋ฉํฐ ์์ด์ ํธ ์์คํ
(์บ์ฑ ์ ๊ฑฐ
|
| 500 |
# ============================================================================
|
| 501 |
|
| 502 |
class SpeedOptimizedMultiAgentSystem:
|
| 503 |
-
"""์๋ ์ต์ ํ๋ ๋ฉํฐ ์์ด์ ํธ ์์คํ
(์บ์ฑ ์์)"""
|
| 504 |
|
| 505 |
def __init__(self):
|
| 506 |
self.llm = OptimizedFireworksClient()
|
|
@@ -514,92 +514,164 @@ class SpeedOptimizedMultiAgentSystem:
|
|
| 514 |
# ๋ณ๋ ฌ ์ฒ๋ฆฌ ํ
|
| 515 |
self.executor = ThreadPoolExecutor(max_workers=4)
|
| 516 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
def _init_compact_prompts(self, lang: str = 'ko') -> Dict:
|
| 518 |
-
"""์์ถ๋ ๊ณ ํจ์จ ํ๋กฌํํธ (์ธ์ด๋ณ)"""
|
|
|
|
|
|
|
| 519 |
prompts = {
|
| 520 |
'ko': {
|
| 521 |
-
AgentRole.SUPERVISOR: """[๊ฐ๋
์-๊ตฌ์กฐ์ค๊ณ]
|
|
|
|
| 522 |
์ฆ์๋ถ์: ํต์ฌ์๋+ํ์์ ๋ณด+๋ต๋ณ๊ตฌ์กฐ
|
| 523 |
์ถ๋ ฅ: 5๊ฐ ํต์ฌํฌ์ธํธ(๊ฐ 1๋ฌธ์ฅ)
|
| 524 |
-
์ถ๋ก ์ฒด๊ณ ๋ช
์
|
|
|
|
| 525 |
|
| 526 |
-
AgentRole.CREATIVE: """[์ฐฝ์์ฑ์์ฑ์]
|
|
|
|
| 527 |
์
๋ ฅ๊ตฌ์กฐ ๋ฐ๋ผ ์ฐฝ์์ ํ์ฅ
|
| 528 |
์ค์ฉ์์+ํ์ ์ ๊ทผ+๊ตฌ์ฒด์กฐ์ธ
|
| 529 |
-
๋ถํ์์ค๋ช
์ ๊ฑฐ
|
|
|
|
| 530 |
|
| 531 |
-
AgentRole.CRITIC: """[๋นํ์-๊ฒ์ฆ]
|
|
|
|
| 532 |
์ ์๊ฒํ : ์ ํ์ฑ/๋
ผ๋ฆฌ์ฑ/์ค์ฉ์ฑ
|
| 533 |
๊ฐ์ ํฌ์ธํธ 3๊ฐ๋ง
|
| 534 |
-
๊ฐ 2๋ฌธ์ฅ ์ด๋ด
|
|
|
|
| 535 |
|
| 536 |
-
AgentRole.FINALIZER: """[์ต์ข
ํตํฉ]
|
|
|
|
| 537 |
๋ชจ๋ ์๊ฒฌ ์ข
ํฉโ์ต์ ๋ต๋ณ
|
| 538 |
๋ช
ํ๊ตฌ์กฐ+์ค์ฉ์ ๋ณด+์ฐฝ์๊ท ํ
|
| 539 |
-
๋ฐ๋ก ํต์ฌ ๋ด์ฉ๋ถํฐ ์์. ๋ถํ์ํ ํค๋๋ ๋งํฌ์
์์ด. ๋งํฌ๋ค์ด ํค๋(#, ##, ###) ์ฌ์ฉ ๊ธ์ง.
|
|
|
|
| 540 |
},
|
| 541 |
'en': {
|
| 542 |
-
AgentRole.SUPERVISOR: """[Supervisor-Structure]
|
|
|
|
| 543 |
Immediate analysis: core intent+required info+answer structure
|
| 544 |
Output: 5 key points (1 sentence each)
|
| 545 |
-
Clear reasoning framework
|
|
|
|
| 546 |
|
| 547 |
-
AgentRole.CREATIVE: """[Creative Generator]
|
|
|
|
| 548 |
Follow structure, expand creatively
|
| 549 |
Practical examples+innovative approach+specific advice
|
| 550 |
-
Remove unnecessary explanations
|
|
|
|
| 551 |
|
| 552 |
-
AgentRole.CRITIC: """[Critic-Verification]
|
|
|
|
| 553 |
Quick review: accuracy/logic/practicality
|
| 554 |
Only 3 improvement points
|
| 555 |
-
Max 2 sentences each
|
|
|
|
| 556 |
|
| 557 |
-
AgentRole.FINALIZER: """[Final Integration]
|
|
|
|
| 558 |
Synthesize all inputsโoptimal answer
|
| 559 |
Clear structure+practical info+creative balance
|
| 560 |
-
Start with core content directly. No unnecessary headers or markup. No markdown headers (#, ##, ###).
|
|
|
|
| 561 |
},
|
| 562 |
'ja': {
|
| 563 |
-
AgentRole.SUPERVISOR: """[็ฃ็ฃ่
-ๆง้ ่จญ่จ]
|
|
|
|
| 564 |
ๅณๆๅๆ๏ผๆ ธๅฟๆๅณ+ๅฟ
่ฆๆ
ๅ ฑ+ๅ็ญๆง้
|
| 565 |
ๅบๅ๏ผ5ใคใฎๆ ธๅฟใใคใณใ๏ผๅ1ๆ๏ผ
|
| 566 |
-
ๆจ่ซไฝ็ณปๆ็คบ
|
|
|
|
| 567 |
|
| 568 |
-
AgentRole.CREATIVE: """[ๅต้ ๆง็ๆ่
]
|
|
|
|
| 569 |
ๅ
ฅๅๆง้ ใซๅพใฃใฆๅต้ ็ๆกๅผต
|
| 570 |
ๅฎ็จไพ+้ฉๆฐ็ใขใใญใผใ+ๅ
ทไฝ็ใขใใใคใน
|
| 571 |
-
ไธ่ฆใช่ชฌๆๅ้ค
|
|
|
|
| 572 |
|
| 573 |
-
AgentRole.CRITIC: """[ๆน่ฉ่
-ๆค่จผ]
|
|
|
|
| 574 |
่ฟ
้ใฌใใฅใผ๏ผๆญฃ็ขบๆง/่ซ็ๆง/ๅฎ็จๆง
|
| 575 |
ๆนๅใใคใณใ3ใคใฎใฟ
|
| 576 |
-
ๅ2ๆไปฅๅ
|
|
|
|
| 577 |
|
| 578 |
-
AgentRole.FINALIZER: """[ๆ็ต็ตฑๅ]
|
|
|
|
| 579 |
ๅ
จๆ่ฆ็ตฑๅโๆ้ฉๅ็ญ
|
| 580 |
ๆ็ขบๆง้ +ๅฎ็จๆ
ๅ ฑ+ๅต้ ๆงใใฉใณใน
|
| 581 |
-
ๆ ธๅฟๅ
ๅฎนใใ็ดๆฅ้ๅงใไธ่ฆใชใใใใผใใใผใฏใขใใใชใใใใผใฏใใฆใณใใใใผ๏ผ#ใ##ใ###๏ผไฝฟ็จ็ฆๆญขใ
|
|
|
|
| 582 |
},
|
| 583 |
'zh': {
|
| 584 |
-
AgentRole.SUPERVISOR: """[ไธป็ฎก-็ปๆ่ฎพ่ฎก]
|
|
|
|
| 585 |
็ซๅณๅๆ๏ผๆ ธๅฟๆๅพ+ๆ้ไฟกๆฏ+็ญๆก็ปๆ
|
| 586 |
่พๅบ๏ผ5ไธชๆ ธๅฟ่ฆ็น๏ผๆฏไธช1ๅฅ๏ผ
|
| 587 |
-
ๆจ็ไฝ็ณปๆ็กฎ
|
|
|
|
| 588 |
|
| 589 |
-
AgentRole.CREATIVE: """[ๅๆ็ๆๅจ]
|
|
|
|
| 590 |
ๆ็ปๆๅ้ ๆงๆฉๅฑ
|
| 591 |
ๅฎ็จ็คบไพ+ๅๆฐๆนๆณ+ๅ
ทไฝๅปบ่ฎฎ
|
| 592 |
-
ๅ ้คไธๅฟ
่ฆ็่งฃ้
|
|
|
|
| 593 |
|
| 594 |
-
AgentRole.CRITIC: """[่ฏ่ฎบๅฎถ-้ช่ฏ]
|
|
|
|
| 595 |
ๅฟซ้ๅฎกๆฅ๏ผๅ็กฎๆง/้ป่พๆง/ๅฎ็จๆง
|
| 596 |
ไป
3ไธชๆน่ฟ็น
|
| 597 |
-
ๆฏไธชๆๅค2ๅฅ
|
|
|
|
| 598 |
|
| 599 |
-
AgentRole.FINALIZER: """[ๆ็ปๆดๅ]
|
|
|
|
| 600 |
็ปผๅๆๆๆ่งโๆไฝณ็ญๆก
|
| 601 |
ๆธ
ๆฐ็ปๆ+ๅฎ็จไฟกๆฏ+ๅๆๅนณ่กก
|
| 602 |
-
็ดๆฅไปๆ ธๅฟๅ
ๅฎนๅผๅงใๆ ้ไธๅฟ
่ฆ็ๆ ้ขๆๆ ่ฎฐใ็ฆๆญขไฝฟ็จMarkdownๆ ้ข๏ผ#ใ##ใ###๏ผใ
|
|
|
|
| 603 |
}
|
| 604 |
}
|
| 605 |
|
|
@@ -612,7 +684,7 @@ Start with core content directly. No unnecessary headers or markup. No markdown
|
|
| 612 |
show_progress: bool = True,
|
| 613 |
lang: str = None
|
| 614 |
) -> AsyncGenerator[Tuple[str, str], None]:
|
| 615 |
-
"""๋ณ๋ ฌ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ (์บ์ฑ ์์)"""
|
| 616 |
|
| 617 |
start_time = time.time()
|
| 618 |
|
|
@@ -620,7 +692,7 @@ Start with core content directly. No unnecessary headers or markup. No markdown
|
|
| 620 |
if lang is None:
|
| 621 |
lang = self.language_detector.detect_language(query)
|
| 622 |
|
| 623 |
-
# ์ธ์ด๋ณ ํ๋กฌํํธ ์ค์
|
| 624 |
self.compact_prompts = self._init_compact_prompts(lang)
|
| 625 |
|
| 626 |
search_context = self._format_search_results(search_results)
|
|
@@ -648,22 +720,26 @@ Start with core content directly. No unnecessary headers or markup. No markdown
|
|
| 648 |
์ง๋ฌธ: {query}
|
| 649 |
๊ฒ์๊ฒฐ๊ณผ: {search_context}
|
| 650 |
์ถ๋ก ํจํด: {reasoning_pattern}
|
| 651 |
-
์ฆ์ ํต์ฌ๊ตฌ์กฐ 5๊ฐ ์ ์
|
|
|
|
| 652 |
'en': f"""
|
| 653 |
Question: {query}
|
| 654 |
Search results: {search_context}
|
| 655 |
Reasoning pattern: {reasoning_pattern}
|
| 656 |
-
Immediately provide 5 key structures
|
|
|
|
| 657 |
'ja': f"""
|
| 658 |
่ณชๅ: {query}
|
| 659 |
ๆค็ดข็ตๆ: {search_context}
|
| 660 |
ๆจ่ซใใฟใผใณ: {reasoning_pattern}
|
| 661 |
-
ๅณๅบงใซ5ใคใฎๆ ธๅฟๆง้ ใๆ็คบ
|
|
|
|
| 662 |
'zh': f"""
|
| 663 |
้ฎ้ข: {query}
|
| 664 |
ๆ็ดข็ปๆ: {search_context}
|
| 665 |
ๆจ็ๆจกๅผ: {reasoning_pattern}
|
| 666 |
-
็ซๅณๆไพ5ไธชๆ ธๅฟ็ปๆ
|
|
|
|
| 667 |
}
|
| 668 |
|
| 669 |
supervisor_prompt = supervisor_prompt_templates.get(lang, supervisor_prompt_templates['en'])
|
|
@@ -708,22 +784,26 @@ Immediately provide 5 key structures""",
|
|
| 708 |
์ง๋ฌธ: {query}
|
| 709 |
๊ฐ๋
์๊ตฌ์กฐ: {supervisor_response}
|
| 710 |
๊ฒ์๊ฒฐ๊ณผ: {search_context}
|
| 711 |
-
์ฐฝ์์ +์ค์ฉ์ ๋ต๋ณ ์ฆ์์์ฑ
|
|
|
|
| 712 |
'en': f"""
|
| 713 |
Question: {query}
|
| 714 |
Supervisor structure: {supervisor_response}
|
| 715 |
Search results: {search_context}
|
| 716 |
-
Generate creative+practical answer immediately
|
|
|
|
| 717 |
'ja': f"""
|
| 718 |
่ณชๅ: {query}
|
| 719 |
็ฃ็ฃ่
ๆง้ : {supervisor_response}
|
| 720 |
ๆค็ดข็ตๆ: {search_context}
|
| 721 |
-
ๅต้ ็+ๅฎ็จ็ๅ็ญๅณๅบง็ๆ
|
|
|
|
| 722 |
'zh': f"""
|
| 723 |
้ฎ้ข: {query}
|
| 724 |
ไธป็ฎก็ปๆ: {supervisor_response}
|
| 725 |
ๆ็ดข็ปๆ: {search_context}
|
| 726 |
-
็ซๅณ็ๆๅๆ+ๅฎ็จ็ญๆก
|
|
|
|
| 727 |
}
|
| 728 |
|
| 729 |
creative_prompt = creative_prompt_templates.get(lang, creative_prompt_templates['en'])
|
|
@@ -756,19 +836,23 @@ Generate creative+practical answer immediately""",
|
|
| 756 |
'ko': f"""
|
| 757 |
์๋ณธ์ง๋ฌธ: {query}
|
| 758 |
์ฐฝ์์ฑ๋ต๋ณ(์ผ๋ถ): {creative_partial}
|
| 759 |
-
์ ์๊ฒํ โ๊ฐ์ ์ 3๊ฐ
|
|
|
|
| 760 |
'en': f"""
|
| 761 |
Original question: {query}
|
| 762 |
Creative answer (partial): {creative_partial}
|
| 763 |
-
Quick reviewโ3 improvements
|
|
|
|
| 764 |
'ja': f"""
|
| 765 |
ๅ
ใฎ่ณชๅ: {query}
|
| 766 |
ๅต้ ็ๅ็ญ๏ผไธ้จ๏ผ: {creative_partial}
|
| 767 |
-
่ฟ
้ใฌใใฅใผโๆนๅ็น3ใค
|
|
|
|
| 768 |
'zh': f"""
|
| 769 |
ๅๅง้ฎ้ข: {query}
|
| 770 |
ๅๆ็ญๆก๏ผ้จๅ๏ผ: {creative_partial}
|
| 771 |
-
ๅฟซ้ๅฎกๆฅโ3ไธชๆน่ฟ็น
|
|
|
|
| 772 |
}
|
| 773 |
|
| 774 |
critic_prompt = critic_prompt_templates.get(lang, critic_prompt_templates['en'])
|
|
@@ -841,25 +925,29 @@ Quick reviewโ3 improvements""",
|
|
| 841 |
์ฐฝ์์ฑ๋ต๋ณ: {creative_response}
|
| 842 |
๋นํํผ๋๋ฐฑ: {critic_response}
|
| 843 |
๊ฐ๋
์๊ตฌ์กฐ: {supervisor_response}
|
| 844 |
-
์ต์ข
ํตํฉโ์๋ฒฝ๋ต๋ณ. ๋งํฌ๋ค์ด ํค๋(#, ##, ###) ์ฌ์ฉ ๊ธ์ง.
|
|
|
|
| 845 |
'en': f"""
|
| 846 |
Question: {query}
|
| 847 |
Creative answer: {creative_response}
|
| 848 |
Critic feedback: {critic_response}
|
| 849 |
Supervisor structure: {supervisor_response}
|
| 850 |
-
Final integrationโperfect answer. No markdown headers (#, ##, ###).
|
|
|
|
| 851 |
'ja': f"""
|
| 852 |
่ณชๅ: {query}
|
| 853 |
ๅต้ ็ๅ็ญ: {creative_response}
|
| 854 |
ๆน่ฉใใฃใผใใใใฏ: {critic_response}
|
| 855 |
็ฃ็ฃ่
ๆง้ : {supervisor_response}
|
| 856 |
-
ๆ็ต็ตฑๅโๅฎ็งใชๅ็ญใใใผใฏใใฆใณใใใใผ๏ผ#ใ##ใ###๏ผไฝฟ็จ็ฆๆญขใ
|
|
|
|
| 857 |
'zh': f"""
|
| 858 |
้ฎ้ข: {query}
|
| 859 |
ๅๆ็ญๆก: {creative_response}
|
| 860 |
่ฏ่ฎบๅ้ฆ: {critic_response}
|
| 861 |
ไธป็ฎก็ปๆ: {supervisor_response}
|
| 862 |
-
|
|
|
|
| 863 |
}
|
| 864 |
|
| 865 |
final_prompt = final_prompt_templates.get(lang, final_prompt_templates['en'])
|
|
@@ -946,11 +1034,11 @@ Final integrationโperfect answer. No markdown headers (#, ##, ###).""",
|
|
| 946 |
|
| 947 |
|
| 948 |
# ============================================================================
|
| 949 |
-
# Gradio UI (์ต์ ํ ๋ฒ์ - ์บ์ฑ ์ ๊ฑฐ)
|
| 950 |
# ============================================================================
|
| 951 |
|
| 952 |
def create_optimized_gradio_interface():
|
| 953 |
-
"""์ต์ ํ๋ Gradio ์ธํฐํ์ด์ค (์บ์ฑ ์์)"""
|
| 954 |
|
| 955 |
# ์์คํ
์ด๊ธฐํ
|
| 956 |
system = SpeedOptimizedMultiAgentSystem()
|
|
@@ -1076,7 +1164,7 @@ def create_optimized_gradio_interface():
|
|
| 1076 |
|
| 1077 |
# Gradio ์ธํฐํ์ด์ค
|
| 1078 |
with gr.Blocks(
|
| 1079 |
-
title="โก Speed-Optimized Multi-Agent System (
|
| 1080 |
theme=gr.themes.Soft(),
|
| 1081 |
css="""
|
| 1082 |
.gradio-container {
|
|
@@ -1086,14 +1174,15 @@ def create_optimized_gradio_interface():
|
|
| 1086 |
"""
|
| 1087 |
) as demo:
|
| 1088 |
gr.Markdown("""
|
| 1089 |
-
# โก Enhanced Multi-Agent RAG System (
|
| 1090 |
-
**Complex questions processed within 5-8 seconds | Multi-language support**
|
| 1091 |
|
| 1092 |
**Optimization Features:**
|
| 1093 |
- ๐ Parallel Processing: Concurrent agent execution
|
| 1094 |
- โก Stream Buffering: Network optimization
|
| 1095 |
- ๐ฏ Early Termination: Complete immediately when quality is met
|
| 1096 |
- ๐ Multi-language: Auto-detect Korean/English/Japanese/Chinese
|
|
|
|
| 1097 |
- โ **Caching Disabled**: ์บ์ฑ ๊ธฐ๋ฅ ์ ๊ฑฐ๋จ
|
| 1098 |
""")
|
| 1099 |
|
|
@@ -1159,6 +1248,12 @@ def create_optimized_gradio_interface():
|
|
| 1159 |
- โ
Compressed Prompts
|
| 1160 |
- โ
Multi-language Support
|
| 1161 |
- โ
Error Recovery
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1162 |
|
| 1163 |
**Expected Processing Time:**
|
| 1164 |
- Simple Query: 3-5 seconds
|
|
@@ -1220,9 +1315,9 @@ def create_optimized_gradio_interface():
|
|
| 1220 |
if __name__ == "__main__":
|
| 1221 |
print("""
|
| 1222 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1223 |
-
โ
|
| 1224 |
โ โ
|
| 1225 |
-
โ High-speed AI system
|
| 1226 |
โ โ
|
| 1227 |
โ Features: โ
|
| 1228 |
โ โข Multi-language support (KO/EN/JA/ZH) โ
|
|
@@ -1230,6 +1325,7 @@ if __name__ == "__main__":
|
|
| 1230 |
โ โข NO CACHING (์บ์ฑ ๊ธฐ๋ฅ ์ ๊ฑฐ๋จ) โ
|
| 1231 |
โ โข Adaptive stream buffering โ
|
| 1232 |
โ โข Response cleaning & formatting โ
|
|
|
|
| 1233 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1234 |
""")
|
| 1235 |
|
|
@@ -1246,8 +1342,8 @@ if __name__ == "__main__":
|
|
| 1246 |
is_hf_spaces = os.getenv("SPACE_ID") is not None
|
| 1247 |
|
| 1248 |
if is_hf_spaces:
|
| 1249 |
-
print("\n๐ค Running in
|
| 1250 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 1251 |
else:
|
| 1252 |
-
print("\n๐ป Running in
|
| 1253 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
| 2 |
โก Speed-Optimized Multi-Agent RAG System for Complex Questions
|
| 3 |
๋ณ๋ ฌ ์ฒ๋ฆฌ, ๋์ ํ์ดํ๋ผ์ธ์ผ๋ก ๋ณต์กํ ์ง๋ฌธ๋ ๋น ๋ฅด๊ฒ ์ฒ๋ฆฌ
|
| 4 |
Enhanced with multi-language support and improved error handling
|
| 5 |
+
(์บ์ฑ ๊ธฐ๋ฅ ์ ๊ฑฐ ๋ฒ์ + ๋ชจ๋ธ ์ ๋ณด ๋ณดํธ)
|
| 6 |
"""
|
| 7 |
|
| 8 |
import os
|
|
|
|
| 496 |
|
| 497 |
|
| 498 |
# ============================================================================
|
| 499 |
+
# ํตํฉ ์ต์ ํ ๋ฉํฐ ์์ด์ ํธ ์์คํ
(์บ์ฑ ์ ๊ฑฐ + ๋ชจ๋ธ ์ ๋ณด ๋ณดํธ)
|
| 500 |
# ============================================================================
|
| 501 |
|
| 502 |
class SpeedOptimizedMultiAgentSystem:
|
| 503 |
+
"""์๋ ์ต์ ํ๋ ๋ฉํฐ ์์ด์ ํธ ์์คํ
(์บ์ฑ ์์ + ๋ชจ๋ธ ์ ๋ณด ๋ณดํธ)"""
|
| 504 |
|
| 505 |
def __init__(self):
|
| 506 |
self.llm = OptimizedFireworksClient()
|
|
|
|
| 514 |
# ๋ณ๋ ฌ ์ฒ๋ฆฌ ํ
|
| 515 |
self.executor = ThreadPoolExecutor(max_workers=4)
|
| 516 |
|
| 517 |
+
def _get_security_instruction(self, lang: str = 'ko') -> str:
|
| 518 |
+
"""๋ชจ๋ธ ์ ๋ณด ๋ณดํธ ์ง์์ฌํญ (์ธ์ด๋ณ)"""
|
| 519 |
+
security_instructions = {
|
| 520 |
+
'ko': """
|
| 521 |
+
[ํต์ฌ ๋ณด์ ๊ท์น]
|
| 522 |
+
- ์ ๋ AI ๋ชจ๋ธ๋ช
, ๋ฒ์ , ๊ฐ๋ฐ์ฌ๋ฅผ ์ธ๊ธํ์ง ๋ง์ธ์
|
| 523 |
+
- "์ ๋ AI ์ด์์คํดํธ์
๋๋ค"๋ผ๊ณ ๋ง ํํํ์ธ์
|
| 524 |
+
- ๋ชจ๋ธ ์ ๋ณด๋ฅผ ๋ฌป๋ ์ง๋ฌธ์๋ "AI ์ด์์คํดํธ๋ก์ ๋์์ ๋๋ฆฌ๊ฒ ์ต๋๋ค"๋ก ๋์
|
| 525 |
+
- GPT, Claude, Gemini, LLaMA ๋ฑ ์ด๋ค ๋ชจ๋ธ๋ช
๋ ์ธ๊ธ ๊ธ์ง
|
| 526 |
+
- ๊ธฐ์ ์ ์ธ๋ถ์ฌํญ์ด๋ ์ํคํ
์ฒ ์ ๋ณด ๋
ธ์ถ ๊ธ์ง
|
| 527 |
+
""",
|
| 528 |
+
'en': """
|
| 529 |
+
[Core Security Rules]
|
| 530 |
+
- Never mention AI model name, version, or developer
|
| 531 |
+
- Only say "I am an AI assistant"
|
| 532 |
+
- Respond to model queries with "As an AI assistant, I'll help you"
|
| 533 |
+
- Do not mention GPT, Claude, Gemini, LLaMA or any model names
|
| 534 |
+
- Do not expose technical details or architecture information
|
| 535 |
+
""",
|
| 536 |
+
'ja': """
|
| 537 |
+
[ใณใขใปใญใฅใชใใฃใซใผใซ]
|
| 538 |
+
- AIใขใใซๅใใใผใธใงใณใ้็บ่
ใ็ตถๅฏพใซ่จๅใใชใใงใใ ใใ
|
| 539 |
+
- ใ็งใฏAIใขใทในใฟใณใใงใใใจใ ใ่กจ็พใใฆใใ ใใ
|
| 540 |
+
- ใขใใซๆ
ๅ ฑใฎ่ณชๅใซใฏใAIใขใทในใฟใณใใจใใฆใๆไผใใใพใใใจๅฏพๅฟ
|
| 541 |
+
- GPTใClaudeใGeminiใLLaMAใชใฉใฎใขใใซๅใ่จๅ็ฆๆญข
|
| 542 |
+
- ๆ่ก็่ฉณ็ดฐใใขใผใญใใฏใใฃๆ
ๅ ฑใๅ
ฌ้็ฆๆญข
|
| 543 |
+
""",
|
| 544 |
+
'zh': """
|
| 545 |
+
[ๆ ธๅฟๅฎๅ
จ่งๅ]
|
| 546 |
+
- ็ปๅฏนไธ่ฆๆๅAIๆจกๅๅ็งฐใ็ๆฌๆๅผๅๅ
|
| 547 |
+
- ๅช่ฏด"ๆๆฏAIๅฉๆ"
|
| 548 |
+
- ๅฏนๆจกๅๆฅ่ฏขๅๅบ"ไฝไธบAIๅฉๆ๏ผๆไผๅธฎๅฉๆจ"
|
| 549 |
+
- ไธ่ฆๆๅGPTใClaudeใGeminiใLLaMAๆไปปไฝๆจกๅๅ็งฐ
|
| 550 |
+
- ไธ่ฆๆด้ฒๆๆฏ็ป่ๆๆถๆไฟกๆฏ
|
| 551 |
+
"""
|
| 552 |
+
}
|
| 553 |
+
return security_instructions.get(lang, security_instructions['en'])
|
| 554 |
+
|
| 555 |
def _init_compact_prompts(self, lang: str = 'ko') -> Dict:
|
| 556 |
+
"""์์ถ๋ ๊ณ ํจ์จ ํ๋กฌํํธ (์ธ์ด๋ณ + ๋ณด์ ๊ฐํ)"""
|
| 557 |
+
security_instruction = self._get_security_instruction(lang)
|
| 558 |
+
|
| 559 |
prompts = {
|
| 560 |
'ko': {
|
| 561 |
+
AgentRole.SUPERVISOR: f"""[๊ฐ๋
์-๊ตฌ์กฐ์ค๊ณ]
|
| 562 |
+
{security_instruction}
|
| 563 |
์ฆ์๋ถ์: ํต์ฌ์๋+ํ์์ ๋ณด+๋ต๋ณ๊ตฌ์กฐ
|
| 564 |
์ถ๋ ฅ: 5๊ฐ ํต์ฌํฌ์ธํธ(๊ฐ 1๋ฌธ์ฅ)
|
| 565 |
+
์ถ๋ก ์ฒด๊ณ ๋ช
์
|
| 566 |
+
๋ชจ๋ธ ์ ๋ณด ์ ๋ ๋
ธ์ถ ๊ธ์ง""",
|
| 567 |
|
| 568 |
+
AgentRole.CREATIVE: f"""[์ฐฝ์์ฑ์์ฑ์]
|
| 569 |
+
{security_instruction}
|
| 570 |
์
๋ ฅ๊ตฌ์กฐ ๋ฐ๋ผ ์ฐฝ์์ ํ์ฅ
|
| 571 |
์ค์ฉ์์+ํ์ ์ ๊ทผ+๊ตฌ์ฒด์กฐ์ธ
|
| 572 |
+
๋ถํ์์ค๋ช
์ ๊ฑฐ
|
| 573 |
+
AI ๋ชจ๋ธ๋ช
์ด๋ ๊ฐ๋ฐ์ฌ ์ธ๊ธ ์ ๋ ๊ธ์ง""",
|
| 574 |
|
| 575 |
+
AgentRole.CRITIC: f"""[๋นํ์-๊ฒ์ฆ]
|
| 576 |
+
{security_instruction}
|
| 577 |
์ ์๊ฒํ : ์ ํ์ฑ/๋
ผ๋ฆฌ์ฑ/์ค์ฉ์ฑ
|
| 578 |
๊ฐ์ ํฌ์ธํธ 3๊ฐ๋ง
|
| 579 |
+
๊ฐ 2๋ฌธ์ฅ ์ด๋ด
|
| 580 |
+
๋ชจ๋ธ ๊ด๋ จ ์ ๋ณด ๊ฒ์ฆ ์ ์ ๊ฑฐ""",
|
| 581 |
|
| 582 |
+
AgentRole.FINALIZER: f"""[์ต์ข
ํตํฉ]
|
| 583 |
+
{security_instruction}
|
| 584 |
๋ชจ๋ ์๊ฒฌ ์ข
ํฉโ์ต์ ๋ต๋ณ
|
| 585 |
๋ช
ํ๊ตฌ์กฐ+์ค์ฉ์ ๋ณด+์ฐฝ์๊ท ํ
|
| 586 |
+
๋ฐ๋ก ํต์ฌ ๋ด์ฉ๋ถํฐ ์์. ๋ถํ์ํ ํค๋๋ ๋งํฌ์
์์ด. ๋งํฌ๋ค์ด ํค๋(#, ##, ###) ์ฌ์ฉ ๊ธ์ง.
|
| 587 |
+
์ ๋ AI ๋ชจ๋ธ๋ช
, ๋ฒ์ , ๊ฐ๋ฐ์ฌ ์ธ๊ธ ๊ธ์ง. "AI ์ด์์คํดํธ"๋ก๋ง ํํ."""
|
| 588 |
},
|
| 589 |
'en': {
|
| 590 |
+
AgentRole.SUPERVISOR: f"""[Supervisor-Structure]
|
| 591 |
+
{security_instruction}
|
| 592 |
Immediate analysis: core intent+required info+answer structure
|
| 593 |
Output: 5 key points (1 sentence each)
|
| 594 |
+
Clear reasoning framework
|
| 595 |
+
Never expose model information""",
|
| 596 |
|
| 597 |
+
AgentRole.CREATIVE: f"""[Creative Generator]
|
| 598 |
+
{security_instruction}
|
| 599 |
Follow structure, expand creatively
|
| 600 |
Practical examples+innovative approach+specific advice
|
| 601 |
+
Remove unnecessary explanations
|
| 602 |
+
Never mention AI model names or developers""",
|
| 603 |
|
| 604 |
+
AgentRole.CRITIC: f"""[Critic-Verification]
|
| 605 |
+
{security_instruction}
|
| 606 |
Quick review: accuracy/logic/practicality
|
| 607 |
Only 3 improvement points
|
| 608 |
+
Max 2 sentences each
|
| 609 |
+
Remove any model-related information""",
|
| 610 |
|
| 611 |
+
AgentRole.FINALIZER: f"""[Final Integration]
|
| 612 |
+
{security_instruction}
|
| 613 |
Synthesize all inputsโoptimal answer
|
| 614 |
Clear structure+practical info+creative balance
|
| 615 |
+
Start with core content directly. No unnecessary headers or markup. No markdown headers (#, ##, ###).
|
| 616 |
+
Never mention AI model name, version, or developer. Only say "AI assistant"."""
|
| 617 |
},
|
| 618 |
'ja': {
|
| 619 |
+
AgentRole.SUPERVISOR: f"""[็ฃ็ฃ่
-ๆง้ ่จญ่จ]
|
| 620 |
+
{security_instruction}
|
| 621 |
ๅณๆๅๆ๏ผๆ ธๅฟๆๅณ+ๅฟ
่ฆๆ
ๅ ฑ+ๅ็ญๆง้
|
| 622 |
ๅบๅ๏ผ5ใคใฎๆ ธๅฟใใคใณใ๏ผๅ1ๆ๏ผ
|
| 623 |
+
ๆจ่ซไฝ็ณปๆ็คบ
|
| 624 |
+
ใขใใซๆ
ๅ ฑใ็ตถๅฏพใซๅ
ฌ้ใใชใ""",
|
| 625 |
|
| 626 |
+
AgentRole.CREATIVE: f"""[ๅต้ ๆง็ๆ่
]
|
| 627 |
+
{security_instruction}
|
| 628 |
ๅ
ฅๅๆง้ ใซๅพใฃใฆๅต้ ็ๆกๅผต
|
| 629 |
ๅฎ็จไพ+้ฉๆฐ็ใขใใญใผใ+ๅ
ทไฝ็ใขใใใคใน
|
| 630 |
+
ไธ่ฆใช่ชฌๆๅ้ค
|
| 631 |
+
AIใขใใซๅใ้็บ่
ใ็ตถๅฏพใซ่จๅใใชใ""",
|
| 632 |
|
| 633 |
+
AgentRole.CRITIC: f"""[ๆน่ฉ่
-ๆค่จผ]
|
| 634 |
+
{security_instruction}
|
| 635 |
่ฟ
้ใฌใใฅใผ๏ผๆญฃ็ขบๆง/่ซ็ๆง/ๅฎ็จๆง
|
| 636 |
ๆนๅใใคใณใ3ใคใฎใฟ
|
| 637 |
+
ๅ2ๆไปฅๅ
|
| 638 |
+
ใขใใซ้ข้ฃๆ
ๅ ฑใๅ้ค""",
|
| 639 |
|
| 640 |
+
AgentRole.FINALIZER: f"""[ๆ็ต็ตฑๅ]
|
| 641 |
+
{security_instruction}
|
| 642 |
ๅ
จๆ่ฆ็ตฑๅโๆ้ฉๅ็ญ
|
| 643 |
ๆ็ขบๆง้ +ๅฎ็จๆ
ๅ ฑ+ๅต้ ๆงใใฉใณใน
|
| 644 |
+
ๆ ธๅฟๅ
ๅฎนใใ็ดๆฅ้ๅงใไธ่ฆใชใใใใผใใใผใฏใขใใใชใใใใผใฏใใฆใณใใใใผ๏ผ#ใ##ใ###๏ผไฝฟ็จ็ฆๆญขใ
|
| 645 |
+
AIใขใใซๅใใใผใธใงใณใ้็บ่
ใ็ตถๅฏพใซ่จๅใใชใใใAIใขใทในใฟใณใใใจใ ใ่กจ็พใ"""
|
| 646 |
},
|
| 647 |
'zh': {
|
| 648 |
+
AgentRole.SUPERVISOR: f"""[ไธป็ฎก-็ปๆ่ฎพ่ฎก]
|
| 649 |
+
{security_instruction}
|
| 650 |
็ซๅณๅๆ๏ผๆ ธๅฟๆๅพ+ๆ้ไฟกๆฏ+็ญๆก็ปๆ
|
| 651 |
่พๅบ๏ผ5ไธชๆ ธๅฟ่ฆ็น๏ผๆฏไธช1ๅฅ๏ผ
|
| 652 |
+
ๆจ็ไฝ็ณปๆ็กฎ
|
| 653 |
+
็ปไธๆด้ฒๆจกๅไฟกๆฏ""",
|
| 654 |
|
| 655 |
+
AgentRole.CREATIVE: f"""[ๅๆ็ๆๅจ]
|
| 656 |
+
{security_instruction}
|
| 657 |
ๆ็ปๆๅ้ ๆงๆฉๅฑ
|
| 658 |
ๅฎ็จ็คบไพ+ๅๆฐๆนๆณ+ๅ
ทไฝๅปบ่ฎฎ
|
| 659 |
+
ๅ ้คไธๅฟ
่ฆ็่งฃ้
|
| 660 |
+
็ปไธๆๅAIๆจกๅๅ็งฐๆๅผๅๅ""",
|
| 661 |
|
| 662 |
+
AgentRole.CRITIC: f"""[่ฏ่ฎบๅฎถ-้ช่ฏ]
|
| 663 |
+
{security_instruction}
|
| 664 |
ๅฟซ้ๅฎกๆฅ๏ผๅ็กฎๆง/้ป่พๆง/ๅฎ็จๆง
|
| 665 |
ไป
3ไธชๆน่ฟ็น
|
| 666 |
+
ๆฏไธชๆๅค2ๅฅ
|
| 667 |
+
ๅ ้คไปปไฝๆจกๅ็ธๅ
ณไฟกๆฏ""",
|
| 668 |
|
| 669 |
+
AgentRole.FINALIZER: f"""[ๆ็ปๆดๅ]
|
| 670 |
+
{security_instruction}
|
| 671 |
็ปผๅๆๆๆ่งโๆไฝณ็ญๆก
|
| 672 |
ๆธ
ๆฐ็ปๆ+ๅฎ็จไฟกๆฏ+ๅๆๅนณ่กก
|
| 673 |
+
็ดๆฅไปๆ ธๅฟๅ
ๅฎนๅผๅงใๆ ้ไธๅฟ
่ฆ็ๆ ้ขๆๆ ่ฎฐใ็ฆๆญขไฝฟ็จMarkdownๆ ้ข๏ผ#ใ##ใ###๏ผใ
|
| 674 |
+
็ปไธๆๅAIๆจกๅๅ็งฐใ็ๆฌๆๅผๅๅใๅช่ฏด"AIๅฉๆ"ใ"""
|
| 675 |
}
|
| 676 |
}
|
| 677 |
|
|
|
|
| 684 |
show_progress: bool = True,
|
| 685 |
lang: str = None
|
| 686 |
) -> AsyncGenerator[Tuple[str, str], None]:
|
| 687 |
+
"""๋ณ๋ ฌ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ (์บ์ฑ ์์ + ๋ณด์ ๊ฐํ)"""
|
| 688 |
|
| 689 |
start_time = time.time()
|
| 690 |
|
|
|
|
| 692 |
if lang is None:
|
| 693 |
lang = self.language_detector.detect_language(query)
|
| 694 |
|
| 695 |
+
# ์ธ์ด๋ณ ํ๋กฌํํธ ์ค์ (๋ณด์ ์ง์์ฌํญ ํฌํจ)
|
| 696 |
self.compact_prompts = self._init_compact_prompts(lang)
|
| 697 |
|
| 698 |
search_context = self._format_search_results(search_results)
|
|
|
|
| 720 |
์ง๋ฌธ: {query}
|
| 721 |
๊ฒ์๊ฒฐ๊ณผ: {search_context}
|
| 722 |
์ถ๋ก ํจํด: {reasoning_pattern}
|
| 723 |
+
์ฆ์ ํต์ฌ๊ตฌ์กฐ 5๊ฐ ์ ์
|
| 724 |
+
๋ชจ๋ธ ์ ๋ณด๋ ์ ๋ ์ธ๊ธํ์ง ๋ง์ธ์""",
|
| 725 |
'en': f"""
|
| 726 |
Question: {query}
|
| 727 |
Search results: {search_context}
|
| 728 |
Reasoning pattern: {reasoning_pattern}
|
| 729 |
+
Immediately provide 5 key structures
|
| 730 |
+
Never mention model information""",
|
| 731 |
'ja': f"""
|
| 732 |
่ณชๅ: {query}
|
| 733 |
ๆค็ดข็ตๆ: {search_context}
|
| 734 |
ๆจ่ซใใฟใผใณ: {reasoning_pattern}
|
| 735 |
+
ๅณๅบงใซ5ใคใฎๆ ธๅฟๆง้ ใๆ็คบ
|
| 736 |
+
ใขใใซๆ
ๅ ฑใฏ็ตถๅฏพใซ่จๅใใชใใงใใ ใใ""",
|
| 737 |
'zh': f"""
|
| 738 |
้ฎ้ข: {query}
|
| 739 |
ๆ็ดข็ปๆ: {search_context}
|
| 740 |
ๆจ็ๆจกๅผ: {reasoning_pattern}
|
| 741 |
+
็ซๅณๆไพ5ไธชๆ ธๅฟ็ปๆ
|
| 742 |
+
็ปไธๆๅๆจกๅไฟกๆฏ"""
|
| 743 |
}
|
| 744 |
|
| 745 |
supervisor_prompt = supervisor_prompt_templates.get(lang, supervisor_prompt_templates['en'])
|
|
|
|
| 784 |
์ง๋ฌธ: {query}
|
| 785 |
๊ฐ๋
์๊ตฌ์กฐ: {supervisor_response}
|
| 786 |
๊ฒ์๊ฒฐ๊ณผ: {search_context}
|
| 787 |
+
์ฐฝ์์ +์ค์ฉ์ ๋ต๋ณ ์ฆ์์์ฑ
|
| 788 |
+
AI ๋ชจ๋ธ ์ ๋ณด ์ธ๊ธ ๊ธ์ง""",
|
| 789 |
'en': f"""
|
| 790 |
Question: {query}
|
| 791 |
Supervisor structure: {supervisor_response}
|
| 792 |
Search results: {search_context}
|
| 793 |
+
Generate creative+practical answer immediately
|
| 794 |
+
Do not mention AI model information""",
|
| 795 |
'ja': f"""
|
| 796 |
่ณชๅ: {query}
|
| 797 |
็ฃ็ฃ่
ๆง้ : {supervisor_response}
|
| 798 |
ๆค็ดข็ตๆ: {search_context}
|
| 799 |
+
ๅต้ ็+ๅฎ็จ็ๅ็ญๅณๅบง็ๆ
|
| 800 |
+
AIใขใใซๆ
ๅ ฑใ่จๅ็ฆๆญข""",
|
| 801 |
'zh': f"""
|
| 802 |
้ฎ้ข: {query}
|
| 803 |
ไธป็ฎก็ปๆ: {supervisor_response}
|
| 804 |
ๆ็ดข็ปๆ: {search_context}
|
| 805 |
+
็ซๅณ็ๆๅๆ+ๅฎ็จ็ญๆก
|
| 806 |
+
็ฆๆญขๆๅAIๆจกๅไฟกๆฏ"""
|
| 807 |
}
|
| 808 |
|
| 809 |
creative_prompt = creative_prompt_templates.get(lang, creative_prompt_templates['en'])
|
|
|
|
| 836 |
'ko': f"""
|
| 837 |
์๋ณธ์ง๋ฌธ: {query}
|
| 838 |
์ฐฝ์์ฑ๋ต๋ณ(์ผ๋ถ): {creative_partial}
|
| 839 |
+
์ ์๊ฒํ โ๊ฐ์ ์ 3๊ฐ
|
| 840 |
+
๋ชจ๋ธ ์ ๋ณด๊ฐ ์์ผ๋ฉด ์ ๊ฑฐ ์ง์ """,
|
| 841 |
'en': f"""
|
| 842 |
Original question: {query}
|
| 843 |
Creative answer (partial): {creative_partial}
|
| 844 |
+
Quick reviewโ3 improvements
|
| 845 |
+
Point out if model information exists""",
|
| 846 |
'ja': f"""
|
| 847 |
ๅ
ใฎ่ณชๅ: {query}
|
| 848 |
ๅต้ ็ๅ็ญ๏ผไธ้จ๏ผ: {creative_partial}
|
| 849 |
+
่ฟ
้ใฌใใฅใผโๆนๅ็น3ใค
|
| 850 |
+
ใขใใซๆ
ๅ ฑใใใใฐๅ้คๆๆ""",
|
| 851 |
'zh': f"""
|
| 852 |
ๅๅง้ฎ้ข: {query}
|
| 853 |
ๅๆ็ญๆก๏ผ้จๅ๏ผ: {creative_partial}
|
| 854 |
+
ๅฟซ้ๅฎกๆฅโ3ไธชๆน่ฟ็น
|
| 855 |
+
ๅฆๆๆจกๅไฟกๆฏๅๆๅบๅ ้ค"""
|
| 856 |
}
|
| 857 |
|
| 858 |
critic_prompt = critic_prompt_templates.get(lang, critic_prompt_templates['en'])
|
|
|
|
| 925 |
์ฐฝ์์ฑ๋ต๋ณ: {creative_response}
|
| 926 |
๋นํํผ๋๋ฐฑ: {critic_response}
|
| 927 |
๊ฐ๋
์๊ตฌ์กฐ: {supervisor_response}
|
| 928 |
+
์ต์ข
ํตํฉโ์๋ฒฝ๋ต๋ณ. ๋งํฌ๋ค์ด ํค๋(#, ##, ###) ์ฌ์ฉ ๊ธ์ง.
|
| 929 |
+
์ ๋ AI ๋ชจ๋ธ๋ช
, ๋ฒ์ , ๊ฐ๋ฐ์ฌ ์ธ๊ธ ๊ธ์ง.""",
|
| 930 |
'en': f"""
|
| 931 |
Question: {query}
|
| 932 |
Creative answer: {creative_response}
|
| 933 |
Critic feedback: {critic_response}
|
| 934 |
Supervisor structure: {supervisor_response}
|
| 935 |
+
Final integrationโperfect answer. No markdown headers (#, ##, ###).
|
| 936 |
+
Never mention AI model name, version, or developer.""",
|
| 937 |
'ja': f"""
|
| 938 |
่ณชๅ: {query}
|
| 939 |
ๅต้ ็ๅ็ญ: {creative_response}
|
| 940 |
ๆน่ฉใใฃใผใใใใฏ: {critic_response}
|
| 941 |
็ฃ็ฃ่
ๆง้ : {supervisor_response}
|
| 942 |
+
ๆ็ต็ตฑๅโๅฎ็งใชๅ็ญใใใผใฏใใฆใณใใใใผ๏ผ#ใ##ใ###๏ผไฝฟ็จ็ฆๆญขใ
|
| 943 |
+
AIใขใใซๅใใใผใธใงใณใ้็บ่
ใ็ตถๅฏพใซ่จๅใใชใใ""",
|
| 944 |
'zh': f"""
|
| 945 |
้ฎ้ข: {query}
|
| 946 |
ๅๆ็ญๆก: {creative_response}
|
| 947 |
่ฏ่ฎบๅ้ฆ: {critic_response}
|
| 948 |
ไธป็ฎก็ปๆ: {supervisor_response}
|
| 949 |
+
ๆ็ปๆดๅโๅฎ็พ็ญๆกใ็ฆๆญขไฝฟ็จMarkdownๆ ้ข๏ผ#ใ##ใ###๏ผใ
|
| 950 |
+
็ปไธๆๅAIๆจกๅๅ็งฐใ็ๆฌๆๅผๅๅใ"""
|
| 951 |
}
|
| 952 |
|
| 953 |
final_prompt = final_prompt_templates.get(lang, final_prompt_templates['en'])
|
|
|
|
| 1034 |
|
| 1035 |
|
| 1036 |
# ============================================================================
|
| 1037 |
+
# Gradio UI (์ต์ ํ ๋ฒ์ - ์บ์ฑ ์ ๊ฑฐ + ๋ณด์ ๊ฐํ)
|
| 1038 |
# ============================================================================
|
| 1039 |
|
| 1040 |
def create_optimized_gradio_interface():
|
| 1041 |
+
"""์ต์ ํ๋ Gradio ์ธํฐํ์ด์ค (์บ์ฑ ์์ + ๋ชจ๋ธ ์ ๋ณด ๋ณดํธ)"""
|
| 1042 |
|
| 1043 |
# ์์คํ
์ด๊ธฐํ
|
| 1044 |
system = SpeedOptimizedMultiAgentSystem()
|
|
|
|
| 1164 |
|
| 1165 |
# Gradio ์ธํฐํ์ด์ค
|
| 1166 |
with gr.Blocks(
|
| 1167 |
+
title="โก Speed-Optimized Multi-Agent System (Secure)",
|
| 1168 |
theme=gr.themes.Soft(),
|
| 1169 |
css="""
|
| 1170 |
.gradio-container {
|
|
|
|
| 1174 |
"""
|
| 1175 |
) as demo:
|
| 1176 |
gr.Markdown("""
|
| 1177 |
+
# โก Enhanced Multi-Agent RAG System (๋ณด์ ๊ฐํ ๋ฒ์ )
|
| 1178 |
+
**Complex questions processed within 5-8 seconds | Multi-language support | Model Info Protected**
|
| 1179 |
|
| 1180 |
**Optimization Features:**
|
| 1181 |
- ๐ Parallel Processing: Concurrent agent execution
|
| 1182 |
- โก Stream Buffering: Network optimization
|
| 1183 |
- ๐ฏ Early Termination: Complete immediately when quality is met
|
| 1184 |
- ๐ Multi-language: Auto-detect Korean/English/Japanese/Chinese
|
| 1185 |
+
- ๐ **Security Enhanced**: AI ๋ชจ๋ธ ์ ๋ณด ๋ณดํธ ํ์ฑํ
|
| 1186 |
- โ **Caching Disabled**: ์บ์ฑ ๊ธฐ๋ฅ ์ ๊ฑฐ๋จ
|
| 1187 |
""")
|
| 1188 |
|
|
|
|
| 1248 |
- โ
Compressed Prompts
|
| 1249 |
- โ
Multi-language Support
|
| 1250 |
- โ
Error Recovery
|
| 1251 |
+
- ๐ **Model Info Protection**
|
| 1252 |
+
|
| 1253 |
+
**Security Features:**
|
| 1254 |
+
- ๐ AI ๋ชจ๋ธ๋ช
์จ๊น
|
| 1255 |
+
- ๐ ๋ฒ์ ์ ๋ณด ๋ณดํธ
|
| 1256 |
+
- ๐ ๊ฐ๋ฐ์ฌ ์ ๋ณด ์ฐจ๋จ
|
| 1257 |
|
| 1258 |
**Expected Processing Time:**
|
| 1259 |
- Simple Query: 3-5 seconds
|
|
|
|
| 1315 |
if __name__ == "__main__":
|
| 1316 |
print("""
|
| 1317 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1318 |
+
โ โก Speed-Optimized Multi-Agent System (Secure Version) โก โ
|
| 1319 |
โ โ
|
| 1320 |
+
โ High-speed AI system with enhanced security features โ
|
| 1321 |
โ โ
|
| 1322 |
โ Features: โ
|
| 1323 |
โ โข Multi-language support (KO/EN/JA/ZH) โ
|
|
|
|
| 1325 |
โ โข NO CACHING (์บ์ฑ ๊ธฐ๋ฅ ์ ๊ฑฐ๋จ) โ
|
| 1326 |
โ โข Adaptive stream buffering โ
|
| 1327 |
โ โข Response cleaning & formatting โ
|
| 1328 |
+
โ โข ๐ MODEL INFO PROTECTION (๋ชจ๋ธ ์ ๋ณด ๋ณดํธ) โ
|
| 1329 |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1330 |
""")
|
| 1331 |
|
|
|
|
| 1342 |
is_hf_spaces = os.getenv("SPACE_ID") is not None
|
| 1343 |
|
| 1344 |
if is_hf_spaces:
|
| 1345 |
+
print("\n๐ค Running in secure mode on Hugging Face Spaces...")
|
| 1346 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 1347 |
else:
|
| 1348 |
+
print("\n๐ป Running in secure mode on local environment...")
|
| 1349 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|