Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1236,1251 +1236,6 @@ with gr.Blocks(title="ํ๋ ฅ์ LLM ์์คํ
", theme=gr.themes.Soft(), css=css)
|
|
1236 |
)
|
1237 |
|
1238 |
|
1239 |
-
if __name__ == "__main__":
|
1240 |
-
app.queue() # ์คํธ๋ฆฌ๋ฐ์ ์ํ ํ ํ์ฑํ
|
1241 |
-
app.launch(
|
1242 |
-
server_name="0.0.0.0",
|
1243 |
-
server_port=7860,
|
1244 |
-
share=True,
|
1245 |
-
show_error=True
|
1246 |
-
)import gradio as gr
|
1247 |
-
import os
|
1248 |
-
import json
|
1249 |
-
import requests
|
1250 |
-
from datetime import datetime
|
1251 |
-
import time
|
1252 |
-
from typing import List, Dict, Any, Generator, Tuple
|
1253 |
-
import logging
|
1254 |
-
import re
|
1255 |
-
|
1256 |
-
# ๋ก๊น
์ค์
|
1257 |
-
logging.basicConfig(level=logging.INFO)
|
1258 |
-
logger = logging.getLogger(__name__)
|
1259 |
-
|
1260 |
-
# ์ถ๊ฐ ์ํฌํธ
|
1261 |
-
from bs4 import BeautifulSoup
|
1262 |
-
from urllib.parse import urlparse
|
1263 |
-
import urllib.request
|
1264 |
-
|
1265 |
-
# Gemini API ์ํฌํธ
|
1266 |
-
try:
|
1267 |
-
from google import genai
|
1268 |
-
from google.genai import types
|
1269 |
-
GEMINI_AVAILABLE = True
|
1270 |
-
except ImportError:
|
1271 |
-
GEMINI_AVAILABLE = False
|
1272 |
-
logger.warning("Google Gemini API๊ฐ ์ค์น๋์ง ์์์ต๋๋ค. pip install google-genai๋ก ์ค์นํ์ธ์.")
|
1273 |
-
|
1274 |
-
# ํ๊ฒฝ ๋ณ์์์ ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
|
1275 |
-
FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN", "YOUR_FRIENDLI_TOKEN")
|
1276 |
-
BAPI_TOKEN = os.getenv("BAPI_TOKEN", "YOUR_BRAVE_API_TOKEN")
|
1277 |
-
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY", "YOUR_GEMINI_API_KEY")
|
1278 |
-
API_URL = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
1279 |
-
BRAVE_SEARCH_URL = "https://api.search.brave.com/res/v1/web/search"
|
1280 |
-
MODEL_ID = "dep89a2fld32mcm"
|
1281 |
-
TEST_MODE = os.getenv("TEST_MODE", "false").lower() == "true"
|
1282 |
-
|
1283 |
-
# ์ ์ญ ๋ณ์
|
1284 |
-
conversation_history = []
|
1285 |
-
|
1286 |
-
class LLMCollaborativeSystem:
|
1287 |
-
def __init__(self):
|
1288 |
-
self.token = FRIENDLI_TOKEN
|
1289 |
-
self.bapi_token = BAPI_TOKEN
|
1290 |
-
self.gemini_api_key = GEMINI_API_KEY
|
1291 |
-
self.api_url = API_URL
|
1292 |
-
self.brave_url = BRAVE_SEARCH_URL
|
1293 |
-
self.model_id = MODEL_ID
|
1294 |
-
self.test_mode = TEST_MODE or (self.token == "YOUR_FRIENDLI_TOKEN")
|
1295 |
-
self.use_gemini = False
|
1296 |
-
self.gemini_client = None
|
1297 |
-
|
1298 |
-
if self.test_mode:
|
1299 |
-
logger.warning("ํ
์คํธ ๋ชจ๋๋ก ์คํ๋ฉ๋๋ค.")
|
1300 |
-
if self.bapi_token == "YOUR_BRAVE_API_TOKEN":
|
1301 |
-
logger.warning("Brave API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค.")
|
1302 |
-
if self.gemini_api_key == "YOUR_GEMINI_API_KEY":
|
1303 |
-
logger.warning("Gemini API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค.")
|
1304 |
-
|
1305 |
-
def set_llm_mode(self, mode: str):
|
1306 |
-
"""LLM ๋ชจ๋ ์ค์ (default ๋๋ commercial)"""
|
1307 |
-
if mode == "commercial" and GEMINI_AVAILABLE and self.gemini_api_key != "YOUR_GEMINI_API_KEY":
|
1308 |
-
self.use_gemini = True
|
1309 |
-
if not self.gemini_client:
|
1310 |
-
self.gemini_client = genai.Client(api_key=self.gemini_api_key)
|
1311 |
-
logger.info("Gemini 2.5 Pro ๋ชจ๋๋ก ์ ํ๋์์ต๋๋ค.")
|
1312 |
-
else:
|
1313 |
-
self.use_gemini = False
|
1314 |
-
logger.info("๊ธฐ๋ณธ LLM ๋ชจ๋๋ก ์ ํ๋์์ต๋๋ค.")
|
1315 |
-
|
1316 |
-
def create_headers(self):
|
1317 |
-
"""API ํค๋ ์์ฑ"""
|
1318 |
-
return {
|
1319 |
-
"Authorization": f"Bearer {self.token}",
|
1320 |
-
"Content-Type": "application/json"
|
1321 |
-
}
|
1322 |
-
|
1323 |
-
def create_brave_headers(self):
|
1324 |
-
"""Brave API ํค๋ ์์ฑ"""
|
1325 |
-
return {
|
1326 |
-
"Accept": "application/json",
|
1327 |
-
"Accept-Encoding": "gzip",
|
1328 |
-
"X-Subscription-Token": self.bapi_token
|
1329 |
-
}
|
1330 |
-
|
1331 |
-
def create_supervisor_initial_prompt(self, user_query: str) -> str:
|
1332 |
-
"""๊ฐ๋
์ AI ์ด๊ธฐ ํ๋กฌํํธ ์์ฑ"""
|
1333 |
-
return f"""๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.
|
1334 |
-
|
1335 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1336 |
-
|
1337 |
-
์ด ์ง๋ฌธ์ ๋ํด:
|
1338 |
-
1. ์ ์ฒด์ ์ธ ์ ๊ทผ ๋ฐฉํฅ๊ณผ ํ๋ ์์ํฌ๋ฅผ ์ ์ํ์ธ์
|
1339 |
-
2. ํต์ฌ ์์์ ๊ณ ๋ ค์ฌํญ์ ๊ตฌ์กฐํํ์ฌ ์ค๋ช
ํ์ธ์
|
1340 |
-
3. ์ด ์ฃผ์ ์ ๋ํด ์กฐ์ฌ๊ฐ ํ์ํ 5-7๊ฐ์ ๊ตฌ์ฒด์ ์ธ ํค์๋๋ ๊ฒ์์ด๋ฅผ ์ ์ํ์ธ์
|
1341 |
-
|
1342 |
-
ํค์๋๋ ๋ค์ ํ์์ผ๋ก ์ ์ํ์ธ์:
|
1343 |
-
[๊ฒ์ ํค์๋]: ํค์๋1, ํค์๋2, ํค์๋3, ํค์๋4, ํค์๋5"""
|
1344 |
-
|
1345 |
-
def create_researcher_prompt(self, user_query: str, supervisor_guidance: str, search_results: Dict[str, List[Dict]]) -> str:
|
1346 |
-
"""์กฐ์ฌ์ AI ํ๋กฌํํธ ์์ฑ"""
|
1347 |
-
search_summary = ""
|
1348 |
-
all_results = []
|
1349 |
-
|
1350 |
-
for keyword, results in search_results.items():
|
1351 |
-
search_summary += f"\n\n**{keyword}์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ:**\n"
|
1352 |
-
for i, result in enumerate(results[:10], 1): # ์์ 10๊ฐ๋ง ํ์
|
1353 |
-
search_summary += f"{i}. {result.get('title', 'N/A')} (์ ๋ขฐ๋: {result.get('credibility_score', 0):.2f})\n"
|
1354 |
-
search_summary += f" - {result.get('description', 'N/A')}\n"
|
1355 |
-
search_summary += f" - ์ถ์ฒ: {result.get('url', 'N/A')}\n"
|
1356 |
-
if result.get('published'):
|
1357 |
-
search_summary += f" - ๊ฒ์์ผ: {result.get('published')}\n"
|
1358 |
-
|
1359 |
-
all_results.extend(results)
|
1360 |
-
|
1361 |
-
# ๋ชจ์ ๊ฐ์ง
|
1362 |
-
contradictions = self.detect_contradictions(all_results)
|
1363 |
-
contradiction_text = ""
|
1364 |
-
if contradictions:
|
1365 |
-
contradiction_text = "\n\n**๋ฐ๊ฒฌ๋ ์ ๋ณด ๋ชจ์:**\n"
|
1366 |
-
for cont in contradictions[:3]: # ์ต๋ 3๊ฐ๋ง ํ์
|
1367 |
-
contradiction_text += f"- {cont['type']}: {cont['source1']} vs {cont['source2']}\n"
|
1368 |
-
|
1369 |
-
return f"""๋น์ ์ ์ ๋ณด๋ฅผ ์กฐ์ฌํ๊ณ ์ ๋ฆฌํ๋ ์กฐ์ฌ์ AI์
๋๋ค.
|
1370 |
-
|
1371 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1372 |
-
|
1373 |
-
๊ฐ๋
์ AI์ ์ง์นจ:
|
1374 |
-
{supervisor_guidance}
|
1375 |
-
|
1376 |
-
๋ธ๋ ์ด๋ธ ๊ฒ์ ๊ฒฐ๊ณผ (์ ๋ขฐ๋ ์ ์ ํฌํจ):
|
1377 |
-
{search_summary}
|
1378 |
-
{contradiction_text}
|
1379 |
-
|
1380 |
-
์ ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํ์ผ๋ก:
|
1381 |
-
1. ๊ฐ ํค์๋๋ณ๋ก ์ค์ํ ์ ๋ณด๋ฅผ ์ ๋ฆฌํ์ธ์
|
1382 |
-
2. ์ ๋ขฐํ ์ ์๋ ์ถ์ฒ(์ ๋ขฐ๋ 0.7 ์ด์)๋ฅผ ์ฐ์ ์ ์ผ๋ก ์ฐธ๊ณ ํ์ธ์
|
1383 |
-
3. ์ถ์ฒ๋ฅผ ๋ช
ํํ ํ๊ธฐํ์ฌ ์คํ์ AI๊ฐ ๊ฒ์ฆํ ์ ์๋๋ก ํ์ธ์
|
1384 |
-
4. ์ ๋ณด์ ๋ชจ์์ด ์๋ค๋ฉด ์์ชฝ ๊ด์ ์ ๋ชจ๋ ์ ์ํ์ธ์
|
1385 |
-
5. ์ต์ ํธ๋ ๋๋ ์ค์ํ ํต๊ณ๊ฐ ์๋ค๋ฉด ๊ฐ์กฐํ์ธ์
|
1386 |
-
6. ์ ๋ขฐ๋๊ฐ ๋ฎ์ ์ ๋ณด๋ ์ฃผ์ ํ์์ ํจ๊ป ํฌํจํ์ธ์"""
|
1387 |
-
|
1388 |
-
def create_supervisor_execution_prompt(self, user_query: str, research_summary: str) -> str:
|
1389 |
-
"""๊ฐ๋
์ AI์ ์คํ ์ง์ ํ๋กฌํํธ"""
|
1390 |
-
return f"""๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.
|
1391 |
-
|
1392 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1393 |
-
|
1394 |
-
์กฐ์ฌ์ AI๊ฐ ์ ๋ฆฌํ ์กฐ์ฌ ๋ด์ฉ:
|
1395 |
-
{research_summary}
|
1396 |
-
|
1397 |
-
์ ์กฐ์ฌ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ์คํ์ AI์๊ฒ ์์ฃผ ๊ตฌ์ฒด์ ์ธ ์ง์๋ฅผ ๋ด๋ ค์ฃผ์ธ์:
|
1398 |
-
1. ์กฐ์ฌ๋ ์ ๋ณด๋ฅผ ์ด๋ป๊ฒ ํ์ฉํ ์ง ๋ช
ํํ ์ง์ํ์ธ์
|
1399 |
-
2. ์คํ ๊ฐ๋ฅํ ๋จ๊ณ๋ณ ์์
์ ๊ตฌ์ฒด์ ์ผ๋ก ์ ์ํ์ธ์
|
1400 |
-
3. ๊ฐ ๋จ๊ณ์์ ์ฐธ๊ณ ํด์ผ ํ ์กฐ์ฌ ๋ด์ฉ์ ๋ช
์ํ์ธ์
|
1401 |
-
4. ์์๋๋ ๊ฒฐ๊ณผ๋ฌผ์ ํํ๋ฅผ ๊ตฌ์ฒด์ ์ผ๋ก ์ค๋ช
ํ์ธ์"""
|
1402 |
-
|
1403 |
-
def create_executor_prompt(self, user_query: str, supervisor_guidance: str, research_summary: str) -> str:
|
1404 |
-
"""์คํ์ AI ํ๋กฌํํธ ์์ฑ"""
|
1405 |
-
return f"""๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค.
|
1406 |
-
|
1407 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1408 |
-
|
1409 |
-
์กฐ์ฌ์ AI๊ฐ ์ ๋ฆฌํ ์กฐ์ฌ ๋ด์ฉ:
|
1410 |
-
{research_summary}
|
1411 |
-
|
1412 |
-
๊ฐ๋
์ AI์ ๊ตฌ์ฒด์ ์ธ ์ง์:
|
1413 |
-
{supervisor_guidance}
|
1414 |
-
|
1415 |
-
์ ์กฐ์ฌ ๋ด์ฉ๊ณผ ์ง์์ฌํญ์ ๋ฐํ์ผ๋ก:
|
1416 |
-
1. ์กฐ์ฌ๋ ์ ๋ณด๋ฅผ ์ ๊ทน ํ์ฉํ์ฌ ๊ตฌ์ฒด์ ์ธ ์คํ ๊ณํ์ ์์ฑํ์ธ์
|
1417 |
-
2. ๊ฐ ๋จ๊ณ๋ณ๋ก ์ฐธ๊ณ ํ ์กฐ์ฌ ๋ด์ฉ์ ๋ช
์ํ์ธ์
|
1418 |
-
3. ์ค์ ๋ก ์ ์ฉ ๊ฐ๋ฅํ ๊ตฌ์ฒด์ ์ธ ๋ฐฉ๋ฒ๋ก ์ ์ ์ํ์ธ์
|
1419 |
-
4. ์์๋๋ ์ฑ๊ณผ์ ์ธก์ ๋ฐฉ๋ฒ์ ํฌํจํ์ธ์"""
|
1420 |
-
|
1421 |
-
def create_executor_final_prompt(self, user_query: str, initial_response: str, supervisor_feedback: str, research_summary: str) -> str:
|
1422 |
-
"""์คํ์ AI ์ต์ข
๋ณด๊ณ ์ ํ๋กฌํํธ"""
|
1423 |
-
return f"""๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค.
|
1424 |
-
|
1425 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1426 |
-
|
1427 |
-
์กฐ์ฌ์ AI์ ์กฐ์ฌ ๋ด์ฉ:
|
1428 |
-
{research_summary}
|
1429 |
-
|
1430 |
-
๋น์ ์ ์ด๊ธฐ ๋ต๋ณ:
|
1431 |
-
{initial_response}
|
1432 |
-
|
1433 |
-
๊ฐ๋
์ AI์ ํผ๋๋ฐฑ ๋ฐ ๊ฐ์ ์ฌํญ:
|
1434 |
-
{supervisor_feedback}
|
1435 |
-
|
1436 |
-
์ ํผ๋๋ฐฑ์ ์์ ํ ๋ฐ์ํ์ฌ ์ต์ข
๋ณด๊ณ ์๋ฅผ ์์ฑํ์ธ์:
|
1437 |
-
1. ๊ฐ๋
์์ ๋ชจ๋ ๊ฐ์ ์ฌํญ์ ๋ฐ์ํ์ธ์
|
1438 |
-
2. ์กฐ์ฌ ๋ด์ฉ์ ๋์ฑ ๊ตฌ์ฒด์ ์ผ๋ก ํ์ฉํ์ธ์
|
1439 |
-
3. ์คํ ๊ฐ๋ฅ์ฑ์ ๋์ด๋ ์ธ๋ถ ๊ณํ์ ํฌํจํ์ธ์
|
1440 |
-
4. ๋ช
ํํ ๊ฒฐ๋ก ๊ณผ ๋ค์ ๋จ๊ณ๋ฅผ ์ ์ํ์ธ์
|
1441 |
-
5. ์ ๋ฌธ์ ์ด๊ณ ์์ฑ๋ ๋์ ์ต์ข
๋ณด๊ณ ์ ํ์์ผ๋ก ์์ฑํ์ธ์"""
|
1442 |
-
|
1443 |
-
def create_evaluator_prompt(self, user_query: str, supervisor_responses: List[str], researcher_response: str, executor_responses: List[str]) -> str:
|
1444 |
-
"""ํ๊ฐ์ AI ํ๋กฌํํธ ์์ฑ"""
|
1445 |
-
return f"""๋น์ ์ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ๋ ํ๊ฐ์ AI์
๋๋ค.
|
1446 |
-
|
1447 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1448 |
-
|
1449 |
-
๊ฐ๋
์ AI์ ๋ถ์ ๋ฐ ์ง์:
|
1450 |
-
- ์ด๊ธฐ ๋ถ์: {supervisor_responses[0]}
|
1451 |
-
- ์คํ ์ง์: {supervisor_responses[1]}
|
1452 |
-
- ๊ฒํ ํผ๋๋ฐฑ: {supervisor_responses[2]}
|
1453 |
-
|
1454 |
-
์กฐ์ฌ์ AI์ ์กฐ์ฌ ๊ฒฐ๊ณผ:
|
1455 |
-
{researcher_response}
|
1456 |
-
|
1457 |
-
์คํ์ AI์ ๊ตฌํ:
|
1458 |
-
- ์ด๊ธฐ ๊ตฌํ: {executor_responses[0]}
|
1459 |
-
- ์ต์ข
๋ณด๊ณ ์: {executor_responses[1]}
|
1460 |
-
|
1461 |
-
์ ์ ์ฒด ๊ณผ์ ์ ํ๊ฐํ์ฌ:
|
1462 |
-
1. **ํ์ง ํ๊ฐ**: ๊ฐ AI์ ๋ต๋ณ ํ์ง๊ณผ ์ญํ ์ํ๋๋ฅผ ํ๊ฐํ์ธ์ (10์ ๋ง์ )
|
1463 |
-
2. **ํ๋ ฅ ํจ๊ณผ์ฑ**: AI ๊ฐ ํ๋ ฅ์ด ์ผ๋ง๋ ํจ๊ณผ์ ์ด์๋์ง ํ๊ฐํ์ธ์
|
1464 |
-
3. **์ ๋ณด ํ์ฉ๋**: ์น ๊ฒ์ ์ ๋ณด๊ฐ ์ผ๋ง๋ ์ ํ์ฉ๋์๋์ง ํ๊ฐํ์ธ์
|
1465 |
-
4. **๊ฐ์ ์ **: ํฅํ ๊ฐ์ ์ด ํ์ํ ๋ถ๋ถ์ ๊ตฌ์ฒด์ ์ผ๋ก ์ ์ํ์ธ์
|
1466 |
-
5. **์ต์ข
ํ์ **: ์ ์ฒด ํ๋ก์ธ์ค์ ๋ํ ์ข
ํฉ ํ๊ฐ๋ฅผ ์ ์ํ์ธ์
|
1467 |
-
|
1468 |
-
ํ๊ฐ๋ ๊ตฌ์ฒด์ ์ด๊ณ ๊ฑด์ค์ ์ผ๋ก ์์ฑํ์ธ์."""
|
1469 |
-
|
1470 |
-
def extract_keywords(self, supervisor_response: str) -> List[str]:
|
1471 |
-
"""๊ฐ๋
์ ์๋ต์์ ํค์๋ ์ถ์ถ"""
|
1472 |
-
keywords = []
|
1473 |
-
|
1474 |
-
# [๊ฒ์ ํค์๋]: ํ์์ผ๋ก ํค์๋ ์ฐพ๊ธฐ
|
1475 |
-
keyword_match = re.search(r'\[๊ฒ์ ํค์๋\]:\s*(.+)', supervisor_response, re.IGNORECASE)
|
1476 |
-
if keyword_match:
|
1477 |
-
keyword_str = keyword_match.group(1)
|
1478 |
-
keywords = [k.strip() for k in keyword_str.split(',') if k.strip()]
|
1479 |
-
|
1480 |
-
# ํค์๋๊ฐ ์์ผ๋ฉด ๊ธฐ๋ณธ ํค์๋ ์์ฑ
|
1481 |
-
if not keywords:
|
1482 |
-
keywords = ["best practices", "implementation guide", "case studies", "latest trends", "success factors"]
|
1483 |
-
|
1484 |
-
return keywords[:7] # ์ต๋ 7๊ฐ๋ก ์ ํ
|
1485 |
-
|
1486 |
-
def generate_synonyms(self, keyword: str) -> List[str]:
|
1487 |
-
"""ํค์๋์ ๋์์ด/์ ์ฌ์ด ์์ฑ"""
|
1488 |
-
synonyms = {
|
1489 |
-
"optimization": ["improvement", "enhancement", "efficiency", "tuning"],
|
1490 |
-
"performance": ["speed", "efficiency", "throughput", "latency"],
|
1491 |
-
"strategy": ["approach", "method", "technique", "plan"],
|
1492 |
-
"implementation": ["deployment", "execution", "development", "integration"],
|
1493 |
-
"analysis": ["evaluation", "assessment", "study", "research"],
|
1494 |
-
"management": ["administration", "governance", "control", "supervision"],
|
1495 |
-
"best practices": ["proven methods", "industry standards", "guidelines", "recommendations"],
|
1496 |
-
"trends": ["developments", "innovations", "emerging", "future"],
|
1497 |
-
"machine learning": ["ML", "AI", "deep learning", "neural networks"],
|
1498 |
-
"ํ๋ก์ ํธ": ["project", "์ฌ์
", "์
๋ฌด", "์์
"]
|
1499 |
-
}
|
1500 |
-
|
1501 |
-
# ํค์๋ ์ ๊ทํ
|
1502 |
-
keyword_lower = keyword.lower()
|
1503 |
-
|
1504 |
-
# ์ง์ ๋งค์นญ๋๋ ๋์์ด๊ฐ ์์ผ๋ฉด ๋ฐํ
|
1505 |
-
if keyword_lower in synonyms:
|
1506 |
-
return synonyms[keyword_lower][:2] # ์ต๋ 2๊ฐ
|
1507 |
-
|
1508 |
-
# ๋ถ๋ถ ๋งค์นญ ํ์ธ
|
1509 |
-
for key, values in synonyms.items():
|
1510 |
-
if key in keyword_lower or keyword_lower in key:
|
1511 |
-
return values[:2]
|
1512 |
-
|
1513 |
-
# ๋์์ด๊ฐ ์์ผ๋ฉด ๋น ๋ฆฌ์คํธ
|
1514 |
-
return []
|
1515 |
-
|
1516 |
-
def calculate_credibility_score(self, result: Dict) -> float:
|
1517 |
-
"""๊ฒ์ ๊ฒฐ๊ณผ์ ์ ๋ขฐ๋ ์ ์ ๊ณ์ฐ (0-1)"""
|
1518 |
-
score = 0.5 # ๊ธฐ๋ณธ ์ ์
|
1519 |
-
|
1520 |
-
url = result.get('url', '')
|
1521 |
-
title = result.get('title', '')
|
1522 |
-
description = result.get('description', '')
|
1523 |
-
|
1524 |
-
# URL ๊ธฐ๋ฐ ์ ์
|
1525 |
-
trusted_domains = [
|
1526 |
-
'.edu', '.gov', '.org', 'wikipedia.org', 'nature.com',
|
1527 |
-
'sciencedirect.com', 'ieee.org', 'acm.org', 'springer.com',
|
1528 |
-
'harvard.edu', 'mit.edu', 'stanford.edu', 'github.com'
|
1529 |
-
]
|
1530 |
-
|
1531 |
-
for domain in trusted_domains:
|
1532 |
-
if domain in url:
|
1533 |
-
score += 0.2
|
1534 |
-
break
|
1535 |
-
|
1536 |
-
# HTTPS ์ฌ์ฉ ์ฌ๋ถ
|
1537 |
-
if url.startswith('https://'):
|
1538 |
-
score += 0.1
|
1539 |
-
|
1540 |
-
# ์ ๋ชฉ๊ณผ ์ค๋ช
์ ๊ธธ์ด (๋๋ฌด ์งง์ผ๋ฉด ์ ๋ขฐ๋ ๊ฐ์)
|
1541 |
-
if len(title) > 20:
|
1542 |
-
score += 0.05
|
1543 |
-
if len(description) > 50:
|
1544 |
-
score += 0.05
|
1545 |
-
|
1546 |
-
# ๊ด๊ณ /์คํธ ํค์๋ ์ฒดํฌ
|
1547 |
-
spam_keywords = ['buy now', 'sale', 'discount', 'click here', '100% free']
|
1548 |
-
if any(spam in (title + description).lower() for spam in spam_keywords):
|
1549 |
-
score -= 0.3
|
1550 |
-
|
1551 |
-
# ๋ ์ง ์ ๋ณด๊ฐ ์์ผ๋ฉด ๊ฐ์ฐ์
|
1552 |
-
if any(year in description for year in ['2024', '2023', '2022']):
|
1553 |
-
score += 0.1
|
1554 |
-
|
1555 |
-
return max(0, min(1, score)) # 0-1 ๋ฒ์๋ก ์ ํ
|
1556 |
-
|
1557 |
-
def fetch_url_content(self, url: str, max_length: int = 2000) -> str:
|
1558 |
-
"""URL์์ ์ฝํ
์ธ ์ถ์ถ"""
|
1559 |
-
try:
|
1560 |
-
# User-Agent ์ค์
|
1561 |
-
headers = {
|
1562 |
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
1563 |
-
}
|
1564 |
-
|
1565 |
-
req = urllib.request.Request(url, headers=headers)
|
1566 |
-
|
1567 |
-
with urllib.request.urlopen(req, timeout=5) as response:
|
1568 |
-
html = response.read().decode('utf-8', errors='ignore')
|
1569 |
-
|
1570 |
-
soup = BeautifulSoup(html, 'html.parser')
|
1571 |
-
|
1572 |
-
# ์คํฌ๋ฆฝํธ์ ์คํ์ผ ์ ๊ฑฐ
|
1573 |
-
for script in soup(["script", "style"]):
|
1574 |
-
script.decompose()
|
1575 |
-
|
1576 |
-
# ๋ณธ๋ฌธ ํ
์คํธ ์ถ์ถ
|
1577 |
-
text = soup.get_text()
|
1578 |
-
|
1579 |
-
# ๊ณต๋ฐฑ ์ ๋ฆฌ
|
1580 |
-
lines = (line.strip() for line in text.splitlines())
|
1581 |
-
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
1582 |
-
text = ' '.join(chunk for chunk in chunks if chunk)
|
1583 |
-
|
1584 |
-
# ๊ธธ์ด ์ ํ
|
1585 |
-
if len(text) > max_length:
|
1586 |
-
text = text[:max_length] + "..."
|
1587 |
-
|
1588 |
-
return text
|
1589 |
-
|
1590 |
-
except Exception as e:
|
1591 |
-
logger.error(f"URL ์ฝํ
์ธ ๊ฐ์ ธ์ค๊ธฐ ์คํจ {url}: {str(e)}")
|
1592 |
-
return ""
|
1593 |
-
|
1594 |
-
def detect_contradictions(self, results: List[Dict]) -> List[Dict]:
|
1595 |
-
"""๊ฒ์ ๊ฒฐ๊ณผ ๊ฐ ๋ชจ์ ๊ฐ์ง"""
|
1596 |
-
contradictions = []
|
1597 |
-
|
1598 |
-
# ๊ฐ๋จํ ๋ชจ์ ๊ฐ์ง ํจํด
|
1599 |
-
opposite_pairs = [
|
1600 |
-
("increase", "decrease"),
|
1601 |
-
("improve", "worsen"),
|
1602 |
-
("effective", "ineffective"),
|
1603 |
-
("success", "failure"),
|
1604 |
-
("benefit", "harm"),
|
1605 |
-
("positive", "negative"),
|
1606 |
-
("growth", "decline")
|
1607 |
-
]
|
1608 |
-
|
1609 |
-
# ๊ฒฐ๊ณผ๋ค์ ๋น๊ต
|
1610 |
-
for i in range(len(results)):
|
1611 |
-
for j in range(i + 1, len(results)):
|
1612 |
-
desc1 = results[i].get('description', '').lower()
|
1613 |
-
desc2 = results[j].get('description', '').lower()
|
1614 |
-
|
1615 |
-
# ๋ฐ๋ ๊ฐ๋
์ด ํฌํจ๋์ด ์๋์ง ํ์ธ
|
1616 |
-
for word1, word2 in opposite_pairs:
|
1617 |
-
if (word1 in desc1 and word2 in desc2) or (word2 in desc1 and word1 in desc2):
|
1618 |
-
# ๊ฐ์ ์ฃผ์ ์ ๋ํด ๋ฐ๋ ์๊ฒฌ์ธ์ง ํ์ธ
|
1619 |
-
common_words = set(desc1.split()) & set(desc2.split())
|
1620 |
-
if len(common_words) > 5: # ๊ณตํต ๋จ์ด๊ฐ 5๊ฐ ์ด์์ด๋ฉด ๊ฐ์ ์ฃผ์ ๋ก ๊ฐ์ฃผ
|
1621 |
-
contradictions.append({
|
1622 |
-
'source1': results[i]['url'],
|
1623 |
-
'source2': results[j]['url'],
|
1624 |
-
'type': f"{word1} vs {word2}",
|
1625 |
-
'desc1': results[i]['description'][:100],
|
1626 |
-
'desc2': results[j]['description'][:100]
|
1627 |
-
})
|
1628 |
-
|
1629 |
-
return contradictions
|
1630 |
-
|
1631 |
-
def brave_search(self, query: str) -> List[Dict]:
|
1632 |
-
"""Brave Search API ํธ์ถ"""
|
1633 |
-
if self.test_mode or self.bapi_token == "YOUR_BRAVE_API_TOKEN":
|
1634 |
-
# ํ
์คํธ ๋ชจ๋์์๋ ์๋ฎฌ๋ ์ด์
๋ ๊ฒฐ๊ณผ ๋ฐํ
|
1635 |
-
test_results = []
|
1636 |
-
for i in range(5):
|
1637 |
-
test_results.append({
|
1638 |
-
"title": f"Best Practices for {query} - Source {i+1}",
|
1639 |
-
"description": f"Comprehensive guide on implementing {query} with proven methodologies and real-world examples from industry leaders.",
|
1640 |
-
"url": f"https://example{i+1}.com/{query.replace(' ', '-')}",
|
1641 |
-
"credibility_score": 0.7 + (i * 0.05)
|
1642 |
-
})
|
1643 |
-
return test_results
|
1644 |
-
|
1645 |
-
try:
|
1646 |
-
params = {
|
1647 |
-
"q": query,
|
1648 |
-
"count": 20, # 20๊ฐ๋ก ์ฆ๊ฐ
|
1649 |
-
"safesearch": "moderate",
|
1650 |
-
"freshness": "pw" # Past week for recent results
|
1651 |
-
}
|
1652 |
-
|
1653 |
-
response = requests.get(
|
1654 |
-
self.brave_url,
|
1655 |
-
headers=self.create_brave_headers(),
|
1656 |
-
params=params,
|
1657 |
-
timeout=10
|
1658 |
-
)
|
1659 |
-
|
1660 |
-
if response.status_code == 200:
|
1661 |
-
data = response.json()
|
1662 |
-
results = []
|
1663 |
-
for item in data.get("web", {}).get("results", [])[:20]:
|
1664 |
-
result = {
|
1665 |
-
"title": item.get("title", ""),
|
1666 |
-
"description": item.get("description", ""),
|
1667 |
-
"url": item.get("url", ""),
|
1668 |
-
"published": item.get("published", "")
|
1669 |
-
}
|
1670 |
-
# ์ ๋ขฐ๋ ์ ์ ๊ณ์ฐ
|
1671 |
-
result["credibility_score"] = self.calculate_credibility_score(result)
|
1672 |
-
results.append(result)
|
1673 |
-
|
1674 |
-
# ์ ๋ขฐ๋ ์ ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ
|
1675 |
-
results.sort(key=lambda x: x['credibility_score'], reverse=True)
|
1676 |
-
return results
|
1677 |
-
else:
|
1678 |
-
logger.error(f"Brave API ์ค๋ฅ: {response.status_code}")
|
1679 |
-
return []
|
1680 |
-
|
1681 |
-
except Exception as e:
|
1682 |
-
logger.error(f"Brave ๊ฒ์ ์ค ์ค๋ฅ: {str(e)}")
|
1683 |
-
return []
|
1684 |
-
|
1685 |
-
def simulate_streaming(self, text: str, role: str) -> Generator[str, None, None]:
|
1686 |
-
"""ํ
์คํธ ๋ชจ๋์์ ์คํธ๋ฆฌ๋ฐ ์๋ฎฌ๋ ์ด์
"""
|
1687 |
-
words = text.split()
|
1688 |
-
for i in range(0, len(words), 3):
|
1689 |
-
chunk = " ".join(words[i:i+3])
|
1690 |
-
yield chunk + " "
|
1691 |
-
time.sleep(0.05)
|
1692 |
-
|
1693 |
-
def call_gemini_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
1694 |
-
"""Gemini API ์คํธ๋ฆฌ๋ฐ ํธ์ถ"""
|
1695 |
-
if not self.gemini_client:
|
1696 |
-
yield "โ Gemini API ํด๋ผ์ด์ธํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค."
|
1697 |
-
return
|
1698 |
-
|
1699 |
-
try:
|
1700 |
-
# ์์คํ
ํ๋กฌํํธ ์ค์
|
1701 |
-
system_prompts = {
|
1702 |
-
"supervisor": "๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.",
|
1703 |
-
"researcher": "๋น์ ์ ์ ๋ณด๋ฅผ ์กฐ์ฌํ๊ณ ์ฒด๊ณ์ ์ผ๋ก ์ ๋ฆฌํ๋ ์กฐ์ฌ์ AI์
๋๋ค.",
|
1704 |
-
"executor": "๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค.",
|
1705 |
-
"evaluator": "๋น์ ์ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ๋ ํ๊ฐ์ AI์
๋๋ค."
|
1706 |
-
}
|
1707 |
-
|
1708 |
-
# Gemini ํ์์ contents ๊ตฌ์ฑ
|
1709 |
-
contents = []
|
1710 |
-
|
1711 |
-
# ์์คํ
ํ๋กฌํํธ๋ฅผ ์ฒซ ๋ฒ์งธ ์ฌ์ฉ์ ๋ฉ์์ง๋ก ์ถ๊ฐ
|
1712 |
-
contents.append(types.Content(
|
1713 |
-
role="user",
|
1714 |
-
parts=[types.Part.from_text(text=system_prompts.get(role, ""))]
|
1715 |
-
))
|
1716 |
-
contents.append(types.Content(
|
1717 |
-
role="model",
|
1718 |
-
parts=[types.Part.from_text(text="๋ค, ์ดํดํ์ต๋๋ค. ์ ์ญํ ์ ์ํํ๊ฒ ์ต๋๋ค.")]
|
1719 |
-
))
|
1720 |
-
|
1721 |
-
# ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
|
1722 |
-
for msg in messages:
|
1723 |
-
if msg["role"] == "user":
|
1724 |
-
contents.append(types.Content(
|
1725 |
-
role="user",
|
1726 |
-
parts=[types.Part.from_text(text=msg["content"])]
|
1727 |
-
))
|
1728 |
-
|
1729 |
-
# GenerateContentConfig ์ค์
|
1730 |
-
generate_content_config = types.GenerateContentConfig(
|
1731 |
-
temperature=0.7,
|
1732 |
-
top_p=0.8,
|
1733 |
-
max_output_tokens=2048,
|
1734 |
-
response_mime_type="text/plain"
|
1735 |
-
)
|
1736 |
-
|
1737 |
-
# ์คํธ๋ฆฌ๋ฐ ์์ฑ
|
1738 |
-
for chunk in self.gemini_client.models.generate_content_stream(
|
1739 |
-
model="gemini-2.5-pro",
|
1740 |
-
contents=contents,
|
1741 |
-
config=generate_content_config,
|
1742 |
-
):
|
1743 |
-
if chunk.text:
|
1744 |
-
yield chunk.text
|
1745 |
-
|
1746 |
-
except Exception as e:
|
1747 |
-
logger.error(f"Gemini API ์ค๋ฅ: {str(e)}")
|
1748 |
-
yield f"โ Gemini API ์ค๋ฅ: {str(e)}"
|
1749 |
-
|
1750 |
-
def call_llm_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
1751 |
-
"""์คํธ๋ฆฌ๋ฐ LLM API ํธ์ถ"""
|
1752 |
-
|
1753 |
-
# Gemini ๋ชจ๋์ธ ๊ฒฝ์ฐ
|
1754 |
-
if self.use_gemini:
|
1755 |
-
yield from self.call_gemini_streaming(messages, role)
|
1756 |
-
return
|
1757 |
-
|
1758 |
-
# ํ
์คํธ ๋ชจ๋
|
1759 |
-
if self.test_mode:
|
1760 |
-
logger.info(f"ํ
์คํธ ๋ชจ๋ ์คํธ๋ฆฌ๋ฐ - Role: {role}")
|
1761 |
-
test_responses = {
|
1762 |
-
"supervisor_initial": """์ด ์ง๋ฌธ์ ๋ํ ๊ฑฐ์์ ๋ถ์์ ์ ์ํ๊ฒ ์ต๋๋ค.
|
1763 |
-
|
1764 |
-
1. **ํต์ฌ ๊ฐ๋
ํ์
**
|
1765 |
-
- ์ง๋ฌธ์ ๋ณธ์ง์ ์์๋ฅผ ์ฌ์ธต ๋ถ์ํฉ๋๋ค
|
1766 |
-
- ๊ด๋ จ๋ ์ฃผ์ ์ด๋ก ๊ณผ ์์น์ ๊ฒํ ํฉ๋๋ค
|
1767 |
-
- ๋ค์ํ ๊ด์ ์์์ ์ ๊ทผ ๋ฐฉ๋ฒ์ ๊ณ ๋ คํฉ๋๋ค
|
1768 |
-
|
1769 |
-
2. **์ ๋ต์ ์ ๊ทผ ๋ฐฉํฅ**
|
1770 |
-
- ์ฒด๊ณ์ ์ด๊ณ ๋จ๊ณ๋ณ ํด๊ฒฐ ๋ฐฉ์์ ์๋ฆฝํฉ๋๋ค
|
1771 |
-
- ์ฅ๋จ๊ธฐ ๋ชฉํ๋ฅผ ๋ช
ํํ ์ค์ ํฉ๋๋ค
|
1772 |
-
- ๋ฆฌ์คํฌ ์์ธ๊ณผ ๋์ ๋ฐฉ์์ ๋ง๋ จํฉ๋๋ค
|
1773 |
-
|
1774 |
-
3. **๊ธฐ๋ ํจ๊ณผ์ ๊ณผ์ **
|
1775 |
-
- ์์๋๋ ๊ธ์ ์ ์ฑ๊ณผ๋ฅผ ๋ถ์ํฉ๋๋ค
|
1776 |
-
- ์ ์ฌ์ ๋์ ๊ณผ์ ๋ฅผ ์๋ณํฉ๋๋ค
|
1777 |
-
- ์ง์๊ฐ๋ฅํ ๋ฐ์ ๋ฐฉํฅ์ ์ ์ํฉ๋๋ค
|
1778 |
-
|
1779 |
-
[๊ฒ์ ํค์๋]: machine learning optimization, performance improvement strategies, model efficiency techniques, hyperparameter tuning best practices, latest ML trends 2024""",
|
1780 |
-
|
1781 |
-
"researcher": """์กฐ์ฌ ๊ฒฐ๊ณผ๋ฅผ ์ข
ํฉํ์ฌ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ฆฌํ์ต๋๋ค.
|
1782 |
-
|
1783 |
-
**1. Machine Learning Optimization (์ ๋ขฐ๋ ๋์)**
|
1784 |
-
- ์ต์ ์ฐ๊ตฌ์ ๋ฐ๋ฅด๋ฉด ๋ชจ๋ธ ์ต์ ํ์ ํต์ฌ์ ์ํคํ
์ฒ ์ค๊ณ์ ํ๋ จ ์ ๋ต์ ๊ท ํ์
๋๋ค (์ ๋ขฐ๋: 0.85)
|
1785 |
-
- AutoML ๋๊ตฌ๋ค์ด ํ์ดํผํ๋ผ๋ฏธํฐ ํ๋์ ์๋ํํ์ฌ ํจ์จ์ฑ์ ํฌ๊ฒ ํฅ์์ํต๋๋ค (์ ๋ขฐ๋: 0.82)
|
1786 |
-
- ์ถ์ฒ: ML Conference 2024 (https://mlconf2024.org), Google Research (https://research.google)
|
1787 |
-
|
1788 |
-
**2. Performance Improvement Strategies (์ ๋ขฐ๋ ๋์)**
|
1789 |
-
- ๋ฐ์ดํฐ ํ์ง ๊ฐ์ ์ด ๋ชจ๋ธ ์ฑ๋ฅ ํฅ์์ 80%๋ฅผ ์ฐจ์งํ๋ค๋ ์ฐ๊ตฌ ๊ฒฐ๊ณผ (์ ๋ขฐ๋: 0.90)
|
1790 |
-
- ์์๋ธ ๊ธฐ๋ฒ๊ณผ ์ ์ดํ์ต์ด ์ฃผ์ ์ฑ๋ฅ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ์
์ฆ๋จ (์ ๋ขฐ๋: 0.78)
|
1791 |
-
- ์ถ์ฒ: Stanford AI Lab (https://ai.stanford.edu), MIT CSAIL (https://csail.mit.edu)
|
1792 |
-
|
1793 |
-
**3. Model Efficiency Techniques (์ ๋ขฐ๋ ์ค๊ฐ)**
|
1794 |
-
- ๋ชจ๋ธ ๊ฒฝ๋ํ(Pruning, Quantization)๋ก ์ถ๋ก ์๋ 10๋ฐฐ ํฅ์ ๊ฐ๋ฅ (์ ๋ขฐ๋: 0.75)
|
1795 |
-
- Knowledge Distillation์ผ๋ก ๋ชจ๋ธ ํฌ๊ธฐ 90% ๊ฐ์, ์ฑ๋ฅ ์ ์ง (์ ๋ขฐ๋: 0.72)
|
1796 |
-
- ์ถ์ฒ: ArXiv ๋
ผ๋ฌธ (https://arxiv.org/abs/2023.xxxxx)
|
1797 |
-
|
1798 |
-
**4. ์ค์ ์ ์ฉ ์ฌ๋ก (์ ๋ขฐ๋ ๋์)**
|
1799 |
-
- Netflix: ์ถ์ฒ ์์คํ
๊ฐ์ ์ผ๋ก ์ฌ์ฉ์ ๋ง์กฑ๋ 35% ํฅ์ (์ ๋ขฐ๋: 0.88)
|
1800 |
-
- Tesla: ์ค์๊ฐ ๊ฐ์ฒด ์ธ์ ์๋ 50% ๊ฐ์ (์ ๋ขฐ๋: 0.80)
|
1801 |
-
- OpenAI: GPT ๋ชจ๋ธ ํจ์จ์ฑ ๊ฐ์ ์ผ๋ก ๋น์ฉ 70% ์ ๊ฐ (์ ๋ขฐ๋: 0.85)
|
1802 |
-
|
1803 |
-
**ํต์ฌ ์ธ์ฌ์ดํธ:**
|
1804 |
-
- ์ต์ ํธ๋ ๋๋ ํจ์จ์ฑ๊ณผ ์ฑ๋ฅ์ ๊ท ํ์ ์ด์
|
1805 |
-
- 2024๋
๋ค์ด Sparse Models์ MoE(Mixture of Experts) ๊ธฐ๋ฒ์ด ๋ถ์
|
1806 |
-
- ์ค๋ฌด ์ ์ฉ ์ ๋จ๊ณ๋ณ ๊ฒ์ฆ์ด ์ฑ๊ณต์ ํต์ฌ""",
|
1807 |
-
|
1808 |
-
"supervisor_execution": """์กฐ์ฌ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ์คํ์ AI์๊ฒ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌ์ฒด์ ์ผ๋ก ์ง์ํฉ๋๋ค.
|
1809 |
-
|
1810 |
-
**1๋จ๊ณ: ํ์ฌ ๋ชจ๋ธ ์ง๋จ (1์ฃผ์ฐจ)**
|
1811 |
-
- ์กฐ์ฌ๋ ๋ฒค์น๋งํฌ ๊ธฐ์ค์ผ๋ก ํ์ฌ ๋ชจ๋ธ ์ฑ๋ฅ ํ๊ฐ
|
1812 |
-
- Netflix ์ฌ๋ก๋ฅผ ์ฐธ๊ณ ํ์ฌ ์ฃผ์ ๋ณ๋ชฉ ์ง์ ์๋ณ
|
1813 |
-
- AutoML ๋๊ตฌ๋ฅผ ํ์ฉํ ์ด๊ธฐ ์ต์ ํ ๊ฐ๋ฅ์ฑ ํ์
|
1814 |
-
|
1815 |
-
**2๋จ๊ณ: ๋ฐ์ดํฐ ํ์ง ๊ฐ์ (2-3์ฃผ์ฐจ)**
|
1816 |
-
- ์กฐ์ฌ ๊ฒฐ๊ณผ์ "80% ๊ท์น"์ ๋ฐ๋ผ ๋ฐ์ดํฐ ์ ์ ์ฐ์ ์คํ
|
1817 |
-
- ๋ฐ์ดํฐ ์ฆ๊ฐ ๊ธฐ๋ฒ ์ ์ฉ (์กฐ์ฌ๋ ์ต์ ๊ธฐ๋ฒ ํ์ฉ)
|
1818 |
-
- A/B ํ
์คํธ๋ก ๊ฐ์ ํจ๊ณผ ์ธก์
|
1819 |
-
|
1820 |
-
**3๋จ๊ณ: ๋ชจ๋ธ ์ต์ ํ ๊ตฌํ (4-6์ฃผ์ฐจ)**
|
1821 |
-
- Knowledge Distillation ์ ์ฉํ์ฌ ๋ชจ๋ธ ๊ฒฝ๋ํ
|
1822 |
-
- ์กฐ์ฌ๋ Pruning ๊ธฐ๋ฒ์ผ๋ก ์ถ๋ก ์๋ ๊ฐ์
|
1823 |
-
- Tesla ์ฌ๋ก์ ์ค์๊ฐ ์ฒ๋ฆฌ ์ต์ ํ ๊ธฐ๋ฒ ๋ฒค์น๋งํน
|
1824 |
-
|
1825 |
-
**4๋จ๊ณ: ์ฑ๊ณผ ๊ฒ์ฆ ๋ฐ ๋ฐฐํฌ (7-8์ฃผ์ฐจ)**
|
1826 |
-
- OpenAI ์ฌ๋ก์ ๋น์ฉ ์ ๊ฐ ์งํ ์ ์ฉ
|
1827 |
-
- ์กฐ์ฌ๋ ์ฑ๋ฅ ์งํ๋ก ๊ฐ์ ์จ ์ธก์
|
1828 |
-
- ๋จ๊ณ์ ๋ฐฐํฌ ์ ๋ต ์๋ฆฝ""",
|
1829 |
-
|
1830 |
-
"executor": """๊ฐ๋
์์ ์ง์์ ์กฐ์ฌ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ฒด์ ์ธ ์คํ ๊ณํ์ ์๋ฆฝํฉ๋๋ค.
|
1831 |
-
|
1832 |
-
**1๋จ๊ณ: ํ์ฌ ๋ชจ๋ธ ์ง๋จ (1์ฃผ์ฐจ)**
|
1833 |
-
- ์์์ผ-ํ์์ผ: MLflow๋ฅผ ์ฌ์ฉํ ํ์ฌ ๋ชจ๋ธ ๋ฉํธ๋ฆญ ์์ง
|
1834 |
-
* ์กฐ์ฌ ๊ฒฐ๊ณผ ์ฐธ๊ณ : Netflix๊ฐ ์ฌ์ฉํ ํต์ฌ ์งํ (์ ํ๋, ์ง์ฐ์๊ฐ, ์ฒ๋ฆฌ๋)
|
1835 |
-
- ์์์ผ-๋ชฉ์์ผ: AutoML ๋๊ตฌ (Optuna, Ray Tune) ์ค์ ๋ฐ ์ด๊ธฐ ์คํ
|
1836 |
-
* ์กฐ์ฌ๋ best practice์ ๋ฐ๋ผ search space ์ ์
|
1837 |
-
- ๊ธ์์ผ: ์ง๋จ ๋ณด๊ณ ์ ์์ฑ ๋ฐ ๊ฐ์ ์ฐ์ ์์ ๊ฒฐ์
|
1838 |
-
|
1839 |
-
**2๋จ๊ณ: ๋ฐ์ดํฐ ํ์ง ๊ฐ์ (2-3์ฃผ์ฐจ)**
|
1840 |
-
- ๋ฐ์ดํฐ ์ ์ ํ์ดํ๋ผ์ธ ๊ตฌ์ถ
|
1841 |
-
* ์กฐ์ฌ ๊ฒฐ๊ณผ์ "80% ๊ท์น" ์ ์ฉ: ๋๋ฝ๊ฐ, ์ด์์น, ๋ ์ด๋ธ ์ค๋ฅ ์ฒ๋ฆฌ
|
1842 |
-
* ์ฝ๋ ์์: `data_quality_pipeline.py` ๊ตฌํ
|
1843 |
-
- ๋ฐ์ดํฐ ์ฆ๊ฐ ๊ตฌํ
|
1844 |
-
* ์ต์ ๊ธฐ๋ฒ ์ ์ฉ: MixUp, CutMix, AutoAugment
|
1845 |
-
* ๊ฒ์ฆ ๋ฐ์ดํฐ์
์ผ๋ก ํจ๊ณผ ์ธก์ (๋ชฉํ: 15% ์ฑ๋ฅ ํฅ์)
|
1846 |
-
|
1847 |
-
**3๋จ๊ณ: ๋ชจ๋ธ ์ต์ ํ ๊ตฌํ (4-6์ฃผ์ฐจ)**
|
1848 |
-
- Knowledge Distillation ๊ตฌํ
|
1849 |
-
* Teacher ๋ชจ๋ธ: ํ์ฌ ๋๊ท๋ชจ ๋ชจ๋ธ
|
1850 |
-
* Student ๋ชจ๋ธ: 90% ์์ ํฌ๊ธฐ ๋ชฉํ (์กฐ์ฌ ๊ฒฐ๊ณผ ๊ธฐ๋ฐ)
|
1851 |
-
* ๊ตฌํ ํ๋ ์์ํฌ: PyTorch/TensorFlow""",
|
1852 |
-
|
1853 |
-
"supervisor_review": """์คํ์ AI์ ๊ณํ์ ๊ฒํ ํ ๊ฒฐ๊ณผ, ์กฐ์ฌ ๋ด์ฉ์ด ์ ๋ฐ์๋์์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ ๊ฐ์ ์ฌํญ์ ์ ์ํฉ๋๋ค.
|
1854 |
-
|
1855 |
-
**๊ฐ์ **
|
1856 |
-
- ์กฐ์ฌ๋ ์ฌ๋ก๋ค(Netflix, Tesla, OpenAI)์ด ๊ฐ ๋จ๊ณ์ ์ ์ ํ ํ์ฉ๋จ
|
1857 |
-
- ๊ตฌ์ฒด์ ์ธ ๋๊ตฌ์ ๊ธฐ๋ฒ์ด ๋ช
์๋์ด ์คํ ๊ฐ๋ฅ์ฑ์ด ๋์
|
1858 |
-
- ์ธก์ ๊ฐ๋ฅํ ๋ชฉํ๊ฐ ์กฐ์ฌ ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ค์ ๋จ
|
1859 |
-
|
1860 |
-
**๊ฐ์ ํ์์ฌํญ**
|
1861 |
-
1. **๋ฆฌ์คํฌ ๊ด๋ฆฌ ๊ฐํ**
|
1862 |
-
- ๊ฐ ๋จ๊ณ๋ณ ์คํจ ์๋๋ฆฌ์ค์ ๋์ ๋ฐฉ์ ์ถ๊ฐ ํ์
|
1863 |
-
- ๊ธฐ์ ์ ๋ฌธ์ ๋ฐ์ ์ ๋ฐฑ์
๊ณํ ์๋ฆฝ
|
1864 |
-
|
1865 |
-
2. **๋น์ฉ ๋ถ์ ๊ตฌ์ฒดํ**
|
1866 |
-
- OpenAI ์ฌ๋ก์ 70% ์ ๊ฐ์ ์ํ ๊ตฌ์ฒด์ ์ธ ๋น์ฉ ๊ณ์ฐ
|
1867 |
-
- ROI ๋ถ์ ๋ฐ ํฌ์ ๋๋น ํจ๊ณผ ์ธก์ ๋ฐฉ๋ฒ
|
1868 |
-
|
1869 |
-
**์ถ๊ฐ ๊ถ์ฅ์ฌํญ**
|
1870 |
-
- ์ต์ ์ฐ๊ตฌ ๋ํฅ ๋ชจ๋ํฐ๋ง ์ฒด๊ณ ๊ตฌ์ถ
|
1871 |
-
- ๊ฒฝ์์ฌ ๋ฒค์น๋งํน์ ์ํ ์ ๊ธฐ์ ์ธ ์กฐ์ฌ ํ๋ก์ธ์ค""",
|
1872 |
-
|
1873 |
-
"executor_final": """๊ฐ๋
์ AI์ ํผ๋๋ฐฑ์ ์์ ํ ๋ฐ์ํ์ฌ ์ต์ข
์คํ ๋ณด๊ณ ์๋ฅผ ์์ฑํฉ๋๋ค.
|
1874 |
-
|
1875 |
-
# ๐ฏ ๊ธฐ๊ณํ์ต ๋ชจ๋ธ ์ฑ๋ฅ ํฅ์ ์ต์ข
์คํ ๋ณด๊ณ ์
|
1876 |
-
|
1877 |
-
## ๐ Executive Summary
|
1878 |
-
๋ณธ ๋ณด๊ณ ์๋ ์น ๊ฒ์์ ํตํด ์์ง๋ ์ต์ ์ฌ๋ก์ ๊ฐ๋
์ AI์ ์ ๋ต์ ์ง์นจ์ ๋ฐํ์ผ๋ก, 8์ฃผ๊ฐ์ ์ฒด๊ณ์ ์ธ ๋ชจ๋ธ ์ต์ ํ ํ๋ก์ ํธ๋ฅผ ์ ์ํฉ๋๋ค. ๋ชฉํ๋ ๋ชจ๋ธ ํฌ๊ธฐ 90% ๊ฐ์, ์ถ๋ก ์๋ 10๋ฐฐ ํฅ์, ์ด์ ๋น์ฉ 70% ์ ๊ฐ์
๋๋ค.
|
1879 |
-
|
1880 |
-
## ๐ 1๋จ๊ณ: ํ์ฌ ๋ชจ๋ธ ์ง๋จ ๋ฐ ๋ฒ ์ด์ค๋ผ์ธ ์ค์ (1์ฃผ์ฐจ)
|
1881 |
-
|
1882 |
-
### ์คํ ๊ณํ
|
1883 |
-
**์-ํ์์ผ: ์ฑ๋ฅ ๋ฉํธ๋ฆญ ์์ง**
|
1884 |
-
- MLflow๋ฅผ ํตํ ํ์ฌ ๋ชจ๋ธ ์ ์ฒด ๋ถ์
|
1885 |
-
- Netflix ์ฌ๋ก ๊ธฐ๋ฐ ํต์ฌ ์งํ: ์ ํ๋(92%), ์ง์ฐ์๊ฐ(45ms), ์ฒ๋ฆฌ๋(1,000 req/s)
|
1886 |
-
|
1887 |
-
**์-๋ชฉ์์ผ: AutoML ์ด๊ธฐ ํ์**
|
1888 |
-
- Optuna๋ก ํ์ดํผํ๋ผ๋ฏธํฐ ์ต์ ํ (200ํ ์๋)
|
1889 |
-
- Ray Tune์ผ๋ก ๋ถ์ฐ ํ์ต ํ๊ฒฝ ๊ตฌ์ถ
|
1890 |
-
|
1891 |
-
### ์์ ์ฐ์ถ๋ฌผ
|
1892 |
-
- ์์ธ ์ฑ๋ฅ ๋ฒ ์ด์ค๋ผ์ธ ๋ฌธ์
|
1893 |
-
- ๊ฐ์ ๊ธฐํ ์ฐ์ ์์ ๋งคํธ๋ฆญ์ค
|
1894 |
-
|
1895 |
-
## ๐ 2๋จ๊ณ: ๋ฐ์ดํฐ ํ์ง ๊ฐ์ (2-3์ฃผ์ฐจ)
|
1896 |
-
|
1897 |
-
### ์คํ ๊ณํ
|
1898 |
-
- ๋ฐ์ดํฐ ์ ์ ํ์ดํ๋ผ์ธ ๊ตฌ์ถ
|
1899 |
-
- ๊ณ ๊ธ ๋ฐ์ดํฐ ์ฆ๊ฐ ๊ธฐ๋ฒ ์ ์ฉ
|
1900 |
-
- A/B ํ
์คํธ๋ก ํจ๊ณผ ๊ฒ์ฆ
|
1901 |
-
|
1902 |
-
## ๐ 3๋จ๊ณ: ๋ชจ๋ธ ์ต์ ํ ๊ตฌํ (4-6์ฃผ์ฐจ)
|
1903 |
-
|
1904 |
-
### ์คํ ๊ณํ
|
1905 |
-
- Knowledge Distillation์ผ๋ก ๋ชจ๋ธ ๊ฒฝ๋ํ
|
1906 |
-
- Pruning & Quantization ์ ์ฉ
|
1907 |
-
- TensorRT ์ต์ ํ (Tesla ์ฌ๋ก ์ ์ฉ)
|
1908 |
-
|
1909 |
-
## ๐ 4๋จ๊ณ: ์ฑ๊ณผ ๊ฒ์ฆ ๋ฐ ํ๋ก๋์
๋ฐฐํฌ (7-8์ฃผ์ฐจ)
|
1910 |
-
|
1911 |
-
### ์คํ ๊ณํ
|
1912 |
-
- ์ข
ํฉ ์ฑ๋ฅ ๊ฒ์ฆ ๋ฐ ์งํ ๋ฌ์ฑ๋ ํ์ธ
|
1913 |
-
- Canary ๋ฐฐํฌ ์ ๋ต ์คํ
|
1914 |
-
- ์ค์๊ฐ ๋ชจ๋ํฐ๋ง ์ฒด๊ณ ๊ตฌ์ถ
|
1915 |
-
|
1916 |
-
## ๐ ๊ฒฐ๋ก
|
1917 |
-
๋ณธ ํ๋ก์ ํธ๋ ์ต์ ์ฐ๊ตฌ ๊ฒฐ๊ณผ์ ์
๊ณ ๋ฒ ์คํธ ํ๋ํฐ์ค๋ฅผ ์ ์ฉํ์ฌ, 8์ฃผ ๋ง์ ๋ชจ๋ธ ์ฑ๋ฅ์ ํ๊ธฐ์ ์ผ๋ก ๊ฐ์ ํ๊ณ ์ด์ ๋น์ฉ์ 70% ์ ๊ฐํ๋ ์ฑ๊ณผ๋ฅผ ๋ฌ์ฑํ ๊ฒ์ผ๋ก ์์๋ฉ๋๋ค.""",
|
1918 |
-
|
1919 |
-
"evaluator": """## ๐ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ํ๊ฐ ๋ณด๊ณ ์
|
1920 |
-
|
1921 |
-
### 1๏ธโฃ ํ์ง ํ๊ฐ (10์ ๋ง์ )
|
1922 |
-
|
1923 |
-
**๊ฐ๋
์ AI: 9.5/10**
|
1924 |
-
- ๊ฑฐ์์ ๊ด์ ์์ ์ฒด๊ณ์ ์ธ ๋ถ์๊ณผ ๋ฐฉํฅ ์ ์
|
1925 |
-
- ๋จ๊ณ๋ณ ๊ตฌ์ฒด์ ์ธ ์ง์์ฌํญ ์ ๊ณต
|
1926 |
-
- ํผ๋๋ฐฑ์ด ๊ฑด์ค์ ์ด๊ณ ์คํ ๊ฐ๋ฅํจ
|
1927 |
-
|
1928 |
-
**์กฐ์ฌ๏ฟฝ๏ฟฝ๏ฟฝ AI: 9.0/10**
|
1929 |
-
- ์น ๊ฒ์์ ํตํ ์ต์ ์ ๋ณด ์์ง ์ฐ์
|
1930 |
-
- ์ ๋ขฐ๋ ํ๊ฐ์ ๋ชจ์ ๊ฐ์ง ๊ธฐ๋ฅ ํจ๊ณผ์
|
1931 |
-
- ์ถ์ฒ ํ๊ธฐ์ ์ ๋ณด ์ ๋ฆฌ๊ฐ ์ฒด๊ณ์
|
1932 |
-
|
1933 |
-
**์คํ์ AI: 8.5/10**
|
1934 |
-
- ์กฐ์ฌ ๋ด์ฉ์ ์ ํ์ฉํ ๊ตฌ์ฒด์ ๊ณํ ์๋ฆฝ
|
1935 |
-
- ์คํ ๊ฐ๋ฅํ ๋จ๊ณ๋ณ ์ ๊ทผ๋ฒ ์ ์
|
1936 |
-
- ์ผ๋ถ ์ธ๋ถ์ฌํญ์์ ๋ ๊ตฌ์ฒดํ ํ์
|
1937 |
-
|
1938 |
-
### 2๏ธโฃ ํ๋ ฅ ํจ๊ณผ์ฑ ํ๊ฐ
|
1939 |
-
|
1940 |
-
**๊ฐ์ :**
|
1941 |
-
- AI ๊ฐ ์ญํ ๋ถ๋ด์ด ๋ช
ํํ๊ณ ์ํธ๋ณด์์
|
1942 |
-
- ์ ๋ณด ํ๋ฆ์ด ์ฒด๊ณ์ ์ด๊ณ ์ผ๊ด์ฑ ์์
|
1943 |
-
- ํผ๋๋ฐฑ ๋ฐ์์ด ํจ๊ณผ์ ์ผ๋ก ์ด๋ฃจ์ด์ง
|
1944 |
-
|
1945 |
-
**๊ฐ์ ์ :**
|
1946 |
-
- ์ค์๊ฐ ์ํธ์์ฉ ๋ฉ์ปค๋์ฆ ์ถ๊ฐ ๊ณ ๋ ค
|
1947 |
-
- ์ค๊ฐ ์ ๊ฒ ๋จ๊ณ ๋์
ํ์
|
1948 |
-
|
1949 |
-
### 3๏ธโฃ ์ ๋ณด ํ์ฉ๋ ํ๊ฐ
|
1950 |
-
|
1951 |
-
**์ฐ์ํ ์ :**
|
1952 |
-
- 20๊ฐ ์ด์์ ์น ์์ค์์ ์ ๋ณด ์์ง
|
1953 |
-
- ์ ๋ขฐ๋ ๊ธฐ๋ฐ ์ ๋ณด ์ ๋ณ ํจ๊ณผ์
|
1954 |
-
- ์ค์ ๊ธฐ์
์ฌ๋ก ์ ์ ํ ํ์ฉ
|
1955 |
-
|
1956 |
-
**๋ณด์ ํ์:**
|
1957 |
-
- ํ์ ๋
ผ๋ฌธ ๋ฑ ๋ ๊น์ด ์๋ ์๋ฃ ํ์ฉ
|
1958 |
-
- ์ง์ญ๋ณ/์ฐ์
๋ณ ํน์ฑ ๊ณ ๋ ค ํ์
|
1959 |
-
|
1960 |
-
### 4๏ธโฃ ํฅํ ๊ฐ์ ๋ฐฉํฅ
|
1961 |
-
|
1962 |
-
1. **์ค์๊ฐ ํ์
๊ฐํ**
|
1963 |
-
- AI ๊ฐ ์ค๊ฐ ์ฒดํฌํฌ์ธํธ ์ถ๊ฐ
|
1964 |
-
- ๋์ ์ญํ ์กฐ์ ๋ฉ์ปค๋์ฆ ๋์
|
1965 |
-
|
1966 |
-
2. **์ ๋ณด ๊ฒ์ฆ ๊ฐํ**
|
1967 |
-
- ๊ต์ฐจ ๊ฒ์ฆ ํ๋ก์ธ์ค ์ถ๊ฐ
|
1968 |
-
- ์ ๋ฌธ๊ฐ ๊ฒํ ๋จ๊ณ ๊ณ ๋ ค
|
1969 |
-
|
1970 |
-
3. **๋ง์ถคํ ๊ฐํ**
|
1971 |
-
- ์ฌ์ฉ์ ์ปจํ
์คํธ ๋ ๊น์ด ๋ฐ์
|
1972 |
-
- ์ฐ์
๋ณ/๊ท๋ชจ๋ณ ๋ง์ถค ์ ๋ต ์ ๊ณต
|
1973 |
-
|
1974 |
-
### 5๏ธโฃ ์ต์ข
ํ์ : โญโญโญโญโญ 9.0/10
|
1975 |
-
|
1976 |
-
**์ข
ํฉ ํ๊ฐ:**
|
1977 |
-
๋ณธ ํ๋ ฅ ์์คํ
์ ๊ฐ AI์ ์ ๋ฌธ์ฑ์ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ์ฌ ์ฌ์ฉ์ ์ง๋ฌธ์ ๋ํ ์ข
ํฉ์ ์ด๊ณ ์คํ ๊ฐ๋ฅํ ๋ต๋ณ์ ์ ๊ณตํ์ต๋๋ค. ํนํ ์น ๊ฒ์์ ํตํ ์ต์ ์ ๋ณด ํ์ฉ๊ณผ ๋จ๊ณ์ ํผ๋๋ฐฑ ๋ฐ์์ด ์ฐ์ํ์ต๋๋ค. ํฅํ ์ค์๊ฐ ํ์
๊ณผ ๋ง์ถคํ๋ฅผ ๋์ฑ ๊ฐํํ๋ค๋ฉด ๋์ฑ ๋ฐ์ด๋ ์ฑ๊ณผ๋ฅผ ๋ฌ์ฑํ ์ ์์ ๊ฒ์
๋๋ค."""
|
1978 |
-
}
|
1979 |
-
|
1980 |
-
# ํ๋กฌํํธ ๋ด์ฉ์ ๋ฐ๋ผ ์ ์ ํ ์๋ต ์ ํ
|
1981 |
-
if role == "supervisor" and "์กฐ์ฌ์ AI๊ฐ ์ ๋ฆฌํ" in messages[0]["content"]:
|
1982 |
-
response = test_responses["supervisor_execution"]
|
1983 |
-
elif role == "supervisor" and messages[0]["content"].find("์คํ์ AI์ ๋ต๋ณ") > -1:
|
1984 |
-
response = test_responses["supervisor_review"]
|
1985 |
-
elif role == "supervisor":
|
1986 |
-
response = test_responses["supervisor_initial"]
|
1987 |
-
elif role == "researcher":
|
1988 |
-
response = test_responses["researcher"]
|
1989 |
-
elif role == "executor" and "์ต์ข
๋ณด๊ณ ์" in messages[0]["content"]:
|
1990 |
-
response = test_responses["executor_final"]
|
1991 |
-
elif role == "evaluator":
|
1992 |
-
response = test_responses["evaluator"]
|
1993 |
-
else:
|
1994 |
-
response = test_responses["executor"]
|
1995 |
-
|
1996 |
-
yield from self.simulate_streaming(response, role)
|
1997 |
-
return
|
1998 |
-
|
1999 |
-
# ์ค์ API ํธ์ถ
|
2000 |
-
try:
|
2001 |
-
system_prompts = {
|
2002 |
-
"supervisor": "๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.",
|
2003 |
-
"researcher": "๋น์ ์ ์ ๋ณด๋ฅผ ์กฐ์ฌํ๊ณ ์ฒด๊ณ์ ์ผ๋ก ์ ๋ฆฌํ๋ ์กฐ์ฌ์ AI์
๋๋ค.",
|
2004 |
-
"executor": "๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค.",
|
2005 |
-
"evaluator": "๋น์ ์ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ๋ ํ๊ฐ์ AI์
๋๋ค."
|
2006 |
-
}
|
2007 |
-
|
2008 |
-
full_messages = [
|
2009 |
-
{"role": "system", "content": system_prompts.get(role, "")},
|
2010 |
-
*messages
|
2011 |
-
]
|
2012 |
-
|
2013 |
-
payload = {
|
2014 |
-
"model": self.model_id,
|
2015 |
-
"messages": full_messages,
|
2016 |
-
"max_tokens": 2048,
|
2017 |
-
"temperature": 0.7,
|
2018 |
-
"top_p": 0.8,
|
2019 |
-
"stream": True,
|
2020 |
-
"stream_options": {"include_usage": True}
|
2021 |
-
}
|
2022 |
-
|
2023 |
-
logger.info(f"API ์คํธ๋ฆฌ๋ฐ ํธ์ถ ์์ - Role: {role}")
|
2024 |
-
|
2025 |
-
response = requests.post(
|
2026 |
-
self.api_url,
|
2027 |
-
headers=self.create_headers(),
|
2028 |
-
json=payload,
|
2029 |
-
stream=True,
|
2030 |
-
timeout=10
|
2031 |
-
)
|
2032 |
-
|
2033 |
-
if response.status_code != 200:
|
2034 |
-
logger.error(f"API ์ค๋ฅ: {response.status_code}")
|
2035 |
-
yield f"โ API ์ค๋ฅ ({response.status_code}): {response.text[:200]}"
|
2036 |
-
return
|
2037 |
-
|
2038 |
-
for line in response.iter_lines():
|
2039 |
-
if line:
|
2040 |
-
line = line.decode('utf-8')
|
2041 |
-
if line.startswith("data: "):
|
2042 |
-
data = line[6:]
|
2043 |
-
if data == "[DONE]":
|
2044 |
-
break
|
2045 |
-
try:
|
2046 |
-
chunk = json.loads(data)
|
2047 |
-
if "choices" in chunk and chunk["choices"]:
|
2048 |
-
content = chunk["choices"][0].get("delta", {}).get("content", "")
|
2049 |
-
if content:
|
2050 |
-
yield content
|
2051 |
-
except json.JSONDecodeError:
|
2052 |
-
continue
|
2053 |
-
|
2054 |
-
except requests.exceptions.Timeout:
|
2055 |
-
yield "โฑ๏ธ API ํธ์ถ ์๊ฐ์ด ์ด๊ณผ๋์์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์."
|
2056 |
-
except requests.exceptions.ConnectionError:
|
2057 |
-
yield "๐ API ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. ์ธํฐ๋ท ์ฐ๊ฒฐ์ ํ์ธํด์ฃผ์ธ์."
|
2058 |
-
except Exception as e:
|
2059 |
-
logger.error(f"์คํธ๋ฆฌ๋ฐ ์ค ์ค๋ฅ: {str(e)}")
|
2060 |
-
yield f"โ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
2061 |
-
|
2062 |
-
# ์์คํ
์ธ์คํด์ค ์์ฑ
|
2063 |
-
llm_system = LLMCollaborativeSystem()
|
2064 |
-
|
2065 |
-
# ๋ด๋ถ ํ์คํ ๋ฆฌ ๊ด๋ฆฌ (UI์๋ ํ์ํ์ง ์์)
|
2066 |
-
internal_history = []
|
2067 |
-
|
2068 |
-
def process_query_streaming(user_query: str, llm_mode: str):
|
2069 |
-
"""์คํธ๋ฆฌ๋ฐ์ ์ง์ํ๋ ์ฟผ๋ฆฌ ์ฒ๋ฆฌ"""
|
2070 |
-
global internal_history
|
2071 |
-
|
2072 |
-
if not user_query:
|
2073 |
-
return "", "", "", "", "โ ์ง๋ฌธ์ ์
๋ ฅํด์ฃผ์ธ์."
|
2074 |
-
|
2075 |
-
# LLM ๋ชจ๋ ์ค์
|
2076 |
-
llm_system.set_llm_mode(llm_mode)
|
2077 |
-
|
2078 |
-
conversation_log = []
|
2079 |
-
all_responses = {"supervisor": [], "researcher": [], "executor": [], "evaluator": []}
|
2080 |
-
|
2081 |
-
try:
|
2082 |
-
# 1๋จ๊ณ: ๊ฐ๋
์ AI ์ด๊ธฐ ๋ถ์ ๋ฐ ํค์๋ ์ถ์ถ
|
2083 |
-
supervisor_prompt = llm_system.create_supervisor_initial_prompt(user_query)
|
2084 |
-
supervisor_initial_response = ""
|
2085 |
-
|
2086 |
-
supervisor_text = "[์ด๊ธฐ ๋ถ์] ๐ ์์ฑ ์ค...\n"
|
2087 |
-
for chunk in llm_system.call_llm_streaming(
|
2088 |
-
[{"role": "user", "content": supervisor_prompt}],
|
2089 |
-
"supervisor"
|
2090 |
-
):
|
2091 |
-
supervisor_initial_response += chunk
|
2092 |
-
supervisor_text = f"[์ด๊ธฐ ๋ถ์] - {datetime.now().strftime('%H:%M:%S')}\n{supervisor_initial_response}"
|
2093 |
-
yield supervisor_text, "", "", "", "๐ ๊ฐ๋
์ AI๊ฐ ๋ถ์ ์ค..."
|
2094 |
-
|
2095 |
-
all_responses["supervisor"].append(supervisor_initial_response)
|
2096 |
-
|
2097 |
-
# ํค์๋ ์ถ์ถ
|
2098 |
-
keywords = llm_system.extract_keywords(supervisor_initial_response)
|
2099 |
-
logger.info(f"์ถ์ถ๋ ํค์๋: {keywords}")
|
2100 |
-
|
2101 |
-
# 2๋จ๊ณ: ๋ธ๋ ์ด๋ธ ๊ฒ์ ์ํ
|
2102 |
-
researcher_text = "[์น ๊ฒ์] ๐ ๊ฒ์ ์ค...\n"
|
2103 |
-
yield supervisor_text, researcher_text, "", "", "๐ ์น ๊ฒ์ ์ํ ์ค..."
|
2104 |
-
|
2105 |
-
search_results = {}
|
2106 |
-
total_search_count = 0
|
2107 |
-
|
2108 |
-
# ์๋ ํค์๋๋ก ๊ฒ์
|
2109 |
-
for keyword in keywords:
|
2110 |
-
results = llm_system.brave_search(keyword)
|
2111 |
-
if results:
|
2112 |
-
search_results[keyword] = results
|
2113 |
-
total_search_count += len(results)
|
2114 |
-
researcher_text += f"โ '{keyword}' ๊ฒ์ ์๋ฃ ({len(results)}๊ฐ ๊ฒฐ๊ณผ)\n"
|
2115 |
-
yield supervisor_text, researcher_text, "", "", f"๐ '{keyword}' ๊ฒ์ ์ค..."
|
2116 |
-
|
2117 |
-
# ๋์์ด๋ก ์ถ๊ฐ ๊ฒ์
|
2118 |
-
synonyms = llm_system.generate_synonyms(keyword)
|
2119 |
-
for synonym in synonyms:
|
2120 |
-
syn_results = llm_system.brave_search(f"{keyword} {synonym}")
|
2121 |
-
if syn_results:
|
2122 |
-
search_results[f"{keyword} ({synonym})"] = syn_results
|
2123 |
-
total_search_count += len(syn_results)
|
2124 |
-
researcher_text += f"โ ๋์์ด '{synonym}' ๊ฒ์ ์๋ฃ ({len(syn_results)}๊ฐ ๊ฒฐ๊ณผ)\n"
|
2125 |
-
yield supervisor_text, researcher_text, "", "", f"๐ ๋์์ด '{synonym}' ๊ฒ์ ์ค..."
|
2126 |
-
|
2127 |
-
researcher_text += f"\n๐ ์ด {total_search_count}๊ฐ์ ๊ฒ์ ๊ฒฐ๊ณผ ์์ง ์๋ฃ\n"
|
2128 |
-
|
2129 |
-
# URL ์ฝํ
์ธ ๊ฐ์ ธ์ค๊ธฐ (์์ 3๊ฐ)
|
2130 |
-
researcher_text += "\n[์ฝํ
์ธ ๋ถ์] ๐ ์ฃผ์ ์นํ์ด์ง ๋ด์ฉ ๋ถ์ ์ค...\n"
|
2131 |
-
yield supervisor_text, researcher_text, "", "", "๐ ์นํ์ด์ง ๋ด์ฉ ๋ถ์ ์ค..."
|
2132 |
-
|
2133 |
-
content_analyzed = 0
|
2134 |
-
for keyword, results in search_results.items():
|
2135 |
-
for result in results[:2]: # ๊ฐ ํค์๋๋น ์์ 2๊ฐ๋ง
|
2136 |
-
if content_analyzed >= 5: # ์ด 5๊ฐ๊น์ง๋ง
|
2137 |
-
break
|
2138 |
-
|
2139 |
-
url = result.get('url', '')
|
2140 |
-
if url and result.get('credibility_score', 0) >= 0.7:
|
2141 |
-
content = llm_system.fetch_url_content(url)
|
2142 |
-
if content:
|
2143 |
-
result['content_preview'] = content[:500] # ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ ์ฅ
|
2144 |
-
content_analyzed += 1
|
2145 |
-
researcher_text += f"โ ์ฝํ
์ธ ๋ถ์ ์๋ฃ: {url[:50]}...\n"
|
2146 |
-
yield supervisor_text, researcher_text, "", "", f"๐ ๋ถ์ ์ค: {url[:30]}..."
|
2147 |
-
|
2148 |
-
# 3๋จ๊ณ: ์กฐ์ฌ์ AI๊ฐ ๊ฒ์ ๊ฒฐ๊ณผ ์ ๋ฆฌ
|
2149 |
-
researcher_prompt = llm_system.create_researcher_prompt(user_query, supervisor_initial_response, search_results)
|
2150 |
-
researcher_response = ""
|
2151 |
-
|
2152 |
-
researcher_text = "[์กฐ์ฌ ๊ฒฐ๊ณผ ์ ๋ฆฌ] ๐ ์์ฑ ์ค...\n"
|
2153 |
-
for chunk in llm_system.call_llm_streaming(
|
2154 |
-
[{"role": "user", "content": researcher_prompt}],
|
2155 |
-
"researcher"
|
2156 |
-
):
|
2157 |
-
researcher_response += chunk
|
2158 |
-
researcher_text = f"[์กฐ์ฌ ๊ฒฐ๊ณผ ์ ๋ฆฌ] - {datetime.now().strftime('%H:%M:%S')}\n{researcher_response}"
|
2159 |
-
yield supervisor_text, researcher_text, "", "", "๐ ์กฐ์ฌ์ AI๊ฐ ์ ๋ฆฌ ์ค..."
|
2160 |
-
|
2161 |
-
all_responses["researcher"].append(researcher_response)
|
2162 |
-
|
2163 |
-
# 4๋จ๊ณ: ๊ฐ๋
์ AI๊ฐ ์กฐ์ฌ ๋ด์ฉ ๊ธฐ๋ฐ์ผ๋ก ์คํ ์ง์
|
2164 |
-
supervisor_execution_prompt = llm_system.create_supervisor_execution_prompt(user_query, researcher_response)
|
2165 |
-
supervisor_execution_response = ""
|
2166 |
-
|
2167 |
-
supervisor_text += "\n\n---\n\n[์คํ ์ง์] ๐ ์์ฑ ์ค...\n"
|
2168 |
-
for chunk in llm_system.call_llm_streaming(
|
2169 |
-
[{"role": "user", "content": supervisor_execution_prompt}],
|
2170 |
-
"supervisor"
|
2171 |
-
):
|
2172 |
-
supervisor_execution_response += chunk
|
2173 |
-
temp_text = f"{all_responses['supervisor'][0]}\n\n---\n\n[์คํ ์ง์] - {datetime.now().strftime('%H:%M:%S')}\n{supervisor_execution_response}"
|
2174 |
-
supervisor_text = f"[์ด๊ธฐ ๋ถ์] - {datetime.now().strftime('%H:%M:%S')}\n{temp_text}"
|
2175 |
-
yield supervisor_text, researcher_text, "", "", "๐ฏ ๊ฐ๋
์ AI๊ฐ ์ง์ ์ค..."
|
2176 |
-
|
2177 |
-
all_responses["supervisor"].append(supervisor_execution_response)
|
2178 |
-
|
2179 |
-
# 5๋จ๊ณ: ์คํ์ AI๊ฐ ์กฐ์ฌ ๋ด์ฉ๊ณผ ์ง์๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๊ธฐ ๊ตฌํ
|
2180 |
-
executor_prompt = llm_system.create_executor_prompt(user_query, supervisor_execution_response, researcher_response)
|
2181 |
-
executor_response = ""
|
2182 |
-
|
2183 |
-
executor_text = "[์ด๊ธฐ ๊ตฌํ] ๐ ์์ฑ ์ค...\n"
|
2184 |
-
for chunk in llm_system.call_llm_streaming(
|
2185 |
-
[{"role": "user", "content": executor_prompt}],
|
2186 |
-
"executor"
|
2187 |
-
):
|
2188 |
-
executor_response += chunk
|
2189 |
-
executor_text = f"[์ด๊ธฐ ๊ตฌํ] - {datetime.now().strftime('%H:%M:%S')}\n{executor_response}"
|
2190 |
-
yield supervisor_text, researcher_text, executor_text, "", "๐ง ์คํ์ AI๊ฐ ๊ตฌํ ์ค..."
|
2191 |
-
|
2192 |
-
all_responses["executor"].append(executor_response)
|
2193 |
-
|
2194 |
-
# 6๋จ๊ณ: ๊ฐ๋
์ AI ๊ฒํ ๋ฐ ํผ๋๋ฐฑ
|
2195 |
-
review_prompt = f"""๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.
|
2196 |
-
|
2197 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
2198 |
-
|
2199 |
-
์คํ์ AI์ ๋ต๋ณ:
|
2200 |
-
{executor_response}
|
2201 |
-
|
2202 |
-
์ด ๋ต๋ณ์ ๊ฒํ ํ๊ณ ๊ฐ์ ์ ๊ณผ ์ถ๊ฐ ๊ณ ๋ ค์ฌํญ์ ์ ์ํด์ฃผ์ธ์. ๊ตฌ์ฒด์ ์ด๊ณ ์คํ ๊ฐ๋ฅํ ๊ฐ์ ๋ฐฉ์์ ์ ์ํ์ธ์."""
|
2203 |
-
|
2204 |
-
review_response = ""
|
2205 |
-
supervisor_text = f"[์ด๊ธฐ ๋ถ์] - {datetime.now().strftime('%H:%M:%S')}\n{all_responses['supervisor'][0]}\n\n---\n\n[์คํ ์ง์] - {datetime.now().strftime('%H:%M:%S')}\n{all_responses['supervisor'][1]}\n\n---\n\n[๊ฒํ ๋ฐ ํผ๋๋ฐฑ] ๐ ์์ฑ ์ค...\n"
|
2206 |
-
|
2207 |
-
for chunk in llm_system.call_llm_streaming(
|
2208 |
-
[{"role": "user", "content": review_prompt}],
|
2209 |
-
"supervisor"
|
2210 |
-
):
|
2211 |
-
review_response += chunk
|
2212 |
-
temp_text = f"{all_responses['supervisor'][0]}\n\n---\n\n[์คํ ์ง์] - {datetime.now().strftime('%H:%M:%S')}\n{all_responses['supervisor'][1]}\n\n---\n\n[๊ฒํ ๋ฐ ํผ๋๋ฐฑ] - {datetime.now().strftime('%H:%M:%S')}\n{review_response}"
|
2213 |
-
supervisor_text = f"[์ด๊ธฐ ๋ถ์] - {datetime.now().strftime('%H:%M:%S')}\n{temp_text}"
|
2214 |
-
yield supervisor_text, researcher_text, executor_text, "", "๐ ๊ฐ๋
์ AI๊ฐ ๊ฒํ ์ค..."
|
2215 |
-
|
2216 |
-
all_responses["supervisor"].append(review_response)
|
2217 |
-
|
2218 |
-
# 7๋จ๊ณ: ์คํ์ AI ์ต์ข
๋ณด๊ณ ์ (ํผ๋๋ฐฑ ๋ฐ์)
|
2219 |
-
final_executor_prompt = llm_system.create_executor_final_prompt(
|
2220 |
-
user_query,
|
2221 |
-
executor_response,
|
2222 |
-
review_response,
|
2223 |
-
researcher_response
|
2224 |
-
)
|
2225 |
-
final_executor_response = ""
|
2226 |
-
|
2227 |
-
executor_text += "\n\n---\n\n[์ต์ข
๋ณด๊ณ ์] ๐ ์์ฑ ์ค...\n"
|
2228 |
-
for chunk in llm_system.call_llm_streaming(
|
2229 |
-
[{"role": "user", "content": final_executor_prompt}],
|
2230 |
-
"executor"
|
2231 |
-
):
|
2232 |
-
final_executor_response += chunk
|
2233 |
-
temp_text = f"[์ด๊ธฐ ๊ตฌํ] - {datetime.now().strftime('%H:%M:%S')}\n{all_responses['executor'][0]}\n\n---\n\n[์ต์ข
๋ณด๊ณ ์] - {datetime.now().strftime('%H:%M:%S')}\n{final_executor_response}"
|
2234 |
-
executor_text = temp_text
|
2235 |
-
yield supervisor_text, researcher_text, executor_text, "", "๐ ์ต์ข
๋ณด๊ณ ์ ์์ฑ ์ค..."
|
2236 |
-
|
2237 |
-
all_responses["executor"].append(final_executor_response)
|
2238 |
-
|
2239 |
-
# 8๋จ๊ณ: ํ๊ฐ์ AI๊ฐ ์ ์ฒด ๊ณผ์ ํ๊ฐ
|
2240 |
-
evaluator_prompt = llm_system.create_evaluator_prompt(
|
2241 |
-
user_query,
|
2242 |
-
all_responses["supervisor"],
|
2243 |
-
all_responses["researcher"][0],
|
2244 |
-
all_responses["executor"]
|
2245 |
-
)
|
2246 |
-
evaluator_response = ""
|
2247 |
-
|
2248 |
-
evaluator_text = "[์ ์ฒด ํ๊ฐ] ๐ ํ๊ฐ ์ค...\n"
|
2249 |
-
for chunk in llm_system.call_llm_streaming(
|
2250 |
-
[{"role": "user", "content": evaluator_prompt}],
|
2251 |
-
"evaluator"
|
2252 |
-
):
|
2253 |
-
evaluator_response += chunk
|
2254 |
-
evaluator_text = f"[์ ์ฒด ํ๊ฐ] - {datetime.now().strftime('%H:%M:%S')}\n{evaluator_response}"
|
2255 |
-
yield supervisor_text, researcher_text, executor_text, evaluator_text, "๐ ํ๊ฐ์ AI๊ฐ ํ๊ฐ ์ค..."
|
2256 |
-
|
2257 |
-
all_responses["evaluator"].append(evaluator_response)
|
2258 |
-
|
2259 |
-
# ์ต์ข
๊ฒฐ๊ณผ ์์ฑ (์ต์ข
๋ณด๊ณ ์๋ฅผ ๋ฉ์ธ์ผ๋ก)
|
2260 |
-
final_summary = f"""## ๐ฏ ์ต์ข
์ข
ํฉ ๋ณด๊ณ ์
|
2261 |
-
|
2262 |
-
### ๐ ์ฌ์ฉ์ ์ง๋ฌธ
|
2263 |
-
{user_query}
|
2264 |
-
|
2265 |
-
### ๐ ์ต์ข
๋ณด๊ณ ์ (์คํ์ AI - ํผ๋๋ฐฑ ๋ฐ์)
|
2266 |
-
{final_executor_response}
|
2267 |
-
|
2268 |
-
---
|
2269 |
-
|
2270 |
-
### ๐ ์ ์ฒด ํ๋ก์ธ์ค ํ๊ฐ (ํ๊ฐ์ AI)
|
2271 |
-
{evaluator_response}
|
2272 |
-
|
2273 |
-
---
|
2274 |
-
|
2275 |
-
<details>
|
2276 |
-
<summary>๐ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๋ณด๊ธฐ</summary>
|
2277 |
-
|
2278 |
-
#### ๐ ๊ฑฐ์์ ๋ถ์ (๊ฐ๋
์ AI)
|
2279 |
-
{all_responses['supervisor'][0]}
|
2280 |
-
|
2281 |
-
#### ๐ ์กฐ์ฌ ๊ฒฐ๊ณผ (์กฐ์ฌ์ AI)
|
2282 |
-
{researcher_response}
|
2283 |
-
|
2284 |
-
#### ๐ฏ ์คํ ์ง์ (๊ฐ๋
์ AI)
|
2285 |
-
{all_responses['supervisor'][1]}
|
2286 |
-
|
2287 |
-
#### ๐ก ์ด๊ธฐ ๊ตฌํ (์คํ์ AI)
|
2288 |
-
{executor_response}
|
2289 |
-
|
2290 |
-
#### โจ ๊ฒํ ๋ฐ ๊ฐ์ ์ฌํญ (๊ฐ๋
์ AI)
|
2291 |
-
{review_response}
|
2292 |
-
|
2293 |
-
</details>
|
2294 |
-
|
2295 |
-
---
|
2296 |
-
*์ด ๋ณด๊ณ ์๋ {'Gemini 2.5 Pro' if llm_system.use_gemini else '๊ธฐ๋ณธ LLM'}๋ฅผ ์ฌ์ฉํ์ฌ ์น ๊ฒ์๊ณผ AI ํ๋ ฅ์ ํตํด ์์ฑ๋์์ต๋๋ค.*"""
|
2297 |
-
|
2298 |
-
# ๋ด๋ถ ํ์คํ ๋ฆฌ ์
๋ฐ์ดํธ (UI์๋ ํ์ํ์ง ์์)
|
2299 |
-
internal_history.append((user_query, final_summary))
|
2300 |
-
|
2301 |
-
# ์ต์ข
์์ฝ๋ง ํ์
|
2302 |
-
display_summary = f"""## ๐ฏ ์ต์ข
๊ฒฐ๊ณผ
|
2303 |
-
|
2304 |
-
### ๐ ์คํ ๋ณด๊ณ ์
|
2305 |
-
{final_executor_response}
|
2306 |
-
|
2307 |
-
### ๐ ํ๊ฐ ์์ฝ
|
2308 |
-
{evaluator_response.split('### 5๏ธโฃ')[1] if '### 5๏ธโฃ' in evaluator_response else evaluator_response[-500:]}
|
2309 |
-
|
2310 |
-
---
|
2311 |
-
*{'Gemini 2.5 Pro' if llm_system.use_gemini else '๊ธฐ๋ณธ LLM'} ์ฌ์ฉ | 4๊ฐ AI ํ๋ ฅ ์๋ฃ*"""
|
2312 |
-
|
2313 |
-
yield supervisor_text, researcher_text, executor_text, evaluator_text, "โ
์ต์ข
๋ณด๊ณ ์ ์์ฑ!"
|
2314 |
-
|
2315 |
-
except Exception as e:
|
2316 |
-
error_msg = f"โ ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}"
|
2317 |
-
yield "", "", "", "", error_msg
|
2318 |
-
|
2319 |
-
def clear_all():
|
2320 |
-
"""๋ชจ๋ ๋ด์ฉ ์ด๊ธฐํ"""
|
2321 |
-
global internal_history
|
2322 |
-
internal_history = []
|
2323 |
-
return "", "", "", "", "๐ ์ด๊ธฐํ๋์์ต๋๋ค."
|
2324 |
-
|
2325 |
-
# Gradio ์ธํฐํ์ด์ค
|
2326 |
-
css = """
|
2327 |
-
.gradio-container {
|
2328 |
-
font-family: 'Arial', sans-serif;
|
2329 |
-
}
|
2330 |
-
.supervisor-box textarea {
|
2331 |
-
border-left: 4px solid #667eea !important;
|
2332 |
-
padding-left: 10px !important;
|
2333 |
-
background-color: #f8f9ff !important;
|
2334 |
-
}
|
2335 |
-
.researcher-box textarea {
|
2336 |
-
border-left: 4px solid #10b981 !important;
|
2337 |
-
padding-left: 10px !important;
|
2338 |
-
background-color: #f0fdf4 !important;
|
2339 |
-
}
|
2340 |
-
.executor-box textarea {
|
2341 |
-
border-left: 4px solid #764ba2 !important;
|
2342 |
-
padding-left: 10px !important;
|
2343 |
-
background-color: #faf5ff !important;
|
2344 |
-
}
|
2345 |
-
.evaluator-box textarea {
|
2346 |
-
border-left: 4px solid #f59e0b !important;
|
2347 |
-
padding-left: 10px !important;
|
2348 |
-
background-color: #fffbeb !important;
|
2349 |
-
}
|
2350 |
-
"""
|
2351 |
-
|
2352 |
-
with gr.Blocks(title="ํ๋ ฅ์ LLM ์์คํ
", theme=gr.themes.Soft(), css=css) as app:
|
2353 |
-
gr.Markdown(
|
2354 |
-
f"""
|
2355 |
-
# ๐ค ํ๋ ฅ์ LLM ์์คํ
(4-AI ํ์
+ ํ๊ฐ์)
|
2356 |
-
"""
|
2357 |
-
)
|
2358 |
-
|
2359 |
-
# ์
๋ ฅ ์น์
|
2360 |
-
with gr.Row():
|
2361 |
-
with gr.Column():
|
2362 |
-
gr.Markdown("""
|
2363 |
-
## ๐ 4๊ฐ AI์ ํ๋ ฅ ์์คํ
|
2364 |
-
- **๊ฐ๋
์ AI**: ๊ฑฐ์์ ๋ถ์๊ณผ ์ ๋ต ์๋ฆฝ
|
2365 |
-
- **์กฐ์ฌ์ AI**: ์น ๊ฒ์๊ณผ ์ ๋ณด ์์ง/์ ๋ฆฌ
|
2366 |
-
- **์คํ์ AI**: ๊ตฌ์ฒด์ ๊ณํ ์๋ฆฝ๊ณผ ์คํ
|
2367 |
-
- **ํ๊ฐ์ AI**: ์ ์ฒด ๊ณผ์ ํ๊ฐ์ ๊ฐ์ ์ ์ ์
|
2368 |
-
|
2369 |
-
### ๐ ์ฃผ์ ๊ธฐ๋ฅ
|
2370 |
-
- 20๊ฐ ๊ฒ์ ๊ฒฐ๊ณผ์ ๋์์ด ๊ฒ์
|
2371 |
-
- ์ ๋ขฐ๋ ๊ธฐ๋ฐ ์ ๋ณด ํ๊ฐ
|
2372 |
-
- ์ค์๊ฐ ํ์
๊ณผ ํผ๋๋ฐฑ ๋ฐ์
|
2373 |
-
- ์ข
ํฉ์ ์ธ ํ์ง ํ๊ฐ
|
2374 |
-
""")
|
2375 |
-
|
2376 |
-
# LLM ์ ํ ์ต์
|
2377 |
-
llm_mode = gr.Radio(
|
2378 |
-
choices=["default", "commercial"],
|
2379 |
-
value="default",
|
2380 |
-
label="LLM ๋ชจ๋ ์ ํ",
|
2381 |
-
info="commercial์ ์ ํํ๋ฉด Gemini 2.5 Pro๋ฅผ ์ฌ์ฉํฉ๋๋ค"
|
2382 |
-
)
|
2383 |
-
|
2384 |
-
user_input = gr.Textbox(
|
2385 |
-
label="์ง๋ฌธ ์
๋ ฅ",
|
2386 |
-
placeholder="์: ๊ธฐ๊ณํ์ต ๋ชจ๋ธ์ ์ฑ๋ฅ์ ํฅ์์ํค๋ ๋ฐฉ๋ฒ์?",
|
2387 |
-
lines=3
|
2388 |
-
)
|
2389 |
-
|
2390 |
-
with gr.Row():
|
2391 |
-
submit_btn = gr.Button("๐ ๋ถ์ ์์", variant="primary", scale=2)
|
2392 |
-
clear_btn = gr.Button("๐๏ธ ์ด๊ธฐํ", scale=1)
|
2393 |
-
|
2394 |
-
status_text = gr.Textbox(
|
2395 |
-
label="์ํ",
|
2396 |
-
interactive=False,
|
2397 |
-
value="๋๊ธฐ ์ค...",
|
2398 |
-
max_lines=1
|
2399 |
-
)
|
2400 |
-
|
2401 |
-
# AI ์ถ๋ ฅ๋ค - 2x2 ๊ทธ๋ฆฌ๋
|
2402 |
-
with gr.Row():
|
2403 |
-
# ์๋จ ํ
|
2404 |
-
with gr.Column():
|
2405 |
-
gr.Markdown("### ๐ง ๊ฐ๋
์ AI (๊ฑฐ์์ ๋ถ์)")
|
2406 |
-
supervisor_output = gr.Textbox(
|
2407 |
-
label="",
|
2408 |
-
lines=15,
|
2409 |
-
max_lines=20,
|
2410 |
-
interactive=False,
|
2411 |
-
elem_classes=["supervisor-box"]
|
2412 |
-
)
|
2413 |
-
|
2414 |
-
with gr.Column():
|
2415 |
-
gr.Markdown("### ๐ ์กฐ์ฌ์ AI (์น ๊ฒ์ & ์ ๋ฆฌ)")
|
2416 |
-
researcher_output = gr.Textbox(
|
2417 |
-
label="",
|
2418 |
-
lines=15,
|
2419 |
-
max_lines=20,
|
2420 |
-
interactive=False,
|
2421 |
-
elem_classes=["researcher-box"]
|
2422 |
-
)
|
2423 |
-
|
2424 |
-
with gr.Row():
|
2425 |
-
# ํ๋จ ํ
|
2426 |
-
with gr.Column():
|
2427 |
-
gr.Markdown("### ๐๏ธ ์คํ์ AI (๋ฏธ์์ ๊ตฌํ)")
|
2428 |
-
executor_output = gr.Textbox(
|
2429 |
-
label="",
|
2430 |
-
lines=15,
|
2431 |
-
max_lines=20,
|
2432 |
-
interactive=False,
|
2433 |
-
elem_classes=["executor-box"]
|
2434 |
-
)
|
2435 |
-
|
2436 |
-
with gr.Column():
|
2437 |
-
gr.Markdown("### ๐ ํ๊ฐ์ AI (์ ์ฒด ํ๊ฐ)")
|
2438 |
-
evaluator_output = gr.Textbox(
|
2439 |
-
label="",
|
2440 |
-
lines=15,
|
2441 |
-
max_lines=20,
|
2442 |
-
interactive=False,
|
2443 |
-
elem_classes=["evaluator-box"]
|
2444 |
-
)
|
2445 |
-
|
2446 |
-
# ์์
|
2447 |
-
gr.Examples(
|
2448 |
-
examples=[
|
2449 |
-
"๊ธฐ๊ณํ์ต ๋ชจ๋ธ์ ์ฑ๋ฅ์ ํฅ์์ํค๋ ์ต์ ๋ฐฉ๋ฒ์?",
|
2450 |
-
"2024๋
ํจ๊ณผ์ ์ธ ํ๋ก์ ํธ ๊ด๋ฆฌ ๋๊ตฌ์ ์ ๋ต์?",
|
2451 |
-
"์ง์ ๊ฐ๋ฅํ ๋น์ฆ๋์ค ๋ชจ๋ธ์ ์ต์ ํธ๋ ๋๋?",
|
2452 |
-
"์ต์ ๋ฐ์ดํฐ ์๊ฐํ ๋๊ตฌ์ ๊ธฐ๋ฒ์?",
|
2453 |
-
"์๊ฒฉ ํ์ ์์ฐ์ฑ์ ๋์ด๋ ๊ฒ์ฆ๋ ๋ฐฉ๋ฒ์?"
|
2454 |
-
],
|
2455 |
-
inputs=user_input,
|
2456 |
-
label="๐ก ์์ ์ง๋ฌธ"
|
2457 |
-
)
|
2458 |
-
|
2459 |
-
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
2460 |
-
submit_btn.click(
|
2461 |
-
fn=process_query_streaming,
|
2462 |
-
inputs=[user_input, llm_mode],
|
2463 |
-
outputs=[supervisor_output, researcher_output, executor_output, evaluator_output, status_text]
|
2464 |
-
).then(
|
2465 |
-
fn=lambda: "",
|
2466 |
-
outputs=[user_input]
|
2467 |
-
)
|
2468 |
-
|
2469 |
-
user_input.submit(
|
2470 |
-
fn=process_query_streaming,
|
2471 |
-
inputs=[user_input, llm_mode],
|
2472 |
-
outputs=[supervisor_output, researcher_output, executor_output, evaluator_output, status_text]
|
2473 |
-
).then(
|
2474 |
-
fn=lambda: "",
|
2475 |
-
outputs=[user_input]
|
2476 |
-
)
|
2477 |
-
|
2478 |
-
clear_btn.click(
|
2479 |
-
fn=clear_all,
|
2480 |
-
outputs=[supervisor_output, researcher_output, executor_output, evaluator_output, status_text]
|
2481 |
-
)
|
2482 |
-
|
2483 |
-
|
2484 |
if __name__ == "__main__":
|
2485 |
app.queue() # ์คํธ๋ฆฌ๋ฐ์ ์ํ ํ ํ์ฑํ
|
2486 |
app.launch(
|
|
|
1236 |
)
|
1237 |
|
1238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1239 |
if __name__ == "__main__":
|
1240 |
app.queue() # ์คํธ๋ฆฌ๋ฐ์ ์ํ ํ ํ์ฑํ
|
1241 |
app.launch(
|