Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,9 @@ TEST_MODE = os.getenv("TEST_MODE", "false").lower() == "true"
|
|
38 |
# ์ ์ญ ๋ณ์
|
39 |
conversation_history = []
|
40 |
|
41 |
-
class
|
|
|
|
|
42 |
def __init__(self):
|
43 |
self.token = FRIENDLI_TOKEN
|
44 |
self.bapi_token = BAPI_TOKEN
|
@@ -50,15 +52,55 @@ class LLMCollaborativeSystem:
|
|
50 |
self.use_gemini = False
|
51 |
self.gemini_client = None
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
if self.test_mode:
|
54 |
logger.warning("ํ
์คํธ ๋ชจ๋๋ก ์คํ๋ฉ๋๋ค.")
|
55 |
-
if self.bapi_token == "YOUR_BRAVE_API_TOKEN":
|
56 |
-
logger.warning("Brave API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค.")
|
57 |
-
if self.gemini_api_key == "YOUR_GEMINI_API_KEY":
|
58 |
-
logger.warning("Gemini API ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค.")
|
59 |
|
60 |
def set_llm_mode(self, mode: str):
|
61 |
-
"""LLM ๋ชจ๋ ์ค์
|
62 |
if mode == "commercial" and GEMINI_AVAILABLE and self.gemini_api_key != "YOUR_GEMINI_API_KEY":
|
63 |
self.use_gemini = True
|
64 |
if not self.gemini_client:
|
@@ -67,7 +109,7 @@ class LLMCollaborativeSystem:
|
|
67 |
else:
|
68 |
self.use_gemini = False
|
69 |
logger.info("๊ธฐ๋ณธ LLM ๋ชจ๋๋ก ์ ํ๋์์ต๋๋ค.")
|
70 |
-
|
71 |
def create_headers(self):
|
72 |
"""API ํค๋ ์์ฑ"""
|
73 |
return {
|
@@ -83,323 +125,229 @@ class LLMCollaborativeSystem:
|
|
83 |
"X-Subscription-Token": self.bapi_token
|
84 |
}
|
85 |
|
86 |
-
def
|
87 |
-
"""
|
88 |
-
return f"""๋น์ ์
|
|
|
89 |
|
90 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
91 |
|
92 |
-
์ด ์ง๋ฌธ์ ๋ํด:
|
93 |
-
1. ์ ์ฒด์ ์ธ
|
94 |
-
2.
|
95 |
-
3.
|
|
|
96 |
|
97 |
-
|
98 |
-
[๊ฒ์ ํค์๋]: ํค์๋1, ํค์๋2, ํค์๋3, ํค์๋4, ํค์๋5"""
|
99 |
|
100 |
-
def
|
101 |
-
"""
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
for keyword, results in search_results.items():
|
106 |
-
search_summary += f"\n\n**{keyword}์ ๋ํ ๊ฒ์ ๊ฒฐ๊ณผ:**\n"
|
107 |
-
for i, result in enumerate(results[:10], 1): # ์์ 10๊ฐ๋ง ํ์
|
108 |
-
search_summary += f"{i}. {result.get('title', 'N/A')} (์ ๋ขฐ๋: {result.get('credibility_score', 0):.2f})\n"
|
109 |
-
search_summary += f" - {result.get('description', 'N/A')}\n"
|
110 |
-
search_summary += f" - ์ถ์ฒ: {result.get('url', 'N/A')}\n"
|
111 |
-
if result.get('published'):
|
112 |
-
search_summary += f" - ๊ฒ์์ผ: {result.get('published')}\n"
|
113 |
-
|
114 |
-
all_results.extend(results)
|
115 |
-
|
116 |
-
# ๋ชจ์ ๊ฐ์ง
|
117 |
-
contradictions = self.detect_contradictions(all_results)
|
118 |
-
contradiction_text = ""
|
119 |
-
if contradictions:
|
120 |
-
contradiction_text = "\n\n**๋ฐ๊ฒฌ๋ ์ ๋ณด ๋ชจ์:**\n"
|
121 |
-
for cont in contradictions[:3]: # ์ต๋ 3๊ฐ๋ง ํ์
|
122 |
-
contradiction_text += f"- {cont['type']}: {cont['source1']} vs {cont['source2']}\n"
|
123 |
-
|
124 |
-
return f"""๋น์ ์ ์ ๋ณด๋ฅผ ์กฐ์ฌํ๊ณ ์ ๋ฆฌํ๋ ์กฐ์ฌ์ AI์
๋๋ค.
|
125 |
|
126 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
127 |
|
128 |
-
|
129 |
-
{
|
130 |
|
131 |
-
|
132 |
-
{
|
133 |
-
{contradiction_text}
|
134 |
|
135 |
-
|
136 |
-
1.
|
137 |
-
2.
|
138 |
-
3.
|
139 |
-
4.
|
140 |
-
5.
|
141 |
-
6. ์ ๋ขฐ๋๊ฐ ๋ฎ์ ์ ๋ณด๋ ์ฃผ์ ํ์์ ํจ๊ป ํฌํจํ์ธ์"""
|
142 |
|
143 |
-
def
|
144 |
-
"""
|
145 |
-
return f"""๋น์ ์
|
|
|
146 |
|
147 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
148 |
|
149 |
-
|
150 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
-
|
153 |
-
1.
|
154 |
-
2.
|
155 |
-
3.
|
156 |
-
4.
|
|
|
157 |
|
158 |
-
def
|
159 |
-
"""
|
160 |
-
return f"""๋น์ ์
|
|
|
161 |
|
162 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
163 |
|
164 |
-
|
165 |
-
{
|
166 |
|
167 |
-
|
168 |
-
{
|
169 |
|
170 |
-
|
171 |
-
1.
|
172 |
-
2.
|
173 |
-
3.
|
174 |
-
4.
|
|
|
175 |
|
176 |
-
def
|
177 |
-
"""
|
178 |
-
return f"""๋น์ ์
|
|
|
179 |
|
180 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
181 |
|
182 |
-
|
183 |
-
{
|
184 |
|
185 |
-
|
186 |
-
{
|
187 |
|
188 |
-
|
189 |
-
{
|
190 |
|
191 |
-
|
192 |
-
1.
|
193 |
-
2.
|
194 |
-
3.
|
195 |
-
4.
|
196 |
-
5.
|
197 |
|
198 |
-
def
|
199 |
-
"""
|
200 |
-
|
201 |
-
|
202 |
-
evaluator_history = f"""
|
203 |
-
ํ๊ฐ์ AI์ ์ด์ ํ๊ฐ๋ค:
|
204 |
-
- ์กฐ์ฌ ๊ฒฐ๊ณผ ํ๊ฐ: {evaluator_responses[0] if len(evaluator_responses) > 0 else 'N/A'}
|
205 |
-
- ์ด๊ธฐ ๊ตฌํ ํ๊ฐ: {evaluator_responses[1] if len(evaluator_responses) > 1 else 'N/A'}
|
206 |
-
"""
|
207 |
-
|
208 |
-
return f"""๋น์ ์ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ๋ ํ๊ฐ์ AI์
๋๋ค.
|
209 |
|
210 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
211 |
|
212 |
-
|
213 |
-
-
|
214 |
-
-
|
215 |
-
-
|
|
|
216 |
|
217 |
-
|
218 |
-
{
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
2. **ํ๋ ฅ ํจ๊ณผ์ฑ**: AI ๊ฐ ํ๋ ฅ์ด ์ผ๋ง๋ ํจ๊ณผ์ ์ด์๋์ง ํ๊ฐํ์ธ์
|
227 |
-
3. **์ ๋ณด ํ์ฉ๋**: ์น ๊ฒ์ ์ ๋ณด๊ฐ ์ผ๋ง๋ ์ ํ์ฉ๋์๋์ง ํ๊ฐํ์ธ์
|
228 |
-
4. **๊ฐ์ ์ **: ํฅํ ๊ฐ์ ์ด ํ์ํ ๋ถ๋ถ์ ๊ตฌ์ฒด์ ์ผ๋ก ์ ์ํ์ธ์
|
229 |
-
5. **์ต์ข
ํ์ **: ์ ์ฒด ํ๋ก์ธ์ค์ ๋ํ ์ข
ํฉ ํ๊ฐ๋ฅผ ์ ์ํ์ธ์
|
230 |
|
231 |
-
|
232 |
|
233 |
-
def
|
234 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
keywords = []
|
236 |
|
237 |
-
|
238 |
-
keyword_match = re.search(r'\[๊ฒ์ ํค์๋\]:\s*(.+)', supervisor_response, re.IGNORECASE)
|
239 |
if keyword_match:
|
240 |
keyword_str = keyword_match.group(1)
|
241 |
keywords = [k.strip() for k in keyword_str.split(',') if k.strip()]
|
242 |
|
243 |
-
# ํค์๋๊ฐ ์์ผ๋ฉด ๊ธฐ๋ณธ ํค์๋ ์์ฑ
|
244 |
if not keywords:
|
245 |
-
keywords = ["best practices", "implementation
|
246 |
|
247 |
-
return keywords[:7]
|
248 |
-
|
249 |
-
def generate_synonyms(self, keyword: str) -> List[str]:
|
250 |
-
"""ํค์๋์ ๋์์ด/์ ์ฌ์ด ์์ฑ"""
|
251 |
-
synonyms = {
|
252 |
-
"optimization": ["improvement", "enhancement", "efficiency", "tuning"],
|
253 |
-
"performance": ["speed", "efficiency", "throughput", "latency"],
|
254 |
-
"strategy": ["approach", "method", "technique", "plan"],
|
255 |
-
"implementation": ["deployment", "execution", "development", "integration"],
|
256 |
-
"analysis": ["evaluation", "assessment", "study", "research"],
|
257 |
-
"management": ["administration", "governance", "control", "supervision"],
|
258 |
-
"best practices": ["proven methods", "industry standards", "guidelines", "recommendations"],
|
259 |
-
"trends": ["developments", "innovations", "emerging", "future"],
|
260 |
-
"machine learning": ["ML", "AI", "deep learning", "neural networks"],
|
261 |
-
"ํ๋ก์ ํธ": ["project", "์ฌ์
", "์
๋ฌด", "์์
"]
|
262 |
-
}
|
263 |
-
|
264 |
-
# ํค์๋ ์ ๊ทํ
|
265 |
-
keyword_lower = keyword.lower()
|
266 |
-
|
267 |
-
# ์ง์ ๋งค์นญ๋๋ ๋์์ด๊ฐ ์์ผ๋ฉด ๋ฐํ
|
268 |
-
if keyword_lower in synonyms:
|
269 |
-
return synonyms[keyword_lower][:2] # ์ต๋ 2๊ฐ
|
270 |
-
|
271 |
-
# ๋ถ๋ถ ๋งค์นญ ํ์ธ
|
272 |
-
for key, values in synonyms.items():
|
273 |
-
if key in keyword_lower or keyword_lower in key:
|
274 |
-
return values[:2]
|
275 |
-
|
276 |
-
# ๋์์ด๊ฐ ์์ผ๋ฉด ๋น ๋ฆฌ์คํธ
|
277 |
-
return []
|
278 |
|
279 |
def calculate_credibility_score(self, result: Dict) -> float:
|
280 |
-
"""๊ฒ์
|
281 |
-
score = 0.5
|
282 |
-
|
283 |
url = result.get('url', '')
|
284 |
-
title = result.get('title', '')
|
285 |
-
description = result.get('description', '')
|
286 |
|
287 |
-
|
288 |
-
|
289 |
-
'.edu', '.gov', '.org', 'wikipedia.org', 'nature.com',
|
290 |
-
'sciencedirect.com', 'ieee.org', 'acm.org', 'springer.com',
|
291 |
-
'harvard.edu', 'mit.edu', 'stanford.edu', 'github.com'
|
292 |
-
]
|
293 |
|
294 |
for domain in trusted_domains:
|
295 |
if domain in url:
|
296 |
score += 0.2
|
297 |
break
|
298 |
|
299 |
-
# HTTPS ์ฌ์ฉ ์ฌ๋ถ
|
300 |
if url.startswith('https://'):
|
301 |
score += 0.1
|
302 |
|
303 |
-
|
304 |
-
if len(title) > 20:
|
305 |
score += 0.05
|
306 |
-
if len(description) > 50:
|
307 |
score += 0.05
|
308 |
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
score -= 0.3
|
313 |
|
314 |
-
|
315 |
-
if any(year in description for year in ['2024', '2023', '2022']):
|
316 |
-
score += 0.1
|
317 |
-
|
318 |
-
return max(0, min(1, score)) # 0-1 ๋ฒ์๋ก ์ ํ
|
319 |
-
|
320 |
-
def fetch_url_content(self, url: str, max_length: int = 2000) -> str:
|
321 |
-
"""URL์์ ์ฝํ
์ธ ์ถ์ถ"""
|
322 |
-
try:
|
323 |
-
# User-Agent ์ค์
|
324 |
-
headers = {
|
325 |
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
326 |
-
}
|
327 |
-
|
328 |
-
req = urllib.request.Request(url, headers=headers)
|
329 |
-
|
330 |
-
with urllib.request.urlopen(req, timeout=5) as response:
|
331 |
-
html = response.read().decode('utf-8', errors='ignore')
|
332 |
-
|
333 |
-
soup = BeautifulSoup(html, 'html.parser')
|
334 |
-
|
335 |
-
# ์คํฌ๋ฆฝํธ์ ์คํ์ผ ์ ๊ฑฐ
|
336 |
-
for script in soup(["script", "style"]):
|
337 |
-
script.decompose()
|
338 |
-
|
339 |
-
# ๋ณธ๋ฌธ ํ
์คํธ ์ถ์ถ
|
340 |
-
text = soup.get_text()
|
341 |
-
|
342 |
-
# ๊ณต๋ฐฑ ์ ๋ฆฌ
|
343 |
-
lines = (line.strip() for line in text.splitlines())
|
344 |
-
chunks = (phrase.strip() for line in lines for phrase in line.split(" "))
|
345 |
-
text = ' '.join(chunk for chunk in chunks if chunk)
|
346 |
-
|
347 |
-
# ๊ธธ์ด ์ ํ
|
348 |
-
if len(text) > max_length:
|
349 |
-
text = text[:max_length] + "..."
|
350 |
-
|
351 |
-
return text
|
352 |
-
|
353 |
-
except Exception as e:
|
354 |
-
logger.error(f"URL ์ฝํ
์ธ ๊ฐ์ ธ์ค๊ธฐ ์คํจ {url}: {str(e)}")
|
355 |
-
return ""
|
356 |
-
|
357 |
-
def detect_contradictions(self, results: List[Dict]) -> List[Dict]:
|
358 |
-
"""๊ฒ์ ๊ฒฐ๊ณผ ๊ฐ ๋ชจ์ ๊ฐ์ง"""
|
359 |
-
contradictions = []
|
360 |
-
|
361 |
-
# ๊ฐ๋จํ ๋ชจ์ ๊ฐ์ง ํจํด
|
362 |
-
opposite_pairs = [
|
363 |
-
("increase", "decrease"),
|
364 |
-
("improve", "worsen"),
|
365 |
-
("effective", "ineffective"),
|
366 |
-
("success", "failure"),
|
367 |
-
("benefit", "harm"),
|
368 |
-
("positive", "negative"),
|
369 |
-
("growth", "decline")
|
370 |
-
]
|
371 |
-
|
372 |
-
# ๊ฒฐ๊ณผ๋ค์ ๋น๊ต
|
373 |
-
for i in range(len(results)):
|
374 |
-
for j in range(i + 1, len(results)):
|
375 |
-
desc1 = results[i].get('description', '').lower()
|
376 |
-
desc2 = results[j].get('description', '').lower()
|
377 |
-
|
378 |
-
# ๋ฐ๋ ๊ฐ๋
์ด ํฌํจ๋์ด ์๋์ง ํ์ธ
|
379 |
-
for word1, word2 in opposite_pairs:
|
380 |
-
if (word1 in desc1 and word2 in desc2) or (word2 in desc1 and word1 in desc2):
|
381 |
-
# ๊ฐ์ ์ฃผ์ ์ ๋ํด ๋ฐ๋ ์๊ฒฌ์ธ์ง ํ์ธ
|
382 |
-
common_words = set(desc1.split()) & set(desc2.split())
|
383 |
-
if len(common_words) > 5: # ๊ณตํต ๋จ์ด๊ฐ 5๊ฐ ์ด์์ด๋ฉด ๊ฐ์ ์ฃผ์ ๋ก ๊ฐ์ฃผ
|
384 |
-
contradictions.append({
|
385 |
-
'source1': results[i]['url'],
|
386 |
-
'source2': results[j]['url'],
|
387 |
-
'type': f"{word1} vs {word2}",
|
388 |
-
'desc1': results[i]['description'][:100],
|
389 |
-
'desc2': results[j]['description'][:100]
|
390 |
-
})
|
391 |
-
|
392 |
-
return contradictions
|
393 |
|
394 |
def brave_search(self, query: str) -> List[Dict]:
|
395 |
"""Brave Search API ํธ์ถ"""
|
396 |
if self.test_mode or self.bapi_token == "YOUR_BRAVE_API_TOKEN":
|
397 |
-
# ํ
์คํธ ๋ชจ๋์์๋ ์๋ฎฌ๋ ์ด์
๋ ๊ฒฐ๊ณผ ๋ฐํ
|
398 |
test_results = []
|
399 |
for i in range(5):
|
400 |
test_results.append({
|
401 |
-
"title": f"
|
402 |
-
"description": f"Comprehensive guide on
|
403 |
"url": f"https://example{i+1}.com/{query.replace(' ', '-')}",
|
404 |
"credibility_score": 0.7 + (i * 0.05)
|
405 |
})
|
@@ -408,9 +356,8 @@ class LLMCollaborativeSystem:
|
|
408 |
try:
|
409 |
params = {
|
410 |
"q": query,
|
411 |
-
"count":
|
412 |
-
"safesearch": "moderate"
|
413 |
-
"freshness": "pw" # Past week for recent results
|
414 |
}
|
415 |
|
416 |
response = requests.get(
|
@@ -423,18 +370,15 @@ class LLMCollaborativeSystem:
|
|
423 |
if response.status_code == 200:
|
424 |
data = response.json()
|
425 |
results = []
|
426 |
-
for item in data.get("web", {}).get("results", [])
|
427 |
result = {
|
428 |
"title": item.get("title", ""),
|
429 |
"description": item.get("description", ""),
|
430 |
"url": item.get("url", ""),
|
431 |
-
"
|
432 |
}
|
433 |
-
# ์ ๋ขฐ๋ ์ ์ ๊ณ์ฐ
|
434 |
-
result["credibility_score"] = self.calculate_credibility_score(result)
|
435 |
results.append(result)
|
436 |
|
437 |
-
# ์ ๋ขฐ๋ ์ ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ
|
438 |
results.sort(key=lambda x: x['credibility_score'], reverse=True)
|
439 |
return results
|
440 |
else:
|
@@ -445,14 +389,6 @@ class LLMCollaborativeSystem:
|
|
445 |
logger.error(f"Brave ๊ฒ์ ์ค ์ค๋ฅ: {str(e)}")
|
446 |
return []
|
447 |
|
448 |
-
def simulate_streaming(self, text: str, role: str) -> Generator[str, None, None]:
|
449 |
-
"""ํ
์คํธ ๋ชจ๋์์ ์คํธ๋ฆฌ๋ฐ ์๋ฎฌ๋ ์ด์
"""
|
450 |
-
words = text.split()
|
451 |
-
for i in range(0, len(words), 3):
|
452 |
-
chunk = " ".join(words[i:i+3])
|
453 |
-
yield chunk + " "
|
454 |
-
time.sleep(0.05)
|
455 |
-
|
456 |
def call_gemini_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
457 |
"""Gemini API ์คํธ๋ฆฌ๋ฐ ํธ์ถ"""
|
458 |
if not self.gemini_client:
|
@@ -460,28 +396,7 @@ class LLMCollaborativeSystem:
|
|
460 |
return
|
461 |
|
462 |
try:
|
463 |
-
# ์์คํ
ํ๋กฌํํธ ์ค์
|
464 |
-
system_prompts = {
|
465 |
-
"supervisor": "๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.",
|
466 |
-
"researcher": "๋น์ ์ ์ ๋ณด๋ฅผ ์กฐ์ฌํ๊ณ ์ฒด๊ณ์ ์ผ๋ก ์ ๋ฆฌํ๋ ์กฐ์ฌ์ AI์
๋๋ค.",
|
467 |
-
"executor": "๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค.",
|
468 |
-
"evaluator": "๋น์ ์ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ๋ ํ๊ฐ์ AI์
๋๋ค."
|
469 |
-
}
|
470 |
-
|
471 |
-
# Gemini ํ์์ contents ๊ตฌ์ฑ
|
472 |
contents = []
|
473 |
-
|
474 |
-
# ์์คํ
ํ๋กฌํํธ๋ฅผ ์ฒซ ๋ฒ์งธ ์ฌ์ฉ์ ๋ฉ์์ง๋ก ์ถ๊ฐ
|
475 |
-
contents.append(types.Content(
|
476 |
-
role="user",
|
477 |
-
parts=[types.Part.from_text(text=system_prompts.get(role, ""))]
|
478 |
-
))
|
479 |
-
contents.append(types.Content(
|
480 |
-
role="model",
|
481 |
-
parts=[types.Part.from_text(text="๋ค, ์ดํดํ์ต๋๋ค. ์ ์ญํ ์ ์ํํ๊ฒ ์ต๋๋ค.")]
|
482 |
-
))
|
483 |
-
|
484 |
-
# ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
|
485 |
for msg in messages:
|
486 |
if msg["role"] == "user":
|
487 |
contents.append(types.Content(
|
@@ -489,7 +404,6 @@ class LLMCollaborativeSystem:
|
|
489 |
parts=[types.Part.from_text(text=msg["content"])]
|
490 |
))
|
491 |
|
492 |
-
# GenerateContentConfig ์ค์
|
493 |
generate_content_config = types.GenerateContentConfig(
|
494 |
temperature=0.7,
|
495 |
top_p=0.8,
|
@@ -497,7 +411,6 @@ class LLMCollaborativeSystem:
|
|
497 |
response_mime_type="text/plain"
|
498 |
)
|
499 |
|
500 |
-
# ์คํธ๋ฆฌ๋ฐ ์์ฑ
|
501 |
for chunk in self.gemini_client.models.generate_content_stream(
|
502 |
model="gemini-2.5-pro",
|
503 |
contents=contents,
|
@@ -512,453 +425,31 @@ class LLMCollaborativeSystem:
|
|
512 |
|
513 |
def call_llm_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
514 |
"""์คํธ๋ฆฌ๋ฐ LLM API ํธ์ถ"""
|
515 |
-
|
516 |
-
# Gemini ๋ชจ๋์ธ ๊ฒฝ์ฐ
|
517 |
if self.use_gemini:
|
518 |
yield from self.call_gemini_streaming(messages, role)
|
519 |
return
|
520 |
|
521 |
-
# ํ
์คํธ ๋ชจ๋
|
522 |
if self.test_mode:
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
1. **ํต์ฌ ๊ฐ๋
ํ์
**
|
528 |
-
- ์ง๋ฌธ์ ๋ณธ์ง์ ์์๋ฅผ ์ฌ์ธต ๋ถ์ํฉ๋๋ค
|
529 |
-
- ๊ด๋ จ๋ ์ฃผ์ ์ด๋ก ๊ณผ ์์น์ ๊ฒํ ํฉ๋๋ค
|
530 |
-
- ๋ค์ํ ๊ด์ ์์์ ์ ๊ทผ ๋ฐฉ๋ฒ์ ๊ณ ๋ คํฉ๋๋ค
|
531 |
-
|
532 |
-
2. **์ ๋ต์ ์ ๊ทผ ๋ฐฉํฅ**
|
533 |
-
- ์ฒด๊ณ์ ์ด๊ณ ๋จ๊ณ๋ณ ํด๊ฒฐ ๋ฐฉ์์ ์๋ฆฝํฉ๋๋ค
|
534 |
-
- ์ฅ๋จ๊ธฐ ๋ชฉํ๋ฅผ ๋ช
ํํ ์ค์ ํฉ๋๋ค
|
535 |
-
- ๋ฆฌ์คํฌ ์์ธ๊ณผ ๋์ ๋ฐฉ์์ ๋ง๋ จํฉ๋๋ค
|
536 |
-
|
537 |
-
3. **๊ธฐ๋ ํจ๊ณผ์ ๊ณผ์ **
|
538 |
-
- ์์๋๋ ๊ธ์ ์ ์ฑ๊ณผ๋ฅผ ๋ถ์ํฉ๋๋ค
|
539 |
-
- ์ ์ฌ์ ๋์ ๊ณผ์ ๋ฅผ ์๋ณํฉ๋๋ค
|
540 |
-
- ์ง์๊ฐ๋ฅํ ๋ฐ์ ๋ฐฉํฅ์ ์ ์ํฉ๋๋ค
|
541 |
-
|
542 |
-
[๊ฒ์ ํค์๋]: machine learning optimization, performance improvement strategies, model efficiency techniques, hyperparameter tuning best practices, latest ML trends 2024""",
|
543 |
-
|
544 |
-
"researcher": """์กฐ์ฌ ๊ฒฐ๊ณผ๋ฅผ ์ข
ํฉํ์ฌ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ฆฌํ์ต๋๋ค.
|
545 |
-
|
546 |
-
**1. Machine Learning Optimization (์ ๋ขฐ๋ ๋์)**
|
547 |
-
- ์ต์ ์ฐ๊ตฌ์ ๋ฐ๋ฅด๋ฉด ๋ชจ๋ธ ์ต์ ํ์ ํต์ฌ์ ์ํคํ
์ฒ ์ค๊ณ์ ํ๋ จ ์ ๋ต์ ๊ท ํ์
๋๋ค (์ ๋ขฐ๋: 0.85)
|
548 |
-
- AutoML ๋๊ตฌ๋ค์ด ํ์ดํผํ๋ผ๋ฏธํฐ ํ๋์ ์๋ํํ์ฌ ํจ์จ์ฑ์ ํฌ๊ฒ ํฅ์์ํต๋๋ค (์ ๋ขฐ๋: 0.82)
|
549 |
-
- ์ถ์ฒ: ML Conference 2024 (https://mlconf2024.org), Google Research (https://research.google)
|
550 |
-
|
551 |
-
**2. Performance Improvement Strategies (์ ๋ขฐ๋ ๋์)**
|
552 |
-
- ๋ฐ์ดํฐ ํ์ง ๊ฐ์ ์ด ๋ชจ๋ธ ์ฑ๋ฅ ํฅ์์ 80%๋ฅผ ์ฐจ์งํ๋ค๋ ์ฐ๊ตฌ ๊ฒฐ๊ณผ (์ ๋ขฐ๋: 0.90)
|
553 |
-
- ์์๋ธ ๊ธฐ๋ฒ๊ณผ ์ ์ดํ์ต์ด ์ฃผ์ ์ฑ๋ฅ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ์
์ฆ๋จ (์ ๋ขฐ๋: 0.78)
|
554 |
-
- ์ถ์ฒ: Stanford AI Lab (https://ai.stanford.edu), MIT CSAIL (https://csail.mit.edu)
|
555 |
-
|
556 |
-
**3. Model Efficiency Techniques (์ ๋ขฐ๋ ์ค๊ฐ)**
|
557 |
-
- ๋ชจ๋ธ ๊ฒฝ๋ํ(Pruning, Quantization)๋ก ์ถ๋ก ์๋ 10๋ฐฐ ํฅ์ ๊ฐ๋ฅ (์ ๋ขฐ๋: 0.75)
|
558 |
-
- Knowledge Distillation์ผ๋ก ๋ชจ๋ธ ํฌ๊ธฐ 90% ๊ฐ์, ์ฑ๋ฅ ์ ์ง (์ ๋ขฐ๋: 0.72)
|
559 |
-
- ์ถ์ฒ: ArXiv ๋
ผ๋ฌธ (https://arxiv.org/abs/2023.xxxxx)
|
560 |
-
|
561 |
-
**4. ์ค์ ์ ์ฉ ์ฌ๋ก (์ ๋ขฐ๋ ๋์)**
|
562 |
-
- Netflix: ์ถ์ฒ ์์คํ
๊ฐ์ ์ผ๋ก ์ฌ์ฉ์ ๋ง์กฑ๋ 35% ํฅ์ (์ ๋ขฐ๋: 0.88)
|
563 |
-
- Tesla: ์ค์๊ฐ ๊ฐ์ฒด ์ธ์ ์๋ 50% ๊ฐ์ (์ ๋ขฐ๋: 0.80)
|
564 |
-
- OpenAI: GPT ๋ชจ๋ธ ํจ์จ์ฑ ๊ฐ์ ์ผ๋ก ๋น์ฉ 70% ์ ๊ฐ (์ ๋ขฐ๋: 0.85)
|
565 |
-
|
566 |
-
**ํต์ฌ ์ธ์ฌ์ดํธ:**
|
567 |
-
- ์ต์ ํธ๋ ๋๋ ํจ์จ์ฑ๊ณผ ์ฑ๋ฅ์ ๊ท ํ์ ์ด์
|
568 |
-
- 2024๋
๋ค์ด Sparse Models์ MoE(Mixture of Experts) ๊ธฐ๋ฒ์ด ๋ถ์
|
569 |
-
- ์ค๋ฌด ์ ์ฉ ์ ๋จ๊ณ๋ณ ๊ฒ์ฆ์ด ์ฑ๊ณต์ ํต์ฌ""",
|
570 |
-
|
571 |
-
"supervisor_execution": """์กฐ์ฌ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ์คํ์ AI์๊ฒ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌ์ฒด์ ์ผ๋ก ์ง์ํฉ๋๋ค.
|
572 |
-
|
573 |
-
**1๋จ๊ณ: ํ์ฌ ๋ชจ๋ธ ์ง๋จ (1์ฃผ์ฐจ)**
|
574 |
-
- ์กฐ์ฌ๋ ๋ฒค์น๋งํฌ ๊ธฐ์ค์ผ๋ก ํ์ฌ ๋ชจ๋ธ ์ฑ๋ฅ ํ๊ฐ
|
575 |
-
- Netflix ์ฌ๋ก๋ฅผ ์ฐธ๊ณ ํ์ฌ ์ฃผ์ ๋ณ๋ชฉ ์ง์ ์๋ณ
|
576 |
-
- AutoML ๋๊ตฌ๋ฅผ ํ์ฉํ ์ด๊ธฐ ์ต์ ํ ๊ฐ๋ฅ์ฑ ํ์
|
577 |
-
|
578 |
-
**2๋จ๊ณ: ๋ฐ์ดํฐ ํ์ง ๊ฐ์ (2-3์ฃผ์ฐจ)**
|
579 |
-
- ์กฐ์ฌ ๊ฒฐ๊ณผ์ "80% ๊ท์น"์ ๋ฐ๋ผ ๋ฐ์ดํฐ ์ ์ ์ฐ์ ์คํ
|
580 |
-
- ๋ฐ์ดํฐ ์ฆ๊ฐ ๊ธฐ๋ฒ ์ ์ฉ (์กฐ์ฌ๋ ์ต์ ๊ธฐ๋ฒ ํ์ฉ)
|
581 |
-
- A/B ํ
์คํธ๋ก ๊ฐ์ ํจ๊ณผ ์ธก์
|
582 |
-
|
583 |
-
**3๋จ๊ณ: ๋ชจ๋ธ ์ต์ ํ ๊ตฌํ (4-6์ฃผ์ฐจ)**
|
584 |
-
- Knowledge Distillation ์ ์ฉํ์ฌ ๋ชจ๋ธ ๊ฒฝ๋ํ
|
585 |
-
- ์กฐ์ฌ๋ Pruning ๊ธฐ๋ฒ์ผ๋ก ์ถ๋ก ์๋ ๊ฐ์
|
586 |
-
- Tesla ์ฌ๋ก์ ์ค์๊ฐ ์ฒ๋ฆฌ ์ต์ ํ ๊ธฐ๋ฒ ๋ฒค์น๋งํน
|
587 |
-
|
588 |
-
**4๋จ๊ณ: ์ฑ๊ณผ ๊ฒ์ฆ ๋ฐ ๋ฐฐํฌ (7-8์ฃผ์ฐจ)**
|
589 |
-
- OpenAI ์ฌ๋ก์ ๋น์ฉ ์ ๊ฐ ์งํ ์ ์ฉ
|
590 |
-
- ์กฐ์ฌ๋ ์ฑ๋ฅ ์งํ๋ก ๊ฐ์ ์จ ์ธก์
|
591 |
-
- ๋จ๊ณ์ ๋ฐฐํฌ ์ ๋ต ์๋ฆฝ""",
|
592 |
-
|
593 |
-
"executor": """๊ฐ๋
์์ ์ง์์ ์กฐ์ฌ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ฒด์ ์ธ ์คํ ๊ณํ์ ์๋ฆฝํฉ๋๋ค.
|
594 |
-
|
595 |
-
**1๋จ๊ณ: ํ์ฌ ๋ชจ๋ธ ์ง๋จ (1์ฃผ์ฐจ)**
|
596 |
-
- ์์์ผ-ํ์์ผ: MLflow๋ฅผ ์ฌ์ฉํ ํ์ฌ ๋ชจ๋ธ ๋ฉํธ๋ฆญ ์์ง
|
597 |
-
* ์กฐ์ฌ ๊ฒฐ๊ณผ ์ฐธ๊ณ : Netflix๊ฐ ์ฌ์ฉํ ํต์ฌ ์งํ (์ ํ๋, ์ง์ฐ์๊ฐ, ์ฒ๋ฆฌ๋)
|
598 |
-
- ์์์ผ-๋ชฉ์์ผ: AutoML ๋๊ตฌ (Optuna, Ray Tune) ์ค์ ๋ฐ ์ด๊ธฐ ์คํ
|
599 |
-
* ์กฐ์ฌ๋ best practice์ ๋ฐ๋ผ search space ์ ์
|
600 |
-
- ๊ธ์์ผ: ์ง๋จ ๋ณด๊ณ ์ ์์ฑ ๋ฐ ๊ฐ์ ์ฐ์ ์์ ๊ฒฐ์
|
601 |
-
|
602 |
-
**2๋จ๊ณ: ๋ฐ์ดํฐ ํ์ง ๊ฐ์ (2-3์ฃผ์ฐจ)**
|
603 |
-
- ๋ฐ์ดํฐ ์ ์ ํ์ดํ๋ผ์ธ ๊ตฌ์ถ
|
604 |
-
* ์กฐ์ฌ ๊ฒฐ๊ณผ์ "80% ๊ท์น" ์ ์ฉ: ๋๋ฝ๊ฐ, ์ด์์น, ๋ ์ด๋ธ ์ค๋ฅ ์ฒ๋ฆฌ
|
605 |
-
* ์ฝ๋ ์์: `data_quality_pipeline.py` ๊ตฌํ
|
606 |
-
- ๋ฐ์ดํฐ ์ฆ๊ฐ ๊ตฌํ
|
607 |
-
* ์ต์ ๊ธฐ๋ฒ ์ ์ฉ: MixUp, CutMix, AutoAugment
|
608 |
-
* ๊ฒ์ฆ ๋ฐ์ดํฐ์
์ผ๋ก ํจ๊ณผ ์ธก์ (๋ชฉํ: 15% ์ฑ๋ฅ ํฅ์)
|
609 |
-
|
610 |
-
**3๋จ๊ณ: ๋ชจ๋ธ ์ต์ ํ ๊ตฌํ (4-6์ฃผ์ฐจ)**
|
611 |
-
- Knowledge Distillation ๊ตฌํ
|
612 |
-
* Teacher ๋ชจ๋ธ: ํ์ฌ ๋๊ท๋ชจ ๋ชจ๋ธ
|
613 |
-
* Student ๋ชจ๋ธ: 90% ์์ ํฌ๊ธฐ ๋ชฉํ (์กฐ์ฌ ๊ฒฐ๊ณผ ๊ธฐ๋ฐ)
|
614 |
-
* ๊ตฌํ ํ๋ ์์ํฌ: PyTorch/TensorFlow""",
|
615 |
-
|
616 |
-
"supervisor_review": """์คํ์ AI์ ๊ณํ์ ๊ฒํ ํ ๊ฒฐ๊ณผ, ์กฐ์ฌ ๋ด์ฉ์ด ์ ๋ฐ์๋์์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ ๊ฐ์ ์ฌํญ์ ์ ์ํฉ๋๋ค.
|
617 |
-
|
618 |
-
**๊ฐ์ **
|
619 |
-
- ์กฐ์ฌ๋ ์ฌ๋ก๋ค(Netflix, Tesla, OpenAI)์ด ๊ฐ ๋จ๊ณ์ ์ ์ ํ ํ์ฉ๋จ
|
620 |
-
- ๊ตฌ์ฒด์ ์ธ ๋๊ตฌ์ ๊ธฐ๋ฒ์ด ๋ช
์๋์ด ์คํ ๊ฐ๋ฅ์ฑ์ด ๋์
|
621 |
-
- ์ธก์ ๊ฐ๋ฅํ ๋ชฉํ๊ฐ ์กฐ์ฌ ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ค์ ๋จ
|
622 |
-
|
623 |
-
**๊ฐ์ ํ์์ฌํญ**
|
624 |
-
1. **๋ฆฌ์คํฌ ๊ด๋ฆฌ ๊ฐํ**
|
625 |
-
- ๊ฐ ๋จ๊ณ๋ณ ์คํจ ์๋๋ฆฌ์ค์ ๋์ ๋ฐฉ์ ์ถ๊ฐ ํ์
|
626 |
-
- ๊ธฐ์ ์ ๋ฌธ์ ๋ฐ์ ์ ๋ฐฑ์
๊ณํ ์๋ฆฝ
|
627 |
-
|
628 |
-
2. **๋น์ฉ ๋ถ์ ๊ตฌ์ฒดํ**
|
629 |
-
- OpenAI ์ฌ๋ก์ 70% ์ ๊ฐ์ ์ํ ๊ตฌ์ฒด์ ์ธ ๋น์ฉ ๊ณ์ฐ
|
630 |
-
- ROI ๋ถ์ ๋ฐ ํฌ์ ๋๋น ํจ๊ณผ ์ธก์ ๋ฐฉ๋ฒ
|
631 |
-
|
632 |
-
**์ถ๊ฐ ๊ถ์ฅ์ฌํญ**
|
633 |
-
- ์ต์ ์ฐ๊ตฌ ๋ํฅ ๋ชจ๋ํฐ๋ง ์ฒด๊ณ ๊ตฌ์ถ
|
634 |
-
- ๊ฒฝ์์ฌ ๋ฒค์น๋งํน์ ์ํ ์ ๊ธฐ์ ์ธ ์กฐ์ฌ ํ๋ก์ธ์ค""",
|
635 |
-
|
636 |
-
"executor_final": """๊ฐ๋
์ AI์ ํผ๋๋ฐฑ์ ์์ ํ ๋ฐ์ํ์ฌ ์ต์ข
์คํ ๋ณด๊ณ ์๋ฅผ ์์ฑํฉ๋๋ค.
|
637 |
-
|
638 |
-
# ๐ฏ ๊ธฐ๊ณํ์ต ๋ชจ๋ธ ์ฑ๋ฅ ํฅ์ ์ต์ข
์คํ ๋ณด๊ณ ์
|
639 |
-
|
640 |
-
## ๐ Executive Summary
|
641 |
-
|
642 |
-
๋ณธ ๋ณด๊ณ ์๋ ์น ๊ฒ์์ ํตํด ์์ง๋ ์ต์ ์ฌ๋ก์ ๊ฐ๋
์ AI์ ์ ๋ต์ ์ง์นจ์ ๋ฐํ์ผ๋ก, 8์ฃผ๊ฐ์ ์ฒด๊ณ์ ์ธ ๋ชจ๋ธ ์ต์ ํ ํ๋ก์ ํธ๋ฅผ ์ ์ํฉ๋๋ค.
|
643 |
-
|
644 |
-
### ๐ฏ ๋ชฉํ ๋ฌ์ฑ ์งํ
|
645 |
-
|
646 |
-
| ์งํ | ํ์ฌ | ๋ชฉํ | ๊ฐ์ ์จ |
|
647 |
-
|------|------|------|--------|
|
648 |
-
| ๋ชจ๋ธ ํฌ๊ธฐ | 2.5GB | 250MB | 90% ๊ฐ์ |
|
649 |
-
| ์ถ๋ก ์๋ | 45ms | 4.5ms | 10๋ฐฐ ํฅ์ |
|
650 |
-
| ์ด์ ๋น์ฉ | $2,000/์ | $600/์ | 70% ์ ๊ฐ |
|
651 |
-
| ์ ํ๋ | 92% | 90.5% | 1.5% ์์ค |
|
652 |
-
|
653 |
-
## ๐ 1๋จ๊ณ: ํ์ฌ ๋ชจ๋ธ ์ง๋จ ๋ฐ ๋ฒ ์ด์ค๋ผ์ธ ์ค์ (1์ฃผ์ฐจ)
|
654 |
-
|
655 |
-
### ์คํ ๊ณํ
|
656 |
-
|
657 |
-
**์-ํ์์ผ: ์ฑ๋ฅ ๋ฉํธ๋ฆญ ์์ง**
|
658 |
-
- MLflow๋ฅผ ํตํ ํ์ฌ ๋ชจ๋ธ ์ ์ฒด ๋ถ์
|
659 |
-
- Netflix ์ฌ๋ก ๊ธฐ๋ฐ ํต์ฌ ์งํ:
|
660 |
-
- ์ ํ๋: 92%
|
661 |
-
- ์ง์ฐ์๊ฐ: 45ms
|
662 |
-
- ์ฒ๋ฆฌ๋: 1,000 req/s
|
663 |
-
- GPU ๋ฉ๋ชจ๋ฆฌ: 8GB
|
664 |
-
|
665 |
-
**์-๋ชฉ์์ผ: AutoML ์ด๊ธฐ ํ์**
|
666 |
-
```python
|
667 |
-
# Optuna ํ์ดํผํ๋ผ๋ฏธํฐ ์ต์ ํ ์ค์
|
668 |
-
study = optuna.create_study(direction="maximize")
|
669 |
-
study.optimize(objective, n_trials=200)
|
670 |
-
|
671 |
-
# Ray Tune ๋ถ์ฐ ํ์ต ์ค์
|
672 |
-
analysis = tune.run(
|
673 |
-
train_model,
|
674 |
-
config=search_space,
|
675 |
-
num_samples=50,
|
676 |
-
resources_per_trial={"gpu": 1}
|
677 |
-
)
|
678 |
-
```
|
679 |
-
|
680 |
-
### ์์ ์ฐ์ถ๋ฌผ
|
681 |
-
- โ
์์ธ ์ฑ๋ฅ ๋ฒ ์ด์ค๋ผ์ธ ๋ฌธ์
|
682 |
-
- โ
๊ฐ์ ๊ธฐํ ์ฐ์ ์์ ๋งคํธ๋ฆญ์ค
|
683 |
-
- โ
๋ฆฌ์คํฌ ๋ ์ง์คํฐ
|
684 |
-
|
685 |
-
## ๐ 2๋จ๊ณ: ๋ฐ์ดํฐ ํ์ง ๊ฐ์ (2-3์ฃผ์ฐจ)
|
686 |
-
|
687 |
-
### ์คํ ๊ณํ
|
688 |
-
|
689 |
-
**๋ฐ์ดํฐ ์ ์ ํ์ดํ๋ผ์ธ ๊ตฌ์ถ**
|
690 |
-
|
691 |
-
> ์กฐ์ฌ ๊ฒฐ๊ณผ์ "80% ๊ท์น" ์ ์ฉ: ๋ฐ์ดํฐ ํ์ง์ด ์ฑ๋ฅ์ 80%๋ฅผ ๊ฒฐ์
|
692 |
-
|
693 |
-
```python
|
694 |
-
class DataQualityPipeline:
|
695 |
-
def __init__(self):
|
696 |
-
self.validators = [
|
697 |
-
MissingValueHandler(threshold=0.05),
|
698 |
-
OutlierDetector(method='isolation_forest'),
|
699 |
-
LabelConsistencyChecker(),
|
700 |
-
DataDriftMonitor()
|
701 |
-
]
|
702 |
-
|
703 |
-
def process(self, data):
|
704 |
-
for validator in self.validators:
|
705 |
-
data = validator.transform(data)
|
706 |
-
self.log_metrics(validator.get_stats())
|
707 |
-
return data
|
708 |
-
```
|
709 |
-
|
710 |
-
**๊ณ ๊ธ ๋ฐ์ดํฐ ์ฆ๊ฐ ๊ธฐ๋ฒ**
|
711 |
-
- **MixUp**: 15% ์ ํ๋ ํฅ์ ์์
|
712 |
-
- **CutMix**: ๊ฒฝ๊ณ ๊ฒ์ถ ์ฑ๋ฅ 20% ๊ฐ์
|
713 |
-
- **AutoAugment**: ์๋ ์ต์ ์ฆ๊ฐ ์ ์ฑ
ํ์
|
714 |
-
|
715 |
-
### ๋ฆฌ์คํฌ ๋์ ์ ๋ต
|
716 |
-
|
717 |
-
| ๋ฆฌ์คํฌ | ํ๋ฅ | ์ํฅ๋ | ๋์ ๋ฐฉ์ |
|
718 |
-
|--------|------|--------|-----------|
|
719 |
-
| ๋ฐ์ดํฐ ํ์ง ์ ํ | ์ค๊ฐ | ๋์ | ๋กค๋ฐฑ ๋ฉ์ปค๋์ฆ ๊ตฌํ |
|
720 |
-
| ์ฆ๊ฐ ๊ณผ์ ํฉ | ๋ฎ์ | ์ค๊ฐ | ๊ฒ์ฆ์
๋ถ๋ฆฌ ๋ฐ ๊ต์ฐจ ๊ฒ์ฆ |
|
721 |
-
| ์ฒ๋ฆฌ ์๊ฐ ์ฆ๊ฐ | ๋์ | ๋ฎ์ | ๋ณ๋ ฌ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ |
|
722 |
-
|
723 |
-
## ๐ 3๋จ๊ณ: ๋ชจ๋ธ ์ต์ ํ ๊ตฌํ (4-6์ฃผ์ฐจ)
|
724 |
-
|
725 |
-
### Knowledge Distillation ์์ธ ๊ณํ
|
726 |
-
|
727 |
-
**Teacher-Student ์ํคํ
์ฒ**
|
728 |
-
- Teacher ๋ชจ๋ธ: ํ์ฌ 2.5GB ๋ชจ๋ธ
|
729 |
-
- Student ๋ชจ๋ธ ์คํ:
|
730 |
-
- ํ๋ผ๋ฏธํฐ: 250M โ 25M (90% ๊ฐ์)
|
731 |
-
- ๋ ์ด์ด: 24 โ 6
|
732 |
-
- Hidden dimension: 1024 โ 256
|
733 |
-
|
734 |
-
**ํ๋ จ ์ ๋ต**
|
735 |
-
```python
|
736 |
-
distillation_config = {
|
737 |
-
"temperature": 5.0,
|
738 |
-
"alpha": 0.7, # KD loss weight
|
739 |
-
"beta": 0.3, # Original loss weight
|
740 |
-
"epochs": 50,
|
741 |
-
"learning_rate": 1e-4,
|
742 |
-
"batch_size": 128
|
743 |
-
}
|
744 |
-
```
|
745 |
-
|
746 |
-
### Pruning & Quantization
|
747 |
-
|
748 |
-
**๊ตฌ์กฐ์ Pruning ๊ณํ**
|
749 |
-
1. Magnitude ๊ธฐ๋ฐ ์ค์๋ ํ๊ฐ
|
750 |
-
2. 50% ์ฑ๋ ์ ๊ฑฐ
|
751 |
-
3. Fine-tuning: 10 ์ํญ
|
752 |
-
4. ์ฑ๋ฅ ๊ฒ์ฆ ๋ฐ ๋ฐ๋ณต
|
753 |
-
|
754 |
-
**INT8 Quantization**
|
755 |
-
- Post-training quantization ์ ์ฉ
|
756 |
-
- Calibration dataset: 1,000 ์ํ
|
757 |
-
- ์์ ์๋ ํฅ์: 4๋ฐฐ
|
758 |
-
|
759 |
-
## ๐ 4๋จ๊ณ: ์ฑ๊ณผ ๊ฒ์ฆ ๋ฐ ํ๋ก๋์
๋ฐฐํฌ (7-8์ฃผ์ฐจ)
|
760 |
-
|
761 |
-
### ์ข
ํฉ ์ฑ๋ฅ ๊ฒ์ฆ
|
762 |
-
|
763 |
-
**์ฑ๋ฅ ์งํ ๋ฌ์ฑ๋ ๊ฒ์ฆ**
|
764 |
-
|
765 |
-
| ํ
์คํธ ํญ๋ชฉ | ๋ฐฉ๋ฒ | ์ฑ๊ณต ๊ธฐ์ค | ๊ฒฐ๊ณผ |
|
766 |
-
|-------------|------|-----------|------|
|
767 |
-
| ์ถ๋ก ์๋ | A/B ํ
์คํธ | <5ms | โ
4.5ms |
|
768 |
-
| ์ ํ๋ | ํ๋์์ ๊ฒ์ฆ | >90% | โ
90.5% |
|
769 |
-
| ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ | ํ๋กํ์ผ๋ง | <300MB | โ
250MB |
|
770 |
-
| ์ฒ๋ฆฌ๋ | ๋ถํ ํ
์คํธ | >5000 req/s | โ
6000 req/s |
|
771 |
-
|
772 |
-
### ๋จ๊ณ์ ๋ฐฐํฌ ์ ๋ต
|
773 |
-
|
774 |
-
```mermaid
|
775 |
-
graph LR
|
776 |
-
A[1% ํธ๋ํฝ] --> B[10% ํธ๋ํฝ]
|
777 |
-
B --> C[50% ํธ๋ํฝ]
|
778 |
-
C --> D[100% ์ ํ]
|
779 |
-
|
780 |
-
A -->|Day 1-3| B
|
781 |
-
B -->|Day 4-7| C
|
782 |
-
C -->|Day 8-14| D
|
783 |
-
```
|
784 |
-
|
785 |
-
### ๋ชจ๋ํฐ๋ง ๋์๋ณด๋
|
786 |
-
|
787 |
-
**ํต์ฌ ๋ฉํธ๋ฆญ**
|
788 |
-
- ๐ด P99 ์ง์ฐ์๊ฐ: < 10ms
|
789 |
-
- ๐ก ์ค๋ฅ์จ: < 0.1%
|
790 |
-
- ๐ข CPU/GPU ์ฌ์ฉ๋ฅ : < 80%
|
791 |
-
|
792 |
-
## ๐ฐ ROI ๋ถ์
|
793 |
-
|
794 |
-
### ๋น์ฉ-ํจ์ต ๋ถ์
|
795 |
-
|
796 |
-
| ํญ๋ชฉ | ๋น์ฉ/ํจ์ต | ์ธ๋ถ ๋ด์ญ |
|
797 |
-
|------|-----------|-----------|
|
798 |
-
| **์ด๊ธฐ ํฌ์** | $50,000 | ์ธ๊ฑด๋น + ์ธํ๋ผ |
|
799 |
-
| **์๊ฐ ์ ๊ฐ์ก** | $14,000 | ์๋ฒ + GPU ๋น์ฉ |
|
800 |
-
| **ํฌ์ ํ์ ๊ธฐ๊ฐ** | 3.6๊ฐ์ | - |
|
801 |
-
| **1๋
์์ด์ต** | $118,000 | ์ ๊ฐ์ก - ํฌ์๋น |
|
802 |
-
|
803 |
-
### ์ฅ๊ธฐ ํจ๊ณผ
|
804 |
-
- ๐ ํ์ฅ์ฑ 10๋ฐฐ ํฅ์
|
805 |
-
- ๐ก ์ ๊ท ์๋น์ค ์ถ์ ๊ฐ๋ฅ
|
806 |
-
- ๐ ํ์ ๋ฐฐ์ถ 70% ๊ฐ์
|
807 |
-
|
808 |
-
## ๐ ์ง์์ ๊ฐ์ ๊ณํ
|
809 |
-
|
810 |
-
### ์๊ฐ ๋ชจ๋ํฐ๋ง
|
811 |
-
- ์ฑ๋ฅ ์งํ ๋ฆฌ๋ทฐ
|
812 |
-
- ์ฌ์ฉ์ ํผ๋๋ฐฑ ๋ถ์
|
813 |
-
- ๊ธฐ์ ๋ถ์ฑ ๊ด๋ฆฌ
|
814 |
-
|
815 |
-
### ๋ถ๊ธฐ๋ณ ์
๋ฐ์ดํธ
|
816 |
-
- ๋ชจ๋ธ ์ฌํ๋ จ
|
817 |
-
- ์๋ก์ด ์ต์ ํ ๊ธฐ๋ฒ ๋์
|
818 |
-
- ๋ฒค์น๋งํฌ ์
๋ฐ์ดํธ
|
819 |
-
|
820 |
-
### ์ฐจ๊ธฐ ํ๋ก์ ํธ ๋ก๋๋งต
|
821 |
-
|
822 |
-
| ๋ถ๊ธฐ | ํ๋ก์ ํธ | ์์ ํจ๊ณผ |
|
823 |
-
|------|----------|-----------|
|
824 |
-
| Q2 2025 | ์ฃ์ง ๋๋ฐ์ด์ค ๋ฐฐํฌ | ์ง์ฐ์๊ฐ 90% ๊ฐ์ |
|
825 |
-
| Q3 2025 | ์ฐํฉ ํ์ต ๋์
| ํ๋ผ์ด๋ฒ์ ๊ฐํ |
|
826 |
-
| Q4 2025 | AutoML ํ๋ซํผ ๊ตฌ์ถ | ๊ฐ๋ฐ ์๋ 5๋ฐฐ ํฅ์ |
|
827 |
-
|
828 |
-
## ๐ ๊ฒฐ๋ก ๋ฐ ๊ถ๊ณ ์ฌํญ
|
829 |
-
|
830 |
-
### ํต์ฌ ์ฑ๊ณผ
|
831 |
-
- โ
๋ชจ๋ ๋ชฉํ ์งํ ๋ฌ์ฑ
|
832 |
-
- โ
์์ฐ ๋ด ํ๋ก์ ํธ ์๋ฃ
|
833 |
-
- โ
๋ฆฌ์คํฌ ์ฑ๊ณต์ ๊ด๋ฆฌ
|
834 |
-
|
835 |
-
### ํฅํ ๊ถ๊ณ ์ฌํญ
|
836 |
-
1. **์ฆ์ ์คํ**: 1-2๋จ๊ณ ์ฆ์ ์ฐฉ์
|
837 |
-
2. **ํ ๊ตฌ์ฑ**: ML์์ง๋์ด 2๋ช
, DevOps 1๋ช
ํ์
|
838 |
-
3. **์ธํ๋ผ ์ค๋น**: GPU ์๋ฒ ์ฌ์ ํ๋ณด
|
839 |
-
4. **๋ณ๊ฒฝ ๊ด๋ฆฌ**: ์ดํด๊ด๊ณ์ ์ฌ์ ๊ต์ก
|
840 |
-
|
841 |
-
> ๋ณธ ํ๋ก์ ํธ๋ ์ต์ ์ฐ๊ตฌ ๊ฒฐ๊ณผ์ ์
๊ณ ๋ฒ ์คํธ ํ๋ํฐ์ค๋ฅผ ์ ์ฉํ์ฌ, 8์ฃผ ๋ง์ ๋ชจ๋ธ ์ฑ๋ฅ์ ํ๊ธฐ์ ์ผ๋ก ๊ฐ์ ํ๊ณ ์ด์ ๋น์ฉ์ 70% ์ ๊ฐํ๋ ์ฑ๊ณผ๋ฅผ ๋ฌ์ฑํ ๊ฒ์ผ๋ก ํ์ ํฉ๋๋ค.
|
842 |
-
|
843 |
-
---
|
844 |
-
*์์ฑ์ผ: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}*
|
845 |
-
*์์ฑ์: ํ๋ ฅ์ AI ์์คํ
(๊ฐ๋
์, ์กฐ์ฌ์, ์คํ์, ํ๊ฐ์ AI)*""",
|
846 |
-
|
847 |
-
"evaluator": """## ๐ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ํ๊ฐ ๋ณด๊ณ ์
|
848 |
-
|
849 |
-
### 1๏ธโฃ ํ์ง ํ๊ฐ (10์ ๋ง์ )
|
850 |
-
|
851 |
-
| AI ์ญํ | ์ ์ | ํ๊ฐ ๋ด์ฉ |
|
852 |
-
|---------|------|-----------|
|
853 |
-
| **๊ฐ๋
์ AI** | 9.5/10 | ๊ฑฐ์์ ๊ด์ ์์ ์ฒด๊ณ์ ์ธ ๋ถ์๊ณผ ๋ฐฉํฅ ์ ์ |
|
854 |
-
| **์กฐ์ฌ์ AI** | 9.0/10 | ์น ๊ฒ์์ ํตํ ์ต์ ์ ๋ณด ์์ง ์ฐ์ |
|
855 |
-
| **์คํ์ AI** | 8.5/10 | ์กฐ์ฌ ๋ด์ฉ์ ์ ํ์ฉํ ๊ตฌ์ฒด์ ๊ณํ ์๋ฆฝ |
|
856 |
-
|
857 |
-
**์์ธ ํ๊ฐ:**
|
858 |
-
- โ
๊ฐ๋
์ AI: ๋จ๊ณ๋ณ ๊ตฌ์ฒด์ ์ธ ์ง์์ฌํญ ์ ๊ณต์ด ํ์ํจ
|
859 |
-
- โ
์กฐ์ฌ์ AI: ์ ๋ขฐ๋ ํ๊ฐ์ ๋ชจ์ ๊ฐ์ง ๊ธฐ๋ฅ์ด ํจ๊ณผ์
|
860 |
-
- โ
์คํ์ AI: ์คํ ๊ฐ๋ฅํ ๋จ๊ณ๋ณ ์ ๊ทผ๋ฒ ์ ์ ์ฐ์
|
861 |
-
|
862 |
-
### 2๏ธโฃ ํ๋ ฅ ํจ๊ณผ์ฑ ํ๊ฐ
|
863 |
-
|
864 |
-
**๊ฐ์ :**
|
865 |
-
- ๐ AI ๊ฐ ์ญํ ๋ถ๋ด์ด ๋ช
ํํ๊ณ ์ํธ๋ณด์์
|
866 |
-
- ๐ ์ ๋ณด ํ๋ฆ์ด ์ฒด๊ณ์ ์ด๊ณ ์ผ๊ด์ฑ ์์
|
867 |
-
- โจ ํผ๋๋ฐฑ ๋ฐ์์ด ํจ๊ณผ์ ์ผ๋ก ์ด๋ฃจ์ด์ง
|
868 |
-
|
869 |
-
**๊ฐ์ ์ :**
|
870 |
-
- โก ์ค์๊ฐ ์ํธ์์ฉ ๋ฉ์ปค๋์ฆ ์ถ๊ฐ ๊ณ ๋ ค
|
871 |
-
- ๐ ์ค๊ฐ ์ ๊ฒ ๋จ๊ณ ๋์
ํ์
|
872 |
-
|
873 |
-
### 3๏ธโฃ ์ ๋ณด ํ์ฉ๋ ํ๊ฐ
|
874 |
-
|
875 |
-
| ํ๊ฐ ํญ๋ชฉ | ๋ฌ์ฑ๋ | ์ธ๋ถ ๋ด์ฉ |
|
876 |
-
|-----------|--------|-----------|
|
877 |
-
| ๊ฒ์ ๋ฒ์ | 95% | 20๊ฐ ์ด์์ ์น ์์ค์์ ์ ๋ณด ์์ง |
|
878 |
-
| ์ ๋ขฐ๋ ํ๊ฐ | 90% | 0.7 ์ด์์ ์ ๋ขฐ๋ ์์ค ์ฐ์ ํ์ฉ |
|
879 |
-
| ์ ๋ณด ํตํฉ | 85% | ๋ค์ํ ๊ด์ ์ ์ ๋ณด๋ฅผ ๊ท ํ์๊ฒ ํตํฉ |
|
880 |
-
|
881 |
-
**์ฐ์ํ ์ :**
|
882 |
-
- โ
์ ๋ขฐ๋ ๊ธฐ๋ฐ ์ ๋ณด ์ ๋ณ ํจ๊ณผ์
|
883 |
-
- โ
์ค์ ๊ธฐ์
์ฌ๋ก ์ ์ ํ ํ์ฉ
|
884 |
-
- โ
์ต์ ํธ๋ ๋ ๋ฐ์ ์ฐ์
|
885 |
-
|
886 |
-
**๋ณด์ ํ์:**
|
887 |
-
- ๐ ํ์ ๋
ผ๋ฌธ ๋ฑ ๋ ๊น์ด ์๋ ์๋ฃ ํ์ฉ
|
888 |
-
- ๐ ์ง์ญ๋ณ/์ฐ์
๋ณ ํน์ฑ ๊ณ ๋ ค ํ์
|
889 |
-
|
890 |
-
### 4๏ธโฃ ํฅํ ๊ฐ์ ๋ฐฉํฅ
|
891 |
-
|
892 |
-
#### 1. **์ค์๊ฐ ํ์
๊ฐํ**
|
893 |
-
- AI ๊ฐ ์ค๊ฐ ์ฒดํฌํฌ์ธํธ ์ถ๊ฐ
|
894 |
-
- ๋์ ์ญํ ์กฐ์ ๋ฉ์ปค๋์ฆ ๋์
|
895 |
-
|
896 |
-
#### 2. **์ ๋ณด ๊ฒ์ฆ ๊ฐํ**
|
897 |
-
- ๊ต์ฐจ ๊ฒ์ฆ ํ๋ก์ธ์ค ์ถ๊ฐ
|
898 |
-
- ์ ๋ฌธ๊ฐ ๊ฒํ ๋จ๊ณ ๊ณ ๋ ค
|
899 |
-
|
900 |
-
#### 3. **๋ง์ถคํ ๊ฐํ**
|
901 |
-
- ์ฌ์ฉ์ ์ปจํ
์คํธ ๋ ๊น์ด ๋ฐ์
|
902 |
-
- ์ฐ์
๋ณ/๊ท๋ชจ๋ณ ๋ง์ถค ์ ๋ต ์ ๊ณต
|
903 |
-
|
904 |
-
### 5๏ธโฃ ์ต์ข
ํ์ : โญโญโญโญโญ **9.0/10**
|
905 |
-
|
906 |
-
> **์ข
ํฉ ํ๊ฐ:**
|
907 |
-
>
|
908 |
-
> ๋ณธ ํ๋ ฅ ์์คํ
์ ๊ฐ AI์ ์ ๋ฌธ์ฑ์ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ์ฌ ์ฌ์ฉ์ ์ง๋ฌธ์ ๋ํ ์ข
ํฉ์ ์ด๊ณ ์คํ ๊ฐ๋ฅํ ๋ต๋ณ์ ์ ๊ณตํ์ต๋๋ค. ํนํ ์น ๊ฒ์์ ํตํ ์ต์ ์ ๋ณด ํ์ฉ๊ณผ ๋จ๊ณ์ ํผ๋๋ฐฑ ๋ฐ์์ด ์ฐ์ํ์ต๋๋ค.
|
909 |
-
>
|
910 |
-
> ํฅํ ์ค์๊ฐ ํ์
๊ณผ ๋ง์ถคํ๋ฅผ ๋์ฑ ๊ฐํํ๋ค๋ฉด ๋์ฑ ๋ฐ์ด๋ ์ฑ๊ณผ๋ฅผ ๋ฌ์ฑํ ์ ์์ ๊ฒ์
๋๋ค.
|
911 |
-
|
912 |
-
---
|
913 |
-
|
914 |
-
**ํ๊ฐ ์๋ฃ ์๊ฐ**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"""
|
915 |
-
}
|
916 |
-
|
917 |
-
# ํ๋กฌํํธ ๋ด์ฉ์ ๋ฐ๋ผ ์ ์ ํ ์๋ต ์ ํ
|
918 |
-
if role == "supervisor" and "์กฐ์ฌ์ AI๊ฐ ์ ๋ฆฌํ" in messages[0]["content"]:
|
919 |
-
response = test_responses["supervisor_execution"]
|
920 |
-
elif role == "supervisor" and messages[0]["content"].find("์คํ์ AI์ ๋ต๋ณ") > -1:
|
921 |
-
response = test_responses["supervisor_review"]
|
922 |
-
elif role == "supervisor":
|
923 |
-
response = test_responses["supervisor_initial"]
|
924 |
-
elif role == "researcher":
|
925 |
-
response = test_responses["researcher"]
|
926 |
-
elif role == "executor" and "์ต์ข
๋ณด๊ณ ์" in messages[0]["content"]:
|
927 |
-
response = test_responses["executor_final"]
|
928 |
-
elif role == "evaluator":
|
929 |
-
response = test_responses["evaluator"]
|
930 |
-
else:
|
931 |
-
response = test_responses["executor"]
|
932 |
|
933 |
-
|
|
|
|
|
|
|
|
|
934 |
return
|
935 |
|
936 |
-
# ์ค์ API ํธ์ถ
|
937 |
try:
|
938 |
-
system_prompts = {
|
939 |
-
"supervisor": "๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.",
|
940 |
-
"researcher": "๋น์ ์ ์ ๋ณด๋ฅผ ์กฐ์ฌํ๊ณ ์ฒด๊ณ์ ์ผ๋ก ์ ๋ฆฌํ๋ ์กฐ์ฌ์ AI์
๋๋ค.",
|
941 |
-
"executor": "๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค.",
|
942 |
-
"evaluator": "๋น์ ์ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ๋ ํ๊ฐ์ AI์
๋๋ค."
|
943 |
-
}
|
944 |
-
|
945 |
-
full_messages = [
|
946 |
-
{"role": "system", "content": system_prompts.get(role, "")},
|
947 |
-
*messages
|
948 |
-
]
|
949 |
-
|
950 |
payload = {
|
951 |
"model": self.model_id,
|
952 |
-
"messages":
|
953 |
"max_tokens": 4096,
|
954 |
"temperature": 0.7,
|
955 |
-
"
|
956 |
-
"stream": True,
|
957 |
-
"stream_options": {"include_usage": True}
|
958 |
}
|
959 |
|
960 |
-
logger.info(f"API ์คํธ๋ฆฌ๋ฐ ํธ์ถ ์์ - Role: {role}")
|
961 |
-
|
962 |
response = requests.post(
|
963 |
self.api_url,
|
964 |
headers=self.create_headers(),
|
@@ -968,8 +459,7 @@ graph LR
|
|
968 |
)
|
969 |
|
970 |
if response.status_code != 200:
|
971 |
-
|
972 |
-
yield f"โ API ์ค๋ฅ ({response.status_code}): {response.text[:200]}"
|
973 |
return
|
974 |
|
975 |
for line in response.iter_lines():
|
@@ -988,638 +478,366 @@ graph LR
|
|
988 |
except json.JSONDecodeError:
|
989 |
continue
|
990 |
|
991 |
-
except requests.exceptions.Timeout:
|
992 |
-
yield "โฑ๏ธ API ํธ์ถ ์๊ฐ์ด ์ด๊ณผ๋์์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์."
|
993 |
-
except requests.exceptions.ConnectionError:
|
994 |
-
yield "๐ API ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. ์ธํฐ๋ท ์ฐ๊ฒฐ์ ํ์ธํด์ฃผ์ธ์."
|
995 |
except Exception as e:
|
996 |
logger.error(f"์คํธ๋ฆฌ๋ฐ ์ค ์ค๋ฅ: {str(e)}")
|
997 |
yield f"โ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
998 |
|
999 |
# ์์คํ
์ธ์คํด์ค ์์ฑ
|
1000 |
-
|
1001 |
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
def process_query_streaming(user_query: str, llm_mode: str):
|
1006 |
-
"""์คํธ๋ฆฌ๋ฐ์ ์ง์ํ๋ ์ฟผ๋ฆฌ ์ฒ๋ฆฌ"""
|
1007 |
-
global internal_history
|
1008 |
-
|
1009 |
if not user_query:
|
1010 |
-
return "", "", "", "", "", "โ ์ง๋ฌธ์ ์
๋ ฅํด์ฃผ์ธ์."
|
1011 |
|
1012 |
-
|
1013 |
-
llm_system.set_llm_mode(llm_mode)
|
1014 |
|
1015 |
-
|
1016 |
-
|
|
|
1017 |
|
1018 |
try:
|
1019 |
-
# 1
|
1020 |
-
|
1021 |
-
|
1022 |
|
1023 |
-
|
1024 |
-
for chunk in
|
1025 |
-
[{"role": "user", "content":
|
1026 |
-
"supervisor"
|
1027 |
):
|
1028 |
-
|
1029 |
-
|
1030 |
-
yield
|
1031 |
-
|
1032 |
-
all_responses["supervisor"].append(supervisor_initial_response)
|
1033 |
-
|
1034 |
-
# ํค์๋ ์ถ์ถ
|
1035 |
-
keywords = llm_system.extract_keywords(supervisor_initial_response)
|
1036 |
-
logger.info(f"์ถ์ถ๋ ํค์๋: {keywords}")
|
1037 |
|
1038 |
-
|
1039 |
-
researcher_text = "[์น ๊ฒ์] ๐ ๊ฒ์ ์ค...\n"
|
1040 |
-
yield supervisor_text, researcher_text, "", "", "", "๐ ์น ๊ฒ์ ์ํ ์ค..."
|
1041 |
|
1042 |
-
|
1043 |
-
|
|
|
|
|
1044 |
|
1045 |
-
# ์๋ ํค์๋๋ก ๊ฒ์
|
1046 |
for keyword in keywords:
|
1047 |
-
results =
|
1048 |
if results:
|
1049 |
search_results[keyword] = results
|
1050 |
-
total_search_count += len(results)
|
1051 |
-
researcher_text += f"โ '{keyword}' ๊ฒ์ ์๋ฃ ({len(results)}๊ฐ ๊ฒฐ๊ณผ)\n"
|
1052 |
-
yield supervisor_text, researcher_text, "", "", "", f"๐ '{keyword}' ๊ฒ์ ์ค..."
|
1053 |
-
|
1054 |
-
# ๋์์ด๋ก ์ถ๊ฐ ๊ฒ์
|
1055 |
-
synonyms = llm_system.generate_synonyms(keyword)
|
1056 |
-
for synonym in synonyms:
|
1057 |
-
syn_results = llm_system.brave_search(f"{keyword} {synonym}")
|
1058 |
-
if syn_results:
|
1059 |
-
search_results[f"{keyword} ({synonym})"] = syn_results
|
1060 |
-
total_search_count += len(syn_results)
|
1061 |
-
researcher_text += f"โ ๋์์ด '{synonym}' ๊ฒ์ ์๋ฃ ({len(syn_results)}๊ฐ ๊ฒฐ๊ณผ)\n"
|
1062 |
-
yield supervisor_text, researcher_text, "", "", "", f"๐ ๋์์ด '{synonym}' ๊ฒ์ ์ค..."
|
1063 |
-
|
1064 |
-
researcher_text += f"\n๐ ์ด {total_search_count}๊ฐ์ ๊ฒ์ ๊ฒฐ๊ณผ ์์ง ์๋ฃ\n"
|
1065 |
-
|
1066 |
-
# URL ์ฝํ
์ธ ๊ฐ์ ธ์ค๊ธฐ (์์ 3๊ฐ)
|
1067 |
-
researcher_text += "\n[์ฝํ
์ธ ๋ถ์] ๐ ์ฃผ์ ์นํ์ด์ง ๋ด์ฉ ๋ถ์ ์ค...\n"
|
1068 |
-
yield supervisor_text, researcher_text, "", "", "", "๐ ์นํ์ด์ง ๋ด์ฉ ๋ถ์ ์ค..."
|
1069 |
-
|
1070 |
-
content_analyzed = 0
|
1071 |
-
for keyword, results in search_results.items():
|
1072 |
-
for result in results[:2]: # ๊ฐ ํค์๋๋น ์์ 2๊ฐ๋ง
|
1073 |
-
if content_analyzed >= 5: # ์ด 5๊ฐ๊น์ง๋ง
|
1074 |
-
break
|
1075 |
-
|
1076 |
-
url = result.get('url', '')
|
1077 |
-
if url and result.get('credibility_score', 0) >= 0.7:
|
1078 |
-
content = llm_system.fetch_url_content(url)
|
1079 |
-
if content:
|
1080 |
-
result['content_preview'] = content[:500] # ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ ์ฅ
|
1081 |
-
content_analyzed += 1
|
1082 |
-
researcher_text += f"โ ์ฝํ
์ธ ๋ถ์ ์๋ฃ: {url[:50]}...\n"
|
1083 |
-
yield supervisor_text, researcher_text, "", "", "", f"๐ ๋ถ์ ์ค: {url[:30]}..."
|
1084 |
|
1085 |
-
#
|
1086 |
-
|
1087 |
-
|
1088 |
|
1089 |
-
|
1090 |
-
for chunk in
|
1091 |
-
[{"role": "user", "content":
|
1092 |
-
"researcher"
|
1093 |
):
|
1094 |
-
|
1095 |
-
|
1096 |
-
yield
|
1097 |
|
1098 |
-
|
1099 |
-
|
1100 |
-
# 4๋จ๊ณ: ํ๊ฐ์ AI๊ฐ ์กฐ์ฌ ๊ฒฐ๊ณผ ํ๊ฐ
|
1101 |
-
evaluator_research_prompt = f"""๋น์ ์ ์ ์ฒด ํ๋ ฅ ๊ณผ์ ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ๋ ํ๊ฐ์ AI์
๋๋ค.
|
1102 |
-
|
1103 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1104 |
-
|
1105 |
-
๊ฐ๋
์ AI์ ์ด๊ธฐ ๋ถ์:
|
1106 |
-
{supervisor_initial_response}
|
1107 |
-
|
1108 |
-
์กฐ์ฌ์ AI์ ์กฐ์ฌ ๊ฒฐ๊ณผ:
|
1109 |
-
{researcher_response}
|
1110 |
-
|
1111 |
-
์ ์กฐ์ฌ ๊ฒฐ๊ณผ๋ฅผ ํ๊ฐํ์ฌ:
|
1112 |
-
1. ์กฐ์ฌ์ ์ถฉ์ค๋์ ์ ๋ขฐ์ฑ์ ํ๊ฐํ์ธ์
|
1113 |
-
2. ๋๋ฝ๋ ์ค์ ์ ๋ณด๊ฐ ์๋์ง ํ์ธํ์ธ์
|
1114 |
-
3. ์กฐ์ฌ ๊ฒฐ๊ณผ์ ํ์ฉ ๊ฐ๋ฅ์ฑ์ ํ๊ฐํ์ธ์
|
1115 |
-
4. ๊ฐ์ ์ด ํ์ํ ๋ถ๋ถ์ ๊ตฌ์ฒด์ ์ผ๋ก ์ ์ํ์ธ์"""
|
1116 |
|
1117 |
-
|
1118 |
-
|
|
|
1119 |
|
1120 |
-
|
1121 |
-
|
1122 |
-
"
|
1123 |
):
|
1124 |
-
|
1125 |
-
|
1126 |
-
yield
|
1127 |
|
1128 |
-
all_responses[
|
1129 |
-
|
1130 |
-
# 5๋จ๊ณ: ๊ฐ๋
์ AI๊ฐ ํ๊ฐ๋ฅผ ๋ฐ์ํ ์คํ ์ง์
|
1131 |
-
supervisor_execution_prompt = f"""๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.
|
1132 |
-
|
1133 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1134 |
-
|
1135 |
-
์กฐ์ฌ์ AI๊ฐ ์ ๋ฆฌํ ์กฐ์ฌ ๋ด์ฉ:
|
1136 |
-
{researcher_response}
|
1137 |
-
|
1138 |
-
ํ๊ฐ์ AI์ ์กฐ์ฌ ๊ฒฐ๊ณผ ํ๊ฐ:
|
1139 |
-
{evaluator_research_response}
|
1140 |
-
|
1141 |
-
์ ์กฐ์ฌ ๋ด์ฉ๊ณผ ํ๊ฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์คํ์ AI์๊ฒ ์์ฃผ ๊ตฌ์ฒด์ ์ธ ์ง์๋ฅผ ๋ด๋ ค์ฃผ์ธ์:
|
1142 |
-
1. ํ๊ฐ์์ ํผ๋๋ฐฑ์ ๋ฐ์ํ์ฌ ์ง์๋ฅผ ๊ฐ์ ํ์ธ์
|
1143 |
-
2. ์กฐ์ฌ๋ ์ ๋ณด๋ฅผ ์ด๋ป๊ฒ ํ์ฉํ ์ง ๋ช
ํํ ์ง์ํ์ธ์
|
1144 |
-
3. ์คํ ๊ฐ๋ฅํ ๋จ๊ณ๋ณ ์์
์ ๊ตฌ์ฒด์ ์ผ๋ก ์ ์ํ์ธ์
|
1145 |
-
4. ์์๋๋ ๊ฒฐ๊ณผ๋ฌผ์ ํํ๋ฅผ ๊ตฌ์ฒด์ ์ผ๋ก ์ค๋ช
ํ์ธ์"""
|
1146 |
|
1147 |
-
|
|
|
|
|
1148 |
|
1149 |
-
|
1150 |
-
for chunk in
|
1151 |
-
[{"role": "user", "content":
|
1152 |
-
"supervisor"
|
1153 |
):
|
1154 |
-
|
1155 |
-
temp_text =
|
1156 |
-
|
1157 |
-
yield
|
1158 |
|
1159 |
-
|
1160 |
|
1161 |
-
#
|
1162 |
-
|
1163 |
-
|
1164 |
|
1165 |
-
|
1166 |
-
for chunk in
|
1167 |
-
[{"role": "user", "content":
|
1168 |
-
"executor"
|
1169 |
):
|
1170 |
-
|
1171 |
-
|
1172 |
-
yield
|
1173 |
|
1174 |
-
all_responses[
|
1175 |
|
1176 |
-
#
|
1177 |
-
|
1178 |
-
|
1179 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1180 |
-
|
1181 |
-
์คํ์ AI์ ์ด๊ธฐ ๊ตฌํ:
|
1182 |
-
{executor_response}
|
1183 |
-
|
1184 |
-
๊ฐ๋
์ AI์ ์ง์์ฌํญ:
|
1185 |
-
{supervisor_execution_response}
|
1186 |
-
|
1187 |
-
์ ์ด๊ธฐ ๊ตฌํ์ ํ๊ฐํ์ฌ:
|
1188 |
-
1. ์ง์์ฌํญ์ด ์ผ๋ง๋ ์ ๋ฐ์๋์๋์ง ํ๊ฐํ์ธ์
|
1189 |
-
2. ๊ตฌํ์ ์คํ ๊ฐ๋ฅ์ฑ๊ณผ ๊ตฌ์ฒด์ฑ์ ํ๊ฐํ์ธ์
|
1190 |
-
3. ๋๋ฝ๋ ์ค์ ์์๊ฐ ์๋์ง ํ์ธํ์ธ์
|
1191 |
-
4. ๊ฐ์ ์ด ํ์ํ ๋ถ๋ถ์ ๊ตฌ์ฒด์ ์ผ๋ก ์ ์ํ์ธ์"""
|
1192 |
|
1193 |
-
|
1194 |
-
|
|
|
|
|
|
|
1195 |
|
1196 |
-
for chunk in
|
1197 |
-
[{"role": "user", "content":
|
1198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1199 |
):
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
yield supervisor_text, researcher_text, executor_text, evaluator_text, "", "๐ ํ๊ฐ์ AI๊ฐ ๊ตฌํ ํ๊ฐ ์ค..."
|
1204 |
|
1205 |
-
all_responses[
|
1206 |
|
1207 |
-
# 8
|
1208 |
-
|
1209 |
-
|
1210 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1211 |
-
|
1212 |
-
์คํ์ AI์ ์ด๊ธฐ ๊ตฌํ:
|
1213 |
-
{executor_response}
|
1214 |
-
|
1215 |
-
ํ๊ฐ์ AI์ ๊ตฌํ ํ๊ฐ:
|
1216 |
-
{evaluator_execution_response}
|
1217 |
-
|
1218 |
-
์ ํ๊ฐ๋ฅผ ๋ฐ์ํ์ฌ ์ต์ข
๋ณด๊ณ ์ ์์ฑ์ ์ํ ๊ฐ์ ์ง์๋ฅผ ๋ด๋ ค์ฃผ์ธ์:
|
1219 |
-
1. ํ๊ฐ์๊ฐ ์ง์ ํ ๋ชจ๋ ๊ฐ์ ์ฌํญ์ ๊ตฌ์ฒด์ ์ผ๋ก ๋ฐ์ํ์ธ์
|
1220 |
-
2. ์ถ๊ฐ๋ก ํ์ํ ๊ตฌ์ฒด์ ์ธ ๋ด์ฉ์ ์ง์ํ์ธ์
|
1221 |
-
3. ์ต์ข
๋ณด๊ณ ์์ ๊ตฌ์กฐ์ ํฌํจํด์ผ ํ ์์๋ฅผ ๋ช
ํํ ์ ์ํ์ธ์"""
|
1222 |
|
1223 |
-
|
1224 |
-
|
|
|
|
|
|
|
|
|
1225 |
|
1226 |
-
|
1227 |
-
|
1228 |
-
"
|
1229 |
):
|
1230 |
-
|
1231 |
-
|
1232 |
-
supervisor_text = f"[์ด๊ธฐ ๋ถ์] - {datetime.now().strftime('%H:%M:%S')}\n{temp_text}"
|
1233 |
-
yield supervisor_text, researcher_text, executor_text, evaluator_text, "", "๐ ๊ฐ๋
์ AI๊ฐ ๊ฐ์ ์ง์ ์ค..."
|
1234 |
|
1235 |
-
|
1236 |
|
1237 |
-
# 9
|
1238 |
-
|
1239 |
-
|
1240 |
-
all_responses["supervisor"],
|
1241 |
-
all_responses["researcher"][0],
|
1242 |
-
all_responses["executor"],
|
1243 |
-
all_responses["evaluator"] # ์ด์ ํ๊ฐ๋ค๋ ์ ๋ฌ
|
1244 |
-
)
|
1245 |
-
evaluator_final_response = ""
|
1246 |
|
1247 |
-
|
1248 |
-
for chunk in
|
1249 |
-
[{"role": "user", "content":
|
1250 |
-
"evaluator"
|
1251 |
):
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
yield supervisor_text, researcher_text, executor_text, evaluator_text, "", "๐ ํ๊ฐ์ AI๊ฐ ์ต์ข
ํ๊ฐ ์ค..."
|
1256 |
-
|
1257 |
-
all_responses["evaluator"].append(evaluator_final_response)
|
1258 |
|
1259 |
-
|
1260 |
-
final_executor_prompt = f"""๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค.
|
1261 |
-
|
1262 |
-
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
1263 |
-
|
1264 |
-
์กฐ์ฌ์ AI์ ์กฐ์ฌ ๋ด์ฉ:
|
1265 |
-
{researcher_response}
|
1266 |
-
|
1267 |
-
๋น์ ์ ์ด๊ธฐ ๊ตฌํ:
|
1268 |
-
{executor_response}
|
1269 |
-
|
1270 |
-
๊ฐ๋
์ AI์ ๊ฐ์ ์ง์:
|
1271 |
-
{supervisor_improvement_response}
|
1272 |
-
|
1273 |
-
ํ๊ฐ์ AI์ ์ ์ฒด ํ๊ฐ:
|
1274 |
-
{evaluator_final_response}
|
1275 |
-
|
1276 |
-
์ ๋ชจ๋ ํผ๋๋ฐฑ์ ์์ ํ ๋ฐ์ํ์ฌ ์ต์ข
๋ณด๊ณ ์๋ฅผ ์์ฑํ์ธ์:
|
1277 |
-
1. ๋ชจ๋ ๊ฐ์ ์ฌํญ๊ณผ ์ง์์ฌํญ์ ๋น ์ง์์ด ๋ฐ์ํ์ธ์
|
1278 |
-
2. ์กฐ์ฌ ๋ด์ฉ์ ์ต๋ํ ๊ตฌ์ฒด์ ์ผ๋ก ํ์ฉํ์ธ์
|
1279 |
-
3. ์คํ ๊ฐ๋ฅ์ฑ์ ๋์ด๋ ์ธ๋ถ ๊ณํ์ ํฌํจํ์ธ์
|
1280 |
-
4. ๋ช
ํํ ๊ฒฐ๋ก ๊ณผ ๋ค์ ๋จ๊ณ๋ฅผ ์ ์ํ์ธ์
|
1281 |
-
5. ์ ๋ฌธ์ ์ด๊ณ ์์ฑ๋ ๋์ ์ต์ข
๋ณด๊ณ ์ ํ์์ผ๋ก ์์ฑํ์ธ์
|
1282 |
-
|
1283 |
-
**์ค์: ๋งํฌ๋ค์ด ํ์์ ์ ๊ทน ํ์ฉํ์ธ์**
|
1284 |
-
- ์ ๋ชฉ์ #, ##, ### ์ ์ฌ์ฉํ์ฌ ๊ณ์ธต์ ์ผ๋ก ๊ตฌ์ฑ
|
1285 |
-
- ์ค์ํ ๋ด์ฉ์ **๊ตต๊ฒ** ํ์
|
1286 |
-
- ๋ฆฌ์คํธ๋ -, * ๋๋ 1. 2. 3. ํ์ ์ฌ์ฉ
|
1287 |
-
- ํ๊ฐ ํ์ํ ๊ฒฝ์ฐ ๋งํฌ๋ค์ด ํ ํ์ ์ฌ์ฉ:
|
1288 |
-
| ํญ๋ชฉ | ๋ด์ฉ | ๋น๊ณ |
|
1289 |
-
|------|------|------|
|
1290 |
-
| ์์1 | ์ค๋ช
1 | ์ฐธ๊ณ 1 |
|
1291 |
-
- ์ฝ๋๋ ``` ๋ก ๊ฐ์ธ์ ํ์
|
1292 |
-
- ์ธ์ฉ๊ตฌ๋ > ๋ฅผ ์ฌ์ฉ
|
1293 |
-
- ๊ตฌ๋ถ์ ์ --- ์ฌ์ฉ"""
|
1294 |
|
1295 |
-
|
|
|
|
|
1296 |
|
1297 |
-
|
1298 |
-
|
1299 |
-
[{"role": "user", "content": final_executor_prompt}],
|
1300 |
-
"executor"
|
1301 |
):
|
1302 |
-
|
1303 |
-
|
1304 |
-
executor_text = temp_text
|
1305 |
-
yield supervisor_text, researcher_text, executor_text, evaluator_text, "", "๐ ์ต์ข
๋ณด๊ณ ์ ์์ฑ ์ค..."
|
1306 |
|
1307 |
-
|
1308 |
|
1309 |
-
#
|
1310 |
-
|
1311 |
-
|
1312 |
-
## ๐ ์ฌ์ฉ์ ์ง๋ฌธ
|
1313 |
-
**{user_query}**
|
1314 |
-
|
1315 |
-
---
|
1316 |
-
|
1317 |
-
## ๐ ์ต์ข
๋ณด๊ณ ์ (์คํ์ AI - ๋ชจ๋ ํผ๋๋ฐฑ ๋ฐ์)
|
1318 |
-
|
1319 |
-
{final_executor_response}
|
1320 |
-
|
1321 |
-
---
|
1322 |
-
|
1323 |
-
## ๐ ์ ์ฒด ํ๋ก์ธ์ค ํ๊ฐ (ํ๊ฐ์ AI)
|
1324 |
-
|
1325 |
-
{evaluator_final_response}
|
1326 |
-
|
1327 |
-
---
|
1328 |
-
|
1329 |
-
## ๐ ํต์ฌ ์กฐ์ฌ ๊ฒฐ๊ณผ ์์ฝ (์กฐ์ฌ์ AI)
|
1330 |
-
|
1331 |
-
{researcher_response[:800]}...
|
1332 |
-
|
1333 |
-
---
|
1334 |
-
|
1335 |
-
## ๐ ํ๋ก์ธ์ค ์๋ฃ
|
1336 |
-
|
1337 |
-
| ํญ๋ชฉ | ๋ด์ฉ |
|
1338 |
-
|------|------|
|
1339 |
-
| **์ฌ์ฉ ๋ชจ๋ธ** | {'Gemini 2.5 Pro' if llm_system.use_gemini else '๊ธฐ๋ณธ LLM'} |
|
1340 |
-
| **ํ๋ก์ธ์ค** | ๊ฐ๋
โ์กฐ์ฌโํ๊ฐโ๊ฐ๋
โ์คํโํ๊ฐโ๊ฐ๋
โํ๊ฐโ์คํ |
|
1341 |
-
| **์ด ๋จ๊ณ** | 9๋จ๊ณ ํ๋ ฅ ์๋ฃ |
|
1342 |
-
| **์์ฑ ์๊ฐ** | {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} |
|
1343 |
-
|
1344 |
-
---
|
1345 |
-
|
1346 |
-
> ๐ก **์ฐธ๊ณ **: ์ด ๋ณด๊ณ ์๋ 4๊ฐ AI์ ํ๋ ฅ์ ํตํด ์์ฑ๋์์ผ๋ฉฐ, ๋ค๋จ๊ณ ํ๊ฐ ํ๋ก์ธ์ค๋ฅผ ๊ฑฐ์ณ ํ์ง์ด ๊ฒ์ฆ๋์์ต๋๋ค."""
|
1347 |
|
1348 |
-
|
1349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1350 |
|
1351 |
-
|
|
|
1352 |
|
1353 |
except Exception as e:
|
1354 |
error_msg = f"โ ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}"
|
1355 |
-
yield "", "", "", "",
|
1356 |
|
1357 |
-
def
|
1358 |
-
"""
|
1359 |
-
|
1360 |
-
internal_history = []
|
1361 |
-
return "", "", "", "", "", "๐ ์ด๊ธฐํ๋์์ต๋๋ค."
|
1362 |
|
1363 |
-
#
|
1364 |
css = """
|
1365 |
.gradio-container {
|
1366 |
font-family: 'Arial', sans-serif;
|
1367 |
}
|
1368 |
-
.
|
1369 |
-
border-left: 4px solid #667eea !important;
|
1370 |
-
padding-left: 10px !important;
|
1371 |
-
background-color: #f8f9ff !important;
|
1372 |
-
}
|
1373 |
-
.researcher-box textarea {
|
1374 |
border-left: 4px solid #10b981 !important;
|
1375 |
-
padding-left: 10px !important;
|
1376 |
background-color: #f0fdf4 !important;
|
1377 |
}
|
1378 |
-
.
|
1379 |
-
border-left: 4px solid #
|
1380 |
-
|
|
|
|
|
|
|
1381 |
background-color: #faf5ff !important;
|
1382 |
}
|
1383 |
-
.
|
1384 |
border-left: 4px solid #f59e0b !important;
|
1385 |
-
padding-left: 10px !important;
|
1386 |
background-color: #fffbeb !important;
|
1387 |
}
|
1388 |
-
.
|
1389 |
-
border: 2px solid #3b82f6 !important;
|
1390 |
-
border-radius: 8px !important;
|
1391 |
-
padding: 16px !important;
|
1392 |
-
background-color: #eff6ff !important;
|
1393 |
-
margin-top: 10px !important;
|
1394 |
-
font-size: 14px !important;
|
1395 |
-
max-height: 700px !important;
|
1396 |
-
overflow-y: auto !important;
|
1397 |
-
line-height: 1.6 !important;
|
1398 |
-
}
|
1399 |
-
.final-report-box h1 {
|
1400 |
-
color: #1e40af !important;
|
1401 |
-
font-size: 24px !important;
|
1402 |
-
margin-bottom: 12px !important;
|
1403 |
-
}
|
1404 |
-
.final-report-box h2 {
|
1405 |
-
color: #2563eb !important;
|
1406 |
-
font-size: 20px !important;
|
1407 |
-
margin-top: 16px !important;
|
1408 |
-
margin-bottom: 10px !important;
|
1409 |
-
}
|
1410 |
-
.final-report-box h3 {
|
1411 |
-
color: #3b82f6 !important;
|
1412 |
-
font-size: 18px !important;
|
1413 |
-
margin-top: 12px !important;
|
1414 |
-
margin-bottom: 8px !important;
|
1415 |
-
}
|
1416 |
-
.final-report-box table {
|
1417 |
-
border-collapse: collapse !important;
|
1418 |
-
width: 100% !important;
|
1419 |
-
margin: 16px 0 !important;
|
1420 |
-
}
|
1421 |
-
.final-report-box th, .final-report-box td {
|
1422 |
-
border: 1px solid #cbd5e1 !important;
|
1423 |
-
padding: 8px 10px !important;
|
1424 |
-
text-align: left !important;
|
1425 |
-
}
|
1426 |
-
.final-report-box th {
|
1427 |
-
background-color: #e0e7ff !important;
|
1428 |
-
font-weight: bold !important;
|
1429 |
-
color: #1e40af !important;
|
1430 |
-
}
|
1431 |
-
.final-report-box tr:nth-child(even) {
|
1432 |
-
background-color: #f8fafc !important;
|
1433 |
-
}
|
1434 |
-
.final-report-box tr:hover {
|
1435 |
-
background-color: #f0f4f8 !important;
|
1436 |
-
}
|
1437 |
-
.final-report-box code {
|
1438 |
-
background-color: #f1f5f9 !important;
|
1439 |
-
padding: 2px 6px !important;
|
1440 |
-
border-radius: 4px !important;
|
1441 |
-
font-family: 'Consolas', 'Monaco', monospace !important;
|
1442 |
-
color: #dc2626 !important;
|
1443 |
-
}
|
1444 |
-
.final-report-box pre {
|
1445 |
-
background-color: #1e293b !important;
|
1446 |
-
color: #e2e8f0 !important;
|
1447 |
-
padding: 12px !important;
|
1448 |
-
border-radius: 6px !important;
|
1449 |
-
overflow-x: auto !important;
|
1450 |
-
margin: 12px 0 !important;
|
1451 |
-
font-size: 13px !important;
|
1452 |
-
}
|
1453 |
-
.final-report-box pre code {
|
1454 |
-
background-color: transparent !important;
|
1455 |
-
color: #e2e8f0 !important;
|
1456 |
-
padding: 0 !important;
|
1457 |
-
}
|
1458 |
-
.final-report-box blockquote {
|
1459 |
border-left: 4px solid #3b82f6 !important;
|
1460 |
-
|
1461 |
-
margin-left: 0 !important;
|
1462 |
-
margin: 12px 0 !important;
|
1463 |
-
color: #475569 !important;
|
1464 |
-
font-style: italic !important;
|
1465 |
-
background-color: #f0f9ff !important;
|
1466 |
-
padding: 10px 12px !important;
|
1467 |
-
border-radius: 0 6px 6px 0 !important;
|
1468 |
-
}
|
1469 |
-
.final-report-box ul, .final-report-box ol {
|
1470 |
-
margin-left: 20px !important;
|
1471 |
-
margin-bottom: 12px !important;
|
1472 |
-
}
|
1473 |
-
.final-report-box li {
|
1474 |
-
margin-bottom: 6px !important;
|
1475 |
-
line-height: 1.6 !important;
|
1476 |
-
}
|
1477 |
-
.final-report-box strong {
|
1478 |
-
color: #1e40af !important;
|
1479 |
-
font-weight: 600 !important;
|
1480 |
-
}
|
1481 |
-
.final-report-box em {
|
1482 |
-
color: #3730a3 !important;
|
1483 |
-
}
|
1484 |
-
.final-report-box hr {
|
1485 |
-
border: none !important;
|
1486 |
-
border-top: 2px solid #cbd5e1 !important;
|
1487 |
-
margin: 24px 0 !important;
|
1488 |
}
|
1489 |
-
.
|
1490 |
-
|
1491 |
-
|
1492 |
}
|
1493 |
-
|
1494 |
-
|
|
|
1495 |
}
|
1496 |
"""
|
1497 |
|
1498 |
-
|
|
|
1499 |
gr.Markdown(
|
1500 |
"""
|
1501 |
-
#
|
1502 |
-
|
1503 |
-
### ๐
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
|
|
|
|
|
|
1510 |
"""
|
1511 |
)
|
1512 |
|
1513 |
-
# ์
๋ ฅ ์น์
|
1514 |
with gr.Row():
|
1515 |
-
with gr.Column():
|
1516 |
-
gr.Markdown("""
|
1517 |
-
## ๐ 4๊ฐ AI์ ํ๋ ฅ ์์คํ
|
1518 |
-
- **๊ฐ๋
์ AI**: ๊ฑฐ์์ ๋ถ์๊ณผ ์ ๋ต ์๋ฆฝ
|
1519 |
-
- **์กฐ์ฌ์ AI**: ์น ๊ฒ์๊ณผ ์ ๋ณด ์์ง/์ ๋ฆฌ
|
1520 |
-
- **์คํ์ AI**: ๊ตฌ์ฒด์ ๊ณํ ์๋ฆฝ๊ณผ ์คํ
|
1521 |
-
- **ํ๊ฐ์ AI**: ์ ์ฒด ๊ณผ์ ํ๊ฐ์ ๊ฐ์ ์ ์ ์
|
1522 |
-
|
1523 |
-
### ๐ ์ฃผ์ ๊ธฐ๋ฅ
|
1524 |
-
- ์ต๋ 4096 ํ ํฐ ์ง์ (๊ธด ์๋ต ๊ฐ๋ฅ)
|
1525 |
-
- 20๊ฐ ๊ฒ์ ๊ฒฐ๊ณผ์ ๋์์ด ๊ฒ์
|
1526 |
-
- ์ ๋ขฐ๋ ๊ธฐ๋ฐ ์ ๋ณด ํ๊ฐ
|
1527 |
-
- ๋ค๋จ๊ณ ํ๊ฐ์ ํผ๋๋ฐฑ ๋ฐ์
|
1528 |
-
|
1529 |
-
### ๐ ํ๋ก์ธ์ค
|
1530 |
-
๊ฐ๋
โ ์กฐ์ฌ โ ํ๊ฐ โ ๊ฐ๋
โ ์คํ โ ํ๊ฐ โ ๊ฐ๋
โ ํ๊ฐ โ ์คํ
|
1531 |
-
""")
|
1532 |
-
|
1533 |
-
# LLM ์ ํ ์ต์
|
1534 |
llm_mode = gr.Radio(
|
1535 |
choices=["default", "commercial"],
|
1536 |
value="default",
|
1537 |
-
label="LLM ๋ชจ๋
|
1538 |
-
info="commercial
|
1539 |
)
|
1540 |
|
1541 |
user_input = gr.Textbox(
|
1542 |
label="์ง๋ฌธ ์
๋ ฅ",
|
1543 |
-
placeholder="์:
|
1544 |
lines=3
|
1545 |
)
|
1546 |
|
1547 |
with gr.Row():
|
1548 |
submit_btn = gr.Button("๐ ๋ถ์ ์์", variant="primary", scale=2)
|
1549 |
clear_btn = gr.Button("๐๏ธ ์ด๊ธฐํ", scale=1)
|
1550 |
-
|
|
|
1551 |
status_text = gr.Textbox(
|
1552 |
-
label="์ํ",
|
1553 |
interactive=False,
|
1554 |
value="๋๊ธฐ ์ค...",
|
1555 |
-
|
1556 |
)
|
1557 |
|
1558 |
-
#
|
1559 |
with gr.Row():
|
1560 |
with gr.Column():
|
1561 |
-
gr.Markdown("###
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1565 |
)
|
1566 |
|
1567 |
-
# AI ์ถ๋ ฅ๋ค - 2x2 ๊ทธ๋ฆฌ๋
|
1568 |
with gr.Row():
|
1569 |
-
# ์๋จ ํ
|
1570 |
with gr.Column():
|
1571 |
-
gr.Markdown("###
|
1572 |
-
|
1573 |
label="",
|
1574 |
-
lines=
|
1575 |
-
max_lines=
|
1576 |
interactive=False,
|
1577 |
-
elem_classes=["
|
1578 |
)
|
1579 |
|
1580 |
with gr.Column():
|
1581 |
-
gr.Markdown("###
|
1582 |
-
|
1583 |
label="",
|
1584 |
-
lines=
|
1585 |
-
max_lines=
|
1586 |
interactive=False,
|
1587 |
-
elem_classes=["
|
1588 |
)
|
1589 |
|
1590 |
with gr.Row():
|
1591 |
-
# ํ๋จ ํ
|
1592 |
with gr.Column():
|
1593 |
-
gr.Markdown("###
|
1594 |
-
|
1595 |
label="",
|
1596 |
-
lines=
|
1597 |
-
max_lines=
|
1598 |
interactive=False,
|
1599 |
-
elem_classes=["
|
1600 |
)
|
1601 |
|
1602 |
with gr.Column():
|
1603 |
-
gr.Markdown("###
|
1604 |
-
|
1605 |
label="",
|
1606 |
-
lines=
|
1607 |
-
max_lines=
|
1608 |
interactive=False,
|
1609 |
-
elem_classes=["
|
1610 |
)
|
1611 |
|
1612 |
# ์์
|
1613 |
gr.Examples(
|
1614 |
examples=[
|
1615 |
-
"
|
1616 |
-
"
|
1617 |
-
"
|
1618 |
-
"
|
1619 |
-
"
|
1620 |
-
"์คํํธ์
์ ์ํ ํจ๊ณผ์ ์ธ ๋ง์ผํ
์ ๋ต์?",
|
1621 |
-
"AI ์ค๋ฆฌ์ ๊ท์ ์ ์ต์ ๋ํฅ์?",
|
1622 |
-
"ํด๋ผ์ฐ๋ ๋ค์ดํฐ๋ธ ์ ํ๋ฆฌ์ผ์ด์
๊ฐ๋ฐ ๋ชจ๋ฒ ์ฌ๋ก๋?"
|
1623 |
],
|
1624 |
inputs=user_input,
|
1625 |
label="๐ก ์์ ์ง๋ฌธ"
|
@@ -1627,35 +845,33 @@ with gr.Blocks(title="ํ๋ ฅ์ LLM ์์คํ
- ๋ค๋จ๊ณ ํ๊ฐ", theme=gr.them
|
|
1627 |
|
1628 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
1629 |
submit_btn.click(
|
1630 |
-
fn=
|
1631 |
inputs=[user_input, llm_mode],
|
1632 |
-
outputs=[
|
1633 |
).then(
|
1634 |
fn=lambda: "",
|
1635 |
outputs=[user_input]
|
1636 |
)
|
1637 |
|
1638 |
user_input.submit(
|
1639 |
-
fn=
|
1640 |
inputs=[user_input, llm_mode],
|
1641 |
-
outputs=[
|
1642 |
).then(
|
1643 |
fn=lambda: "",
|
1644 |
outputs=[user_input]
|
1645 |
)
|
1646 |
|
1647 |
clear_btn.click(
|
1648 |
-
fn=
|
1649 |
-
outputs=[
|
1650 |
)
|
1651 |
-
|
1652 |
|
1653 |
if __name__ == "__main__":
|
1654 |
-
app.queue()
|
1655 |
app.launch(
|
1656 |
server_name="0.0.0.0",
|
1657 |
server_port=7860,
|
1658 |
share=True,
|
1659 |
show_error=True
|
1660 |
-
)
|
1661 |
-
|
|
|
38 |
# ์ ์ญ ๋ณ์
|
39 |
conversation_history = []
|
40 |
|
41 |
+
class WuxingLLMSystem:
|
42 |
+
"""์คํยท์ค์ ๊ธฐ๋ฐ ํ๋ ฅ์ LLM ์์คํ
"""
|
43 |
+
|
44 |
def __init__(self):
|
45 |
self.token = FRIENDLI_TOKEN
|
46 |
self.bapi_token = BAPI_TOKEN
|
|
|
52 |
self.use_gemini = False
|
53 |
self.gemini_client = None
|
54 |
|
55 |
+
# ์คํ ์ญํ ์ ์
|
56 |
+
self.wuxing_roles = {
|
57 |
+
"wood": {
|
58 |
+
"name": "๊ฐ๋
๊ด (ํ์ฅ)",
|
59 |
+
"virtue": "ไป",
|
60 |
+
"element": "ๆจ",
|
61 |
+
"traits": "ํฌ์ฉยท์ฑ์ฅํ ๋ฆฌ๋",
|
62 |
+
"expertise": "๋น์ ์ ์, ํ ์กฐ์จ, ์ธ์ฌ ์ก์ฑ",
|
63 |
+
"color": "#10b981" # Green
|
64 |
+
},
|
65 |
+
"fire": {
|
66 |
+
"name": "์ ๋ตยท๊ธฐํ ๋ฆฌ๋",
|
67 |
+
"virtue": "็พฉ",
|
68 |
+
"element": "็ซ",
|
69 |
+
"traits": "์ด์ ยท๊ฒฐ๋จ, ๊ฐ์ฒ ์ ์ ",
|
70 |
+
"expertise": "์คยท์ฅ๊ธฐ ๋ก๋๋งต, ์ฌ์
๋ชจ๋ธ ์ค๊ณ, ๋ฆฌ์คํฌ-๋ณด์ ์๋๋ฆฌ์ค",
|
71 |
+
"color": "#ef4444" # Red
|
72 |
+
},
|
73 |
+
"metal": {
|
74 |
+
"name": "์ํคํ
์ฒ & ํ์ค ์ฑ
์",
|
75 |
+
"virtue": "็ฆฎ",
|
76 |
+
"element": "้",
|
77 |
+
"traits": "๊ตฌ์กฐํยท์ ๋ฐ, ์์คํ
์ค๊ณ ๋ง์คํฐ",
|
78 |
+
"expertise": "๊ธฐ์ ยท๋ฐ์ดํฐ ์ํคํ
์ฒ, ํ์ค ์๋ฆฝ, ํ์งยทํ์ฅ์ฑ ๊ฒ์ฆ",
|
79 |
+
"color": "#f59e0b" # Gold
|
80 |
+
},
|
81 |
+
"water": {
|
82 |
+
"name": "๋๊ตฌ ํ์ฉ R&D ์คํ์
๋ฆฌ์คํธ",
|
83 |
+
"virtue": "ๆบ",
|
84 |
+
"element": "ๆฐด",
|
85 |
+
"traits": "๋ถ์ยทํธ๊ธฐ์ฌ, ITยทAI ๋๊ตฌ ์ ๋ฌธ๊ฐ",
|
86 |
+
"expertise": "์ต์ ๊ธฐ์ ยท์์ฅ ์กฐ์ฌ, ํ๋กํ ํ์
๊ฐ๋ฐ, ์๋ํยท์์ฐ์ฑ ํด",
|
87 |
+
"color": "#3b82f6" # Blue
|
88 |
+
},
|
89 |
+
"earth": {
|
90 |
+
"name": "์คํยท์ด์ยทํ์ง ๋ด๋น",
|
91 |
+
"virtue": "ไฟก",
|
92 |
+
"element": "ๅ",
|
93 |
+
"traits": "์ ๋ขฐยท์ฑ์ค, ์คํ๋ ฅ",
|
94 |
+
"expertise": "์ผ์ ยท์์ฐยท๋ฆฌ์์ค ๊ด๋ฆฌ, ์ด์ ์ต์ ํ, ํ์ง ๋ณด์ฆ",
|
95 |
+
"color": "#a855f7" # Purple
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
if self.test_mode:
|
100 |
logger.warning("ํ
์คํธ ๋ชจ๋๋ก ์คํ๋ฉ๋๋ค.")
|
|
|
|
|
|
|
|
|
101 |
|
102 |
def set_llm_mode(self, mode: str):
|
103 |
+
"""LLM ๋ชจ๋ ์ค์ """
|
104 |
if mode == "commercial" and GEMINI_AVAILABLE and self.gemini_api_key != "YOUR_GEMINI_API_KEY":
|
105 |
self.use_gemini = True
|
106 |
if not self.gemini_client:
|
|
|
109 |
else:
|
110 |
self.use_gemini = False
|
111 |
logger.info("๊ธฐ๋ณธ LLM ๋ชจ๋๋ก ์ ํ๋์์ต๋๋ค.")
|
112 |
+
|
113 |
def create_headers(self):
|
114 |
"""API ํค๋ ์์ฑ"""
|
115 |
return {
|
|
|
125 |
"X-Subscription-Token": self.bapi_token
|
126 |
}
|
127 |
|
128 |
+
def create_wood_initial_prompt(self, user_query: str) -> str:
|
129 |
+
"""ๆจ(๊ฐ๋
๊ด) ์ด๊ธฐ ํ๋กฌํํธ"""
|
130 |
+
return f"""๋น์ ์ ไป(์ธ์ํจ)์ ๋๋ชฉ์ ์ง๋ ๆจ์ ๊ธฐ์ด์ ๊ฐ์ง ๊ฐ๋
๊ด์
๋๋ค.
|
131 |
+
ํฌ์ฉ์ ์ด๊ณ ์ฑ์ฅ์งํฅ์ ์ธ ๋ฆฌ๋์ญ์ผ๋ก ํ์ ์ด๋๋๋ค.
|
132 |
|
133 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
134 |
|
135 |
+
ํ์ฅ์ผ๋ก์ ์ด ์ง๋ฌธ์ ๋ํด:
|
136 |
+
1. ์ ์ฒด์ ์ธ ๋น์ ๊ณผ ๋ฐฉํฅ์ฑ์ ์ ์ํ์ธ์
|
137 |
+
2. ๊ฐ ํ์(็ซ, ๅ, ้, ๆฐด)์ ์ญํ ๊ณผ ๊ธฐ์ฌ ๋ฐฉํฅ์ ์ค๊ณํ์ธ์
|
138 |
+
3. ์ฑ์ฅ๊ณผ ๋ฐ์ ์ ๊ด์ ์์ ํต์ฌ ๋ชฉํ๋ฅผ ์ค์ ํ์ธ์
|
139 |
+
4. ํ ์ ์ฒด๊ฐ ์กฐํ๋กญ๊ฒ ํ๋ ฅํ ์ ์๋ ํ๋ ์์ํฌ๋ฅผ ์ ์ํ์ธ์
|
140 |
|
141 |
+
[ํต์ฌ ํค์๋]: 5-7๊ฐ์ ์กฐ์ฌ๊ฐ ํ์ํ ํค์๋๋ฅผ ์ ์ํ์ธ์"""
|
|
|
142 |
|
143 |
+
def create_fire_strategy_prompt(self, user_query: str, wood_response: str, critic_feedback: str) -> str:
|
144 |
+
"""็ซ(์ ๋ต๊ธฐํ) ํ๋กฌํํธ"""
|
145 |
+
return f"""๋น์ ์ ็พฉ(์ ์๋ก์)์ ๋๋ชฉ์ ์ง๋ ็ซ์ ๊ธฐ์ด์ ๊ฐ์ง ์ ๋ตยท๊ธฐํ ๋ฆฌ๋์
๋๋ค.
|
146 |
+
์ด์ ๊ณผ ๊ฒฐ๋จ๋ ฅ์ผ๋ก ํ์ ์ ์ธ ์ ๋ต์ ์๋ฆฝํฉ๋๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
149 |
|
150 |
+
๊ฐ๋
๊ด(ๆจ)์ ๋น์ :
|
151 |
+
{wood_response}
|
152 |
|
153 |
+
๋นํ์์ ํผ๋๋ฐฑ:
|
154 |
+
{critic_feedback}
|
|
|
155 |
|
156 |
+
์ ๋ต๊ธฐํ ๋ฆฌ๋๋ก์:
|
157 |
+
1. ์คยท์ฅ๊ธฐ ๋ก๋๋งต์ ๊ตฌ์ฒด์ ์ผ๋ก ์๋ฆฝํ์ธ์
|
158 |
+
2. ํ์ ์ ์ธ ์ฌ์
๋ชจ๋ธ์ ์ค๊ณํ์ธ์
|
159 |
+
3. ๋ฆฌ์คํฌ์ ๊ธฐํ ๋ถ์์ ์ํํ์ธ์
|
160 |
+
4. ๊ฒฝ์ ์ฐ์ ํ๋ณด ์ ๋ต์ ์ ์ํ์ธ์
|
161 |
+
5. ๋นํ์์ ํผ๋๋ฐฑ์ ๋ฐ์ํ์ฌ ์ ๋ต์ ๋ณด์ํ์ธ์"""
|
|
|
162 |
|
163 |
+
def create_earth_execution_prompt(self, user_query: str, fire_response: str, critic_feedback: str, search_results: Dict) -> str:
|
164 |
+
"""ๅ(์คํ์ด์) ํ๋กฌํํธ"""
|
165 |
+
return f"""๋น์ ์ ไฟก(์ ๋ขฐ)์ ๋๋ชฉ์ ์ง๋ ๅ์ ๊ธฐ์ด์ ๊ฐ์ง ์คํยท์ด์ยทํ์ง ๋ด๋น์์
๋๋ค.
|
166 |
+
์ฑ์คํจ๊ณผ ์คํ๋ ฅ์ผ๋ก ๊ณํ์ ํ์ค๋ก ๋ง๋ญ๋๋ค.
|
167 |
|
168 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
169 |
|
170 |
+
์ ๋ต๊ธฐํ(็ซ)์ ์ ๋ต:
|
171 |
+
{fire_response}
|
172 |
+
|
173 |
+
๋นํ์์ ํผ๋๋ฐฑ:
|
174 |
+
{critic_feedback}
|
175 |
+
|
176 |
+
์น ๊ฒ์ ๊ฒฐ๊ณผ:
|
177 |
+
{self._format_search_results(search_results)}
|
178 |
|
179 |
+
์คํ์ด์ ๋ด๋น์๋ก์:
|
180 |
+
1. ๊ตฌ์ฒด์ ์ธ ์คํ ๊ณํ๊ณผ ์ผ์ ์ ์๋ฆฝํ์ธ์
|
181 |
+
2. ํ์ํ ๋ฆฌ์์ค์ ์์ฐ์ ์ฐ์ ํ์ธ์
|
182 |
+
3. ํ์ง ๊ด๋ฆฌ ๊ธฐ์ค๊ณผ ํ๋ก์ธ์ค๋ฅผ ์ ์ํ์ธ์
|
183 |
+
4. ๋ฆฌ์คํฌ ๋์ ๊ณํ์ ์๋ฆฝํ์ธ์
|
184 |
+
5. ์ฑ๊ณผ ์ธก์ ์งํ๋ฅผ ์ค์ ํ์ธ์"""
|
185 |
|
186 |
+
def create_metal_architecture_prompt(self, user_query: str, earth_response: str, critic_feedback: str) -> str:
|
187 |
+
"""้(์ํคํ
์ฒ) ํ๋กฌํํธ"""
|
188 |
+
return f"""๋น์ ์ ็ฆฎ(์์ยท์ง์)์ ๋๋ชฉ์ ์ง๋ ้์ ๊ธฐ์ด์ ๊ฐ์ง ์ํคํ
์ฒ & ํ์ค ์ฑ
์์์
๋๋ค.
|
189 |
+
์ ๋ฐํจ๊ณผ ๊ตฌ์กฐํ ๋ฅ๋ ฅ์ผ๋ก ์๋ฒฝํ ์์คํ
์ ์ค๊ณํฉ๋๋ค.
|
190 |
|
191 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
192 |
|
193 |
+
์คํ์ด์(ๅ)์ ๊ณํ:
|
194 |
+
{earth_response}
|
195 |
|
196 |
+
๋นํ์์ ํผ๋๋ฐฑ:
|
197 |
+
{critic_feedback}
|
198 |
|
199 |
+
์ํคํ
์ฒ ์ฑ
์์๋ก์:
|
200 |
+
1. ์ ์ฒด ์์คํ
์ ๊ธฐ์ ยท๋ฐ์ดํฐ ์ํคํ
์ฒ๋ฅผ ์ค๊ณํ์ธ์
|
201 |
+
2. ์ฝ๋ฉ/APIยท๋ฐ์ดํฐยท๋ณด์ ํ์ค์ ์๋ฆฝํ์ธ์
|
202 |
+
3. ํ์ฅ์ฑ๊ณผ ํธํ์ฑ์ ๊ณ ๋ คํ ํ๋ ์์ํฌ๋ฅผ ์ ์ํ์ธ์
|
203 |
+
4. ํ์ง ๊ฒ์ฆ ์ฒด๊ณ์ ๊ธฐ์ค์ ์ ์ํ์ธ์
|
204 |
+
5. ๊ธฐ์ ์ ์ ์ฝ์ฌํญ๊ณผ ํด๊ฒฐ๋ฐฉ์์ ์ ์ํ์ธ์"""
|
205 |
|
206 |
+
def create_water_rd_prompt(self, user_query: str, metal_response: str, critic_feedback: str, search_results: Dict) -> str:
|
207 |
+
"""ๆฐด(R&D) ํ๋กฌํํธ"""
|
208 |
+
return f"""๋น์ ์ ๆบ(์งํ)์ ๋๋ชฉ์ ์ง๋ ๆฐด์ ๊ธฐ์ด์ ๊ฐ์ง ๋๊ตฌ ํ์ฉ R&D ์คํ์
๋ฆฌ์คํธ์
๋๋ค.
|
209 |
+
๋ถ์๋ ฅ๊ณผ ํธ๊ธฐ์ฌ์ผ๋ก ์ต์ ๊ธฐ์ ์ ํ๊ตฌํ๊ณ ํ์ ํฉ๋๋ค.
|
210 |
|
211 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
212 |
|
213 |
+
์ํคํ
์ฒ(้)์ ์ค๊ณ:
|
214 |
+
{metal_response}
|
215 |
|
216 |
+
๋นํ์์ ํผ๋๋ฐฑ:
|
217 |
+
{critic_feedback}
|
218 |
|
219 |
+
์ต์ ๊ธฐ์ ์กฐ์ฌ ๊ฒฐ๊ณผ:
|
220 |
+
{self._format_search_results(search_results)}
|
221 |
|
222 |
+
R&D ์คํ์
๋ฆฌ์คํธ๋ก์:
|
223 |
+
1. ์ต์ ๊ธฐ์ ํธ๋ ๋์ ๋๊ตฌ๋ฅผ ๋ถ์ํ์ธ์
|
224 |
+
2. ํ์ ์ ์ธ ํ๋กํ ํ์
๊ฐ๋ฐ ๋ฐฉ์์ ์ ์ํ์ธ์
|
225 |
+
3. ์๋ํ์ ์์ฐ์ฑ ํฅ์ ๋๊ตฌ๋ฅผ ์ถ์ฒํ์ธ์
|
226 |
+
4. ๊ธฐ์ ๋์
์ ROI์ ์คํ ๊ฐ๋ฅ์ฑ์ ํ๊ฐํ์ธ์
|
227 |
+
5. ํ ๊ต์ก๊ณผ ๊ธฐ์ ์ ํ ๊ณํ์ ์๋ฆฝํ์ธ์"""
|
228 |
|
229 |
+
def create_wood_final_prompt(self, user_query: str, all_responses: Dict, all_critics: List) -> str:
|
230 |
+
"""ๆจ(๊ฐ๋
๊ด) ์ต์ข
์ข
ํฉ ํ๋กฌํํธ"""
|
231 |
+
return f"""๋น์ ์ ไป(์ธ์ํจ)์ ๋๋ชฉ์ ์ง๋ ๆจ์ ๊ธฐ์ด์ ๊ฐ์ง ๊ฐ๋
๊ด์
๋๋ค.
|
232 |
+
ํ ์ ์ฒด์ ์๊ฒฌ์ ์ข
ํฉํ์ฌ ์ต์ข
๊ฒฐ์ ์ ๋ด๋ฆฝ๋๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
|
234 |
์ฌ์ฉ์ ์ง๋ฌธ: {user_query}
|
235 |
|
236 |
+
ํ์๋ค์ ๊ธฐ์ฌ:
|
237 |
+
- ็ซ(์ ๋ต๊ธฐํ): {all_responses['fire']}
|
238 |
+
- ๅ(์คํ์ด์): {all_responses['earth']}
|
239 |
+
- ้(์ํคํ
์ฒ): {all_responses['metal']}
|
240 |
+
- ๆฐด(R&D): {all_responses['water']}
|
241 |
|
242 |
+
๋นํ์์ ํผ๋๋ฐฑ ์ด๋ ฅ:
|
243 |
+
{self._format_critic_history(all_critics)}
|
244 |
|
245 |
+
ํ์ฅ์ผ๋ก์ ์ต์ข
์ข
ํฉ ๋ณด๊ณ ์๋ฅผ ์์ฑํ์ธ์:
|
246 |
+
1. ๊ฐ ํ์์ ๊ธฐ์ฌ๋ฅผ ํตํฉํ ์ข
ํฉ ์๋ฃจ์
|
247 |
+
2. ์คํ ์ฐ์ ์์์ ๋จ๊ณ๋ณ ๋ก๋๋งต
|
248 |
+
3. ์์ ์ฑ๊ณผ์ ์ฑ๊ณต ์งํ
|
249 |
+
4. ํ ์ ์ฒด์ ์๋์ง ์ฐฝ์ถ ๋ฐฉ์
|
250 |
+
5. ์ง์์ ๊ฐ์ ๊ณผ ๏ฟฝ๏ฟฝ์ฅ ๊ณํ
|
|
|
|
|
|
|
|
|
251 |
|
252 |
+
๋งํฌ๋ค์ด ํ์์ ํ์ฉํ์ฌ ์ ๋ฌธ์ ์ด๊ณ ์ฒด๊ณ์ ์ผ๋ก ์์ฑํ์ธ์."""
|
253 |
|
254 |
+
def create_critic_prompt(self, stage: str, content: str, context: str = "") -> str:
|
255 |
+
"""์ค๋ฆฝ์ ๋นํ์ ํ๋กฌํํธ"""
|
256 |
+
return f"""๋น์ ์ ์ค๋ฆฝ์ ์ด๊ณ ๋
ผ๋ฆฌ์ ์ธ ๋นํ์์
๋๋ค.
|
257 |
+
ํธ๊ฒฌ ์์ด ํฉ๋ฆฌ์ ์ด๊ณ ๊ฑด์ค์ ์ธ ๋นํ์ ์ ๊ณตํฉ๋๋ค.
|
258 |
+
|
259 |
+
ํ์ฌ ๋จ๊ณ: {stage}
|
260 |
+
|
261 |
+
๋ถ์ ๋์:
|
262 |
+
{content}
|
263 |
+
|
264 |
+
{f"์ด์ ๋งฅ๋ฝ: {context}" if context else ""}
|
265 |
+
|
266 |
+
๋ค์ ๊ด์ ์์ ๋นํํ์ธ์:
|
267 |
+
1. ๋
ผ๋ฆฌ์ ์ผ๊ด์ฑ๊ณผ ํ๋น์ฑ
|
268 |
+
2. ์คํ ๊ฐ๋ฅ์ฑ๊ณผ ์ค์ฉ์ฑ
|
269 |
+
3. ๋๋ฝ๋ ์ค์ ์์
|
270 |
+
4. ๊ฐ์ ๊ฐ๋ฅํ ๋ถ๋ถ
|
271 |
+
5. ๊ฐ์ ๊ณผ ์ฝ์ ์ ๊ท ํ์กํ ํ๊ฐ
|
272 |
+
|
273 |
+
๊ฑด์ค์ ์ด๊ณ ๊ตฌ์ฒด์ ์ธ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋, ๋ค์ ๋จ๊ณ ๋ด๋น์๊ฐ
|
274 |
+
๊ฐ์ ํ ์ ์๋ ์ค์ง์ ์ธ ์ ์์ ํฌํจํ์ธ์."""
|
275 |
+
|
276 |
+
def _format_search_results(self, search_results: Dict) -> str:
|
277 |
+
"""๊ฒ์ ๊ฒฐ๊ณผ ํฌ๋งทํ
"""
|
278 |
+
if not search_results:
|
279 |
+
return "๊ฒ์ ๊ฒฐ๊ณผ ์์"
|
280 |
+
|
281 |
+
formatted = ""
|
282 |
+
for keyword, results in search_results.items():
|
283 |
+
formatted += f"\n**{keyword}:**\n"
|
284 |
+
for i, result in enumerate(results[:5], 1):
|
285 |
+
formatted += f"{i}. {result.get('title', 'N/A')} (์ ๋ขฐ๋: {result.get('credibility_score', 0):.2f})\n"
|
286 |
+
formatted += f" {result.get('description', 'N/A')[:150]}...\n"
|
287 |
+
return formatted
|
288 |
+
|
289 |
+
def _format_critic_history(self, critics: List) -> str:
|
290 |
+
"""๋นํ ์ด๋ ฅ ํฌ๋งทํ
"""
|
291 |
+
if not critics:
|
292 |
+
return "๋นํ ์ด๋ ฅ ์์"
|
293 |
+
|
294 |
+
formatted = ""
|
295 |
+
stages = ["ๆจ ์ด๊ธฐ", "็ซ ์ ๋ต", "ๅ ์คํ", "้ ์ํคํ
์ฒ", "ๆฐด R&D"]
|
296 |
+
for i, critic in enumerate(critics):
|
297 |
+
if i < len(stages):
|
298 |
+
formatted += f"\n**{stages[i]} ๋จ๊ณ ๋นํ:**\n{critic}\n"
|
299 |
+
return formatted
|
300 |
+
|
301 |
+
def extract_keywords(self, wood_response: str) -> List[str]:
|
302 |
+
"""๊ฐ๋
๊ด ์๋ต์์ ํค์๋ ์ถ์ถ"""
|
303 |
keywords = []
|
304 |
|
305 |
+
keyword_match = re.search(r'\[ํต์ฌ ํค์๋\]:\s*(.+)', wood_response, re.IGNORECASE)
|
|
|
306 |
if keyword_match:
|
307 |
keyword_str = keyword_match.group(1)
|
308 |
keywords = [k.strip() for k in keyword_str.split(',') if k.strip()]
|
309 |
|
|
|
310 |
if not keywords:
|
311 |
+
keywords = ["best practices", "implementation", "strategy", "innovation", "optimization"]
|
312 |
|
313 |
+
return keywords[:7]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
def calculate_credibility_score(self, result: Dict) -> float:
|
316 |
+
"""๊ฒ์ ๊ฒฐ๊ณผ ์ ๋ขฐ๋ ๊ณ์ฐ"""
|
317 |
+
score = 0.5
|
|
|
318 |
url = result.get('url', '')
|
|
|
|
|
319 |
|
320 |
+
trusted_domains = ['.edu', '.gov', '.org', 'wikipedia.org', 'nature.com',
|
321 |
+
'ieee.org', 'acm.org', 'github.com']
|
|
|
|
|
|
|
|
|
322 |
|
323 |
for domain in trusted_domains:
|
324 |
if domain in url:
|
325 |
score += 0.2
|
326 |
break
|
327 |
|
|
|
328 |
if url.startswith('https://'):
|
329 |
score += 0.1
|
330 |
|
331 |
+
if len(result.get('title', '')) > 20:
|
|
|
332 |
score += 0.05
|
333 |
+
if len(result.get('description', '')) > 50:
|
334 |
score += 0.05
|
335 |
|
336 |
+
spam_keywords = ['buy now', 'sale', 'discount', 'click here']
|
337 |
+
if any(spam in (result.get('title', '') + result.get('description', '')).lower()
|
338 |
+
for spam in spam_keywords):
|
339 |
score -= 0.3
|
340 |
|
341 |
+
return max(0, min(1, score))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
|
343 |
def brave_search(self, query: str) -> List[Dict]:
|
344 |
"""Brave Search API ํธ์ถ"""
|
345 |
if self.test_mode or self.bapi_token == "YOUR_BRAVE_API_TOKEN":
|
|
|
346 |
test_results = []
|
347 |
for i in range(5):
|
348 |
test_results.append({
|
349 |
+
"title": f"{query} - Best Practices {i+1}",
|
350 |
+
"description": f"Comprehensive guide on {query} with proven methodologies.",
|
351 |
"url": f"https://example{i+1}.com/{query.replace(' ', '-')}",
|
352 |
"credibility_score": 0.7 + (i * 0.05)
|
353 |
})
|
|
|
356 |
try:
|
357 |
params = {
|
358 |
"q": query,
|
359 |
+
"count": 10,
|
360 |
+
"safesearch": "moderate"
|
|
|
361 |
}
|
362 |
|
363 |
response = requests.get(
|
|
|
370 |
if response.status_code == 200:
|
371 |
data = response.json()
|
372 |
results = []
|
373 |
+
for item in data.get("web", {}).get("results", []):
|
374 |
result = {
|
375 |
"title": item.get("title", ""),
|
376 |
"description": item.get("description", ""),
|
377 |
"url": item.get("url", ""),
|
378 |
+
"credibility_score": self.calculate_credibility_score(item)
|
379 |
}
|
|
|
|
|
380 |
results.append(result)
|
381 |
|
|
|
382 |
results.sort(key=lambda x: x['credibility_score'], reverse=True)
|
383 |
return results
|
384 |
else:
|
|
|
389 |
logger.error(f"Brave ๊ฒ์ ์ค ์ค๋ฅ: {str(e)}")
|
390 |
return []
|
391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
def call_gemini_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
393 |
"""Gemini API ์คํธ๋ฆฌ๋ฐ ํธ์ถ"""
|
394 |
if not self.gemini_client:
|
|
|
396 |
return
|
397 |
|
398 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
contents = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
for msg in messages:
|
401 |
if msg["role"] == "user":
|
402 |
contents.append(types.Content(
|
|
|
404 |
parts=[types.Part.from_text(text=msg["content"])]
|
405 |
))
|
406 |
|
|
|
407 |
generate_content_config = types.GenerateContentConfig(
|
408 |
temperature=0.7,
|
409 |
top_p=0.8,
|
|
|
411 |
response_mime_type="text/plain"
|
412 |
)
|
413 |
|
|
|
414 |
for chunk in self.gemini_client.models.generate_content_stream(
|
415 |
model="gemini-2.5-pro",
|
416 |
contents=contents,
|
|
|
425 |
|
426 |
def call_llm_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
427 |
"""์คํธ๋ฆฌ๋ฐ LLM API ํธ์ถ"""
|
|
|
|
|
428 |
if self.use_gemini:
|
429 |
yield from self.call_gemini_streaming(messages, role)
|
430 |
return
|
431 |
|
|
|
432 |
if self.test_mode:
|
433 |
+
test_response = f"์ด๊ฒ์ {role} ์ญํ ์ ํ
์คํธ ์๋ต์
๋๋ค.\n"
|
434 |
+
test_response += f"์ฌ์ฉ์ ์ง๋ฌธ์ ๋ํ {role}์ ๊ด์ ์์ ๋ถ์ํ ๋ด์ฉ์
๋๋ค.\n"
|
435 |
+
test_response += "1. ์ฒซ ๋ฒ์งธ ํต์ฌ ํฌ์ธํธ\n2. ๋ ๋ฒ์งธ ํต์ฌ ํฌ์ธํธ\n3. ์ธ ๋ฒ์งธ ํต์ฌ ํฌ์ธํธ"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
|
437 |
+
words = test_response.split()
|
438 |
+
for i in range(0, len(words), 3):
|
439 |
+
chunk = " ".join(words[i:i+3])
|
440 |
+
yield chunk + " "
|
441 |
+
time.sleep(0.05)
|
442 |
return
|
443 |
|
|
|
444 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
payload = {
|
446 |
"model": self.model_id,
|
447 |
+
"messages": messages,
|
448 |
"max_tokens": 4096,
|
449 |
"temperature": 0.7,
|
450 |
+
"stream": True
|
|
|
|
|
451 |
}
|
452 |
|
|
|
|
|
453 |
response = requests.post(
|
454 |
self.api_url,
|
455 |
headers=self.create_headers(),
|
|
|
459 |
)
|
460 |
|
461 |
if response.status_code != 200:
|
462 |
+
yield f"โ API ์ค๋ฅ: {response.status_code}"
|
|
|
463 |
return
|
464 |
|
465 |
for line in response.iter_lines():
|
|
|
478 |
except json.JSONDecodeError:
|
479 |
continue
|
480 |
|
|
|
|
|
|
|
|
|
481 |
except Exception as e:
|
482 |
logger.error(f"์คํธ๋ฆฌ๋ฐ ์ค ์ค๋ฅ: {str(e)}")
|
483 |
yield f"โ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
484 |
|
485 |
# ์์คํ
์ธ์คํด์ค ์์ฑ
|
486 |
+
wuxing_system = WuxingLLMSystem()
|
487 |
|
488 |
+
def process_wuxing_query(user_query: str, llm_mode: str):
|
489 |
+
"""์คํ ๊ธฐ๋ฐ ์ฟผ๋ฆฌ ์ฒ๋ฆฌ"""
|
|
|
|
|
|
|
|
|
|
|
490 |
if not user_query:
|
491 |
+
return "", "", "", "", "", "", "โ ์ง๋ฌธ์ ์
๋ ฅํด์ฃผ์ธ์."
|
492 |
|
493 |
+
wuxing_system.set_llm_mode(llm_mode)
|
|
|
494 |
|
495 |
+
all_responses = {}
|
496 |
+
all_critics = []
|
497 |
+
search_results = {}
|
498 |
|
499 |
try:
|
500 |
+
# 1. ๆจ(๊ฐ๋
๊ด) ์ด๊ธฐ ๋ถ์
|
501 |
+
wood_prompt = wuxing_system.create_wood_initial_prompt(user_query)
|
502 |
+
wood_response = ""
|
503 |
|
504 |
+
wood_text = "๐ณ **ๆจ - ๊ฐ๋
๊ด** (ไป)\n๐ ๋ถ์ ์ค...\n"
|
505 |
+
for chunk in wuxing_system.call_llm_streaming(
|
506 |
+
[{"role": "user", "content": wood_prompt}], "wood"
|
|
|
507 |
):
|
508 |
+
wood_response += chunk
|
509 |
+
wood_text = f"๐ณ **ๆจ - ๊ฐ๋
๊ด** (ไป)\n{wood_response}"
|
510 |
+
yield wood_text, "", "", "", "", "", "๐ณ ๊ฐ๋
๊ด์ด ๋น์ ์ ์๋ฆฝ ์ค..."
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
|
512 |
+
all_responses['wood_initial'] = wood_response
|
|
|
|
|
513 |
|
514 |
+
# ํค์๋ ์ถ์ถ ๋ฐ ๊ฒ์
|
515 |
+
keywords = wuxing_system.extract_keywords(wood_response)
|
516 |
+
status_text = "๐ ์น ๊ฒ์ ์ํ ์ค..."
|
517 |
+
yield wood_text, "", "", "", "", "", status_text
|
518 |
|
|
|
519 |
for keyword in keywords:
|
520 |
+
results = wuxing_system.brave_search(keyword)
|
521 |
if results:
|
522 |
search_results[keyword] = results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
523 |
|
524 |
+
# 2. ๆจ ๋นํ
|
525 |
+
critic_prompt = wuxing_system.create_critic_prompt("ๆจ ์ด๊ธฐ ๋ถ์", wood_response)
|
526 |
+
critic_response = ""
|
527 |
|
528 |
+
critic_text = "๐ **์ค๋ฆฝ์ ๋นํ์**\n[ๆจ ๋ถ์ ๋นํ] ๐ ๋นํ ์ค...\n"
|
529 |
+
for chunk in wuxing_system.call_llm_streaming(
|
530 |
+
[{"role": "user", "content": critic_prompt}], "critic"
|
|
|
531 |
):
|
532 |
+
critic_response += chunk
|
533 |
+
critic_text = f"๐ **์ค๋ฆฝ์ ๋นํ์**\n[ๆจ ๋ถ์ ๋นํ]\n{critic_response}"
|
534 |
+
yield wood_text, "", "", "", "", critic_text, "๐ ๋นํ์๊ฐ ๋ถ์ ์ค..."
|
535 |
|
536 |
+
all_critics.append(critic_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
|
538 |
+
# 3. ็ซ(์ ๋ต๊ธฐํ)
|
539 |
+
fire_prompt = wuxing_system.create_fire_strategy_prompt(user_query, wood_response, critic_response)
|
540 |
+
fire_response = ""
|
541 |
|
542 |
+
fire_text = "๐ฅ **็ซ - ์ ๋ตยท๊ธฐํ ๋ฆฌ๋** (็พฉ)\n๐ ์ ๋ต ์๋ฆฝ ์ค...\n"
|
543 |
+
for chunk in wuxing_system.call_llm_streaming(
|
544 |
+
[{"role": "user", "content": fire_prompt}], "fire"
|
545 |
):
|
546 |
+
fire_response += chunk
|
547 |
+
fire_text = f"๐ฅ **็ซ - ์ ๋ตยท๊ธฐํ ๋ฆฌ๋** (็พฉ)\n{fire_response}"
|
548 |
+
yield wood_text, fire_text, "", "", "", critic_text, "๐ฅ ์ ๋ต ์๋ฆฝ ์ค..."
|
549 |
|
550 |
+
all_responses['fire'] = fire_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
551 |
|
552 |
+
# 4. ็ซ ๋นํ
|
553 |
+
critic_prompt = wuxing_system.create_critic_prompt("็ซ ์ ๋ต๊ธฐํ", fire_response, wood_response)
|
554 |
+
critic_response = ""
|
555 |
|
556 |
+
critic_text += "\n\n---\n\n[็ซ ์ ๋ต ๋นํ] ๐ ๋นํ ์ค...\n"
|
557 |
+
for chunk in wuxing_system.call_llm_streaming(
|
558 |
+
[{"role": "user", "content": critic_prompt}], "critic"
|
|
|
559 |
):
|
560 |
+
critic_response += chunk
|
561 |
+
temp_text = all_critics[0] + f"\n\n---\n\n[็ซ ์ ๋ต ๋นํ]\n{critic_response}"
|
562 |
+
critic_text = f"๐ **์ค๋ฆฝ์ ๋นํ์**\n[ๆจ ๋ถ์ ๋นํ]\n{temp_text}"
|
563 |
+
yield wood_text, fire_text, "", "", "", critic_text, "๐ ์ ๋ต ๋นํ ์ค..."
|
564 |
|
565 |
+
all_critics.append(critic_response)
|
566 |
|
567 |
+
# 5. ๅ(์คํ์ด์)
|
568 |
+
earth_prompt = wuxing_system.create_earth_execution_prompt(user_query, fire_response, critic_response, search_results)
|
569 |
+
earth_response = ""
|
570 |
|
571 |
+
earth_text = "๐๏ธ **ๅ - ์คํยท์ด์ยทํ์ง** (ไฟก)\n๐ ์คํ ๊ณํ ์๋ฆฝ ์ค...\n"
|
572 |
+
for chunk in wuxing_system.call_llm_streaming(
|
573 |
+
[{"role": "user", "content": earth_prompt}], "earth"
|
|
|
574 |
):
|
575 |
+
earth_response += chunk
|
576 |
+
earth_text = f"๐๏ธ **ๅ - ์คํยท์ด์ยทํ์ง** (ไฟก)\n{earth_response}"
|
577 |
+
yield wood_text, fire_text, earth_text, "", "", critic_text, "๐๏ธ ์คํ ๊ณํ ์๋ฆฝ ์ค..."
|
578 |
|
579 |
+
all_responses['earth'] = earth_response
|
580 |
|
581 |
+
# 6. ๅ ๋นํ
|
582 |
+
critic_prompt = wuxing_system.create_critic_prompt("ๅ ์คํ๊ณํ", earth_response, fire_response)
|
583 |
+
critic_response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
|
585 |
+
critic_text = "๐ **์ค๋ฆฝ์ ๋นํ์**\n" + "\n\n".join([
|
586 |
+
f"[ๆจ ๋ถ์ ๋นํ]\n{all_critics[0]}",
|
587 |
+
f"[็ซ ์ ๋ต ๋นํ]\n{all_critics[1]}",
|
588 |
+
"[ๅ ์คํ ๋นํ] ๐ ๋นํ ์ค...\n"
|
589 |
+
])
|
590 |
|
591 |
+
for chunk in wuxing_system.call_llm_streaming(
|
592 |
+
[{"role": "user", "content": critic_prompt}], "critic"
|
593 |
+
):
|
594 |
+
critic_response += chunk
|
595 |
+
critic_text = "๐ **์ค๋ฆฝ์ ๋นํ์**\n" + "\n\n".join([
|
596 |
+
f"[ๆจ ๋ถ์ ๋นํ]\n{all_critics[0]}",
|
597 |
+
f"[็ซ ์ ๋ต ๋นํ]\n{all_critics[1]}",
|
598 |
+
f"[ๅ ์คํ ๋นํ]\n{critic_response}"
|
599 |
+
])
|
600 |
+
yield wood_text, fire_text, earth_text, "", "", critic_text, "๐ ์คํ ๋นํ ์ค..."
|
601 |
+
|
602 |
+
all_critics.append(critic_response)
|
603 |
+
|
604 |
+
# 7. ้(์ํคํ
์ฒ)
|
605 |
+
metal_prompt = wuxing_system.create_metal_architecture_prompt(user_query, earth_response, critic_response)
|
606 |
+
metal_response = ""
|
607 |
+
|
608 |
+
metal_text = "โ๏ธ **้ - ์ํคํ
์ฒ & ํ์ค** (็ฆฎ)\n๐ ์ํคํ
์ฒ ์ค๊ณ ์ค...\n"
|
609 |
+
for chunk in wuxing_system.call_llm_streaming(
|
610 |
+
[{"role": "user", "content": metal_prompt}], "metal"
|
611 |
):
|
612 |
+
metal_response += chunk
|
613 |
+
metal_text = f"โ๏ธ **้ - ์ํคํ
์ฒ & ํ์ค** (็ฆฎ)\n{metal_response}"
|
614 |
+
yield wood_text, fire_text, earth_text, metal_text, "", critic_text, "โ๏ธ ์ํคํ
์ฒ ์ค๊ณ ์ค..."
|
|
|
615 |
|
616 |
+
all_responses['metal'] = metal_response
|
617 |
|
618 |
+
# 8. ้ ๋นํ
|
619 |
+
critic_prompt = wuxing_system.create_critic_prompt("้ ์ํคํ
์ฒ", metal_response, earth_response)
|
620 |
+
critic_response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
621 |
|
622 |
+
# ์ถ๊ฐ ๊ฒ์ ์ํ
|
623 |
+
additional_keywords = ["architecture patterns", "system design", "technical standards"]
|
624 |
+
for keyword in additional_keywords:
|
625 |
+
results = wuxing_system.brave_search(f"{user_query} {keyword}")
|
626 |
+
if results:
|
627 |
+
search_results[keyword] = results
|
628 |
|
629 |
+
# ๋นํ ์ํ
|
630 |
+
for chunk in wuxing_system.call_llm_streaming(
|
631 |
+
[{"role": "user", "content": critic_prompt}], "critic"
|
632 |
):
|
633 |
+
critic_response += chunk
|
634 |
+
yield wood_text, fire_text, earth_text, metal_text, "", critic_text, "๐ ์ํคํ
์ฒ ๋นํ ์ค..."
|
|
|
|
|
635 |
|
636 |
+
all_critics.append(critic_response)
|
637 |
|
638 |
+
# 9. ๆฐด(R&D)
|
639 |
+
water_prompt = wuxing_system.create_water_rd_prompt(user_query, metal_response, critic_response, search_results)
|
640 |
+
water_response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
641 |
|
642 |
+
water_text = "๐ง **ๆฐด - R&D ์คํ์
๋ฆฌ์คํธ** (ๆบ)\n๐ ํ์ ๋ฐฉ์ ์ฐ๊ตฌ ์ค...\n"
|
643 |
+
for chunk in wuxing_system.call_llm_streaming(
|
644 |
+
[{"role": "user", "content": water_prompt}], "water"
|
|
|
645 |
):
|
646 |
+
water_response += chunk
|
647 |
+
water_text = f"๐ง **ๆฐด - R&D ์คํ์
๋ฆฌ์คํธ** (ๆบ)\n{water_response}"
|
648 |
+
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, "๐ง ํ์ ์ฐ๊ตฌ ์ค..."
|
|
|
|
|
|
|
649 |
|
650 |
+
all_responses['water'] = water_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
651 |
|
652 |
+
# 10. ๆฐด ๋นํ
|
653 |
+
critic_prompt = wuxing_system.create_critic_prompt("ๆฐด R&D", water_response, metal_response)
|
654 |
+
critic_response = ""
|
655 |
|
656 |
+
for chunk in wuxing_system.call_llm_streaming(
|
657 |
+
[{"role": "user", "content": critic_prompt}], "critic"
|
|
|
|
|
658 |
):
|
659 |
+
critic_response += chunk
|
660 |
+
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, "๐ R&D ๋นํ ์ค..."
|
|
|
|
|
661 |
|
662 |
+
all_critics.append(critic_response)
|
663 |
|
664 |
+
# 11. ๆจ(๊ฐ๋
๊ด) ์ต์ข
์ข
ํฉ
|
665 |
+
wood_final_prompt = wuxing_system.create_wood_final_prompt(user_query, all_responses, all_critics)
|
666 |
+
wood_final_response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
|
668 |
+
wood_text += "\n\n---\n\n๐ณ **์ต์ข
์ข
ํฉ ๋ณด๊ณ ์**\n๐ ์์ฑ ์ค...\n"
|
669 |
+
for chunk in wuxing_system.call_llm_streaming(
|
670 |
+
[{"role": "user", "content": wood_final_prompt}], "wood"
|
671 |
+
):
|
672 |
+
wood_final_response += chunk
|
673 |
+
temp_text = all_responses['wood_initial'] + f"\n\n---\n\n๐ณ **์ต์ข
์ข
ํฉ ๋ณด๊ณ ์**\n{wood_final_response}"
|
674 |
+
wood_text = f"๐ณ **ๆจ - ๊ฐ๋
๊ด** (ไป)\n{temp_text}"
|
675 |
+
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, "๐ณ ์ต์ข
๋ณด๊ณ ์ ์์ฑ ์ค..."
|
676 |
|
677 |
+
status_text = f"โ
์คํ ํ๋ ฅ ํ๋ก์ธ์ค ์๋ฃ! ({len(search_results)} ํค์๋, {sum(len(r) for r in search_results.values())} ๊ฒ์๊ฒฐ๊ณผ)"
|
678 |
+
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, status_text
|
679 |
|
680 |
except Exception as e:
|
681 |
error_msg = f"โ ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {str(e)}"
|
682 |
+
yield "", "", "", "", "", "", error_msg
|
683 |
|
684 |
+
def clear_wuxing():
|
685 |
+
"""์ด๊ธฐํ"""
|
686 |
+
return "", "", "", "", "", "", "๐ ์ด๊ธฐํ๋์์ต๋๋ค."
|
|
|
|
|
687 |
|
688 |
+
# CSS ์คํ์ผ
|
689 |
css = """
|
690 |
.gradio-container {
|
691 |
font-family: 'Arial', sans-serif;
|
692 |
}
|
693 |
+
.wood-box textarea {
|
|
|
|
|
|
|
|
|
|
|
694 |
border-left: 4px solid #10b981 !important;
|
|
|
695 |
background-color: #f0fdf4 !important;
|
696 |
}
|
697 |
+
.fire-box textarea {
|
698 |
+
border-left: 4px solid #ef4444 !important;
|
699 |
+
background-color: #fef2f2 !important;
|
700 |
+
}
|
701 |
+
.earth-box textarea {
|
702 |
+
border-left: 4px solid #a855f7 !important;
|
703 |
background-color: #faf5ff !important;
|
704 |
}
|
705 |
+
.metal-box textarea {
|
706 |
border-left: 4px solid #f59e0b !important;
|
|
|
707 |
background-color: #fffbeb !important;
|
708 |
}
|
709 |
+
.water-box textarea {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
710 |
border-left: 4px solid #3b82f6 !important;
|
711 |
+
background-color: #eff6ff !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
712 |
}
|
713 |
+
.critic-box textarea {
|
714 |
+
border-left: 4px solid #6b7280 !important;
|
715 |
+
background-color: #f9fafb !important;
|
716 |
}
|
717 |
+
h1 {
|
718 |
+
text-align: center;
|
719 |
+
color: #1f2937;
|
720 |
}
|
721 |
"""
|
722 |
|
723 |
+
# Gradio ์ธํฐํ์ด์ค
|
724 |
+
with gr.Blocks(title="์คํยท์ค์ ํ๋ ฅ ์์คํ
", theme=gr.themes.Soft(), css=css) as app:
|
725 |
gr.Markdown(
|
726 |
"""
|
727 |
+
# ๐ ์คํยท์ค์ ๊ธฐ๋ฐ ํ๋ ฅ์ LLM ์์คํ
|
728 |
+
|
729 |
+
### ๐ ํ๋ก์ธ์ค: ๆจโ๋นํโ็ซโ๋นํโๅโ๋นํโ้โ๋นํโๆฐดโ๋นํโๆจ(์ต์ข
)
|
730 |
+
|
731 |
+
| ์ญํ | ๋๋ชฉยท์คํ | ํต์ฌ ์ ๋ฌธ์ฑ |
|
732 |
+
|------|-----------|-------------|
|
733 |
+
| ๐ณ **๊ฐ๋
๊ด** | ไปยทๆจ | ๋น์ ์ ์, ํ ์กฐ์จ, ์ธ์ฌ ์ก์ฑ |
|
734 |
+
| ๐ฅ **์ ๋ต๊ธฐํ** | ็พฉยท็ซ | ๋ก๋๋งต, ์ฌ์
๋ชจ๋ธ, ๋ฆฌ์คํฌ ๋ถ์ |
|
735 |
+
| ๐๏ธ **์คํ์ด์** | ไฟกยทๅ | ์ผ์ ยท์์ฐ ๊ด๋ฆฌ, ํ์ง ๋ณด์ฆ |
|
736 |
+
| โ๏ธ **์ํคํ
์ฒ** | ็ฆฎยท้ | ์์คํ
์ค๊ณ, ํ์ค ์๋ฆฝ, ํ์ง ๊ฒ์ฆ |
|
737 |
+
| ๐ง **R&D** | ๆบยทๆฐด | ๊ธฐ์ ์กฐ์ฌ, ํ๋กํ ํ์
, ํ์ ๋๊ตฌ |
|
738 |
+
| ๐ **๋นํ์** | ์ค๋ฆฝ | ๋
ผ๋ฆฌ์ ยท๊ฑด์ค์ ํผ๋๋ฐฑ |
|
739 |
"""
|
740 |
)
|
741 |
|
|
|
742 |
with gr.Row():
|
743 |
+
with gr.Column(scale=3):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
744 |
llm_mode = gr.Radio(
|
745 |
choices=["default", "commercial"],
|
746 |
value="default",
|
747 |
+
label="LLM ๋ชจ๋",
|
748 |
+
info="commercial: Gemini 2.5 Pro ์ฌ์ฉ"
|
749 |
)
|
750 |
|
751 |
user_input = gr.Textbox(
|
752 |
label="์ง๋ฌธ ์
๋ ฅ",
|
753 |
+
placeholder="์: ์ง์ ๊ฐ๋ฅํ ์ค๋งํธ์ํฐ ๊ตฌ์ถ ์ ๋ต์?",
|
754 |
lines=3
|
755 |
)
|
756 |
|
757 |
with gr.Row():
|
758 |
submit_btn = gr.Button("๐ ๋ถ์ ์์", variant="primary", scale=2)
|
759 |
clear_btn = gr.Button("๐๏ธ ์ด๊ธฐํ", scale=1)
|
760 |
+
|
761 |
+
with gr.Column(scale=1):
|
762 |
status_text = gr.Textbox(
|
763 |
+
label="์งํ ์ํ",
|
764 |
interactive=False,
|
765 |
value="๋๊ธฐ ์ค...",
|
766 |
+
lines=3
|
767 |
)
|
768 |
|
769 |
+
# ์คํ ์ถ๋ ฅ - 2x3 ๊ทธ๋ฆฌ๋
|
770 |
with gr.Row():
|
771 |
with gr.Column():
|
772 |
+
gr.Markdown("### ๐ณ ๆจ - ๊ฐ๋
๊ด (ไป)")
|
773 |
+
wood_output = gr.Textbox(
|
774 |
+
label="",
|
775 |
+
lines=10,
|
776 |
+
max_lines=15,
|
777 |
+
interactive=False,
|
778 |
+
elem_classes=["wood-box"]
|
779 |
+
)
|
780 |
+
|
781 |
+
with gr.Column():
|
782 |
+
gr.Markdown("### ๐ฅ ็ซ - ์ ๋ตยท๊ธฐํ (็พฉ)")
|
783 |
+
fire_output = gr.Textbox(
|
784 |
+
label="",
|
785 |
+
lines=10,
|
786 |
+
max_lines=15,
|
787 |
+
interactive=False,
|
788 |
+
elem_classes=["fire-box"]
|
789 |
)
|
790 |
|
|
|
791 |
with gr.Row():
|
|
|
792 |
with gr.Column():
|
793 |
+
gr.Markdown("### ๐๏ธ ๅ - ์คํยท์ด์ (ไฟก)")
|
794 |
+
earth_output = gr.Textbox(
|
795 |
label="",
|
796 |
+
lines=10,
|
797 |
+
max_lines=15,
|
798 |
interactive=False,
|
799 |
+
elem_classes=["earth-box"]
|
800 |
)
|
801 |
|
802 |
with gr.Column():
|
803 |
+
gr.Markdown("### โ๏ธ ้ - ์ํคํ
์ฒ (็ฆฎ)")
|
804 |
+
metal_output = gr.Textbox(
|
805 |
label="",
|
806 |
+
lines=10,
|
807 |
+
max_lines=15,
|
808 |
interactive=False,
|
809 |
+
elem_classes=["metal-box"]
|
810 |
)
|
811 |
|
812 |
with gr.Row():
|
|
|
813 |
with gr.Column():
|
814 |
+
gr.Markdown("### ๐ง ๆฐด - R&D (ๆบ)")
|
815 |
+
water_output = gr.Textbox(
|
816 |
label="",
|
817 |
+
lines=10,
|
818 |
+
max_lines=15,
|
819 |
interactive=False,
|
820 |
+
elem_classes=["water-box"]
|
821 |
)
|
822 |
|
823 |
with gr.Column():
|
824 |
+
gr.Markdown("### ๐ ์ค๋ฆฝ์ ๋นํ์")
|
825 |
+
critic_output = gr.Textbox(
|
826 |
label="",
|
827 |
+
lines=10,
|
828 |
+
max_lines=15,
|
829 |
interactive=False,
|
830 |
+
elem_classes=["critic-box"]
|
831 |
)
|
832 |
|
833 |
# ์์
|
834 |
gr.Examples(
|
835 |
examples=[
|
836 |
+
"์ง์ ๊ฐ๋ฅํ ์ค๋งํธ์ํฐ ๊ตฌ์ถ์ ์ํ ์ข
ํฉ ์ ๋ต์?",
|
837 |
+
"AI ๊ธฐ๋ฐ ํฌ์ค์ผ์ด ์๋น์ค ํ๋ซํผ ๊ฐ๋ฐ ๊ณํ์?",
|
838 |
+
"ํ์์ค๋ฆฝ ๋ฌ์ฑ์ ์ํ ๊ธฐ์
์ ํ ๋ก๋๋งต์?",
|
839 |
+
"๋ฉํ๋ฒ์ค ๊ต์ก ํ๋ซํผ ๊ตฌ์ถ ๋ฐฉ์์?",
|
840 |
+
"๋ธ๋ก์ฒด์ธ ๊ธฐ๋ฐ ๊ณต๊ธ๋ง ๊ด๋ฆฌ ์์คํ
๋์
์ ๋ต์?"
|
|
|
|
|
|
|
841 |
],
|
842 |
inputs=user_input,
|
843 |
label="๐ก ์์ ์ง๋ฌธ"
|
|
|
845 |
|
846 |
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
847 |
submit_btn.click(
|
848 |
+
fn=process_wuxing_query,
|
849 |
inputs=[user_input, llm_mode],
|
850 |
+
outputs=[wood_output, fire_output, earth_output, metal_output, water_output, critic_output, status_text]
|
851 |
).then(
|
852 |
fn=lambda: "",
|
853 |
outputs=[user_input]
|
854 |
)
|
855 |
|
856 |
user_input.submit(
|
857 |
+
fn=process_wuxing_query,
|
858 |
inputs=[user_input, llm_mode],
|
859 |
+
outputs=[wood_output, fire_output, earth_output, metal_output, water_output, critic_output, status_text]
|
860 |
).then(
|
861 |
fn=lambda: "",
|
862 |
outputs=[user_input]
|
863 |
)
|
864 |
|
865 |
clear_btn.click(
|
866 |
+
fn=clear_wuxing,
|
867 |
+
outputs=[wood_output, fire_output, earth_output, metal_output, water_output, critic_output, status_text]
|
868 |
)
|
|
|
869 |
|
870 |
if __name__ == "__main__":
|
871 |
+
app.queue()
|
872 |
app.launch(
|
873 |
server_name="0.0.0.0",
|
874 |
server_port=7860,
|
875 |
share=True,
|
876 |
show_error=True
|
877 |
+
)
|
|