Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -277,34 +277,93 @@ class LLMCollaborativeSystem:
|
|
277 |
if self.test_mode:
|
278 |
logger.info(f"ํ
์คํธ ๋ชจ๋ ์คํธ๋ฆฌ๋ฐ - Role: {role}")
|
279 |
|
280 |
-
# ํ
์คํธ
|
281 |
-
if role == "supervisor"
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
response = """์ข
ํฉ๋ ์กฐ์ฌ ๋ด์ฉ์ ๋ฐํ์ผ๋ก ์คํ์ AI์๊ฒ ๊ตฌ์ฒด์ ์ผ๋ก ์ง์ํฉ๋๋ค."""
|
291 |
-
elif role == "supervisor" and messages[0]["content"].find("์คํ์ AI์ ๋ต๋ณ") > -1:
|
292 |
-
response = """์คํ์ AI์ ๊ณํ์ ๊ฒํ ํ ๊ฒฐ๊ณผ, ๊ฐ์ ์ฌํญ์ ์ ์ํฉ๋๋ค."""
|
293 |
-
elif role == "supervisor":
|
294 |
-
response = """์ด ์ง๋ฌธ์ ๋ํ ๊ฑฐ์์ ๋ถ์์ ์ ์ํ๊ฒ ์ต๋๋ค.
|
295 |
-
|
296 |
-
[๊ฒ์ ํค์๋]: best practices, implementation guide, case studies"""
|
297 |
-
elif role == "researcher" and "์ถ๊ฐ ์กฐ์ฌ" in messages[0]["content"]:
|
298 |
-
response = """๊ฐ๋
์์ ํผ๋๋ฐฑ์ ๋ฐ์ํ์ฌ ์ถ๊ฐ ์กฐ์ฌ๋ฅผ ์ํํ์ต๋๋ค."""
|
299 |
elif role == "researcher":
|
300 |
-
|
301 |
-
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
else:
|
304 |
-
response = "
|
305 |
|
306 |
yield from self.simulate_streaming(response, role)
|
307 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
# ๐ฏ ML ๋ชจ๋ธ ์ต์ ํ ํ๋ก์ ํธ ์ต์ข
์คํ ๋ณด๊ณ ์
|
310 |
|
@@ -1072,4 +1131,4 @@ if __name__ == "__main__":
|
|
1072 |
server_port=7860,
|
1073 |
share=True,
|
1074 |
show_error=True
|
1075 |
-
)
|
|
|
277 |
if self.test_mode:
|
278 |
logger.info(f"ํ
์คํธ ๋ชจ๋ ์คํธ๋ฆฌ๋ฐ - Role: {role}")
|
279 |
|
280 |
+
# ๊ฐ๋จํ ํ
์คํธ ์๋ต
|
281 |
+
if role == "supervisor":
|
282 |
+
if "์กฐ์ฌ์ AI์ 1์ฐจ ์กฐ์ฌ ๊ฒฐ๊ณผ" in messages[0]["content"]:
|
283 |
+
response = "์กฐ์ฌ ๋ด์ฉ์ ๊ฒํ ํ์ต๋๋ค. ์ถ๊ฐ ์กฐ์ฌ๊ฐ ํ์ํฉ๋๋ค. [์ถ๊ฐ ๊ฒ์ ํค์๋]: ์ต์ ๋๊ตฌ, ์คํจ ์ฌ๋ก, ROI ๋ถ์"
|
284 |
+
elif "์กฐ์ฌ์ AI๊ฐ ์ ๋ฆฌํ ์ต์ข
์กฐ์ฌ ๋ด์ฉ" in messages[0]["content"]:
|
285 |
+
response = "์กฐ์ฌ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌ์ฒด์ ์ธ ์คํ ์ง์๋ฅผ ๋ด๋ฆฝ๋๋ค. ๋จ๊ณ๋ณ๋ก ์งํํ์ธ์."
|
286 |
+
elif "์คํ์ AI์ ๋ต๋ณ" in messages[0]["content"]:
|
287 |
+
response = "์คํ ๊ณํ์ ๊ฒํ ํ์ต๋๋ค. ๋ชจ๋ํฐ๋ง ์ฒด๊ณ์ ํ ์ญ๋ ๊ฐ๋ฐ์ด ํ์ํฉ๋๋ค."
|
288 |
+
else:
|
289 |
+
response = "๊ฑฐ์์ ๋ถ์์ ์์ํฉ๋๋ค. [๊ฒ์ ํค์๋]: ๋ชจ๋ฒ ์ฌ๋ก, ๊ตฌํ ๊ฐ์ด๋, ์ฌ๋ก ์ฐ๊ตฌ"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
elif role == "researcher":
|
291 |
+
if "์ถ๊ฐ ์กฐ์ฌ" in messages[0]["content"]:
|
292 |
+
response = "์ถ๊ฐ ์กฐ์ฌ๋ฅผ ์๋ฃํ์ต๋๋ค. ๊ตฌ์ฒด์ ์ธ ๋๊ตฌ์ ROI ๋ฐ์ดํฐ๋ฅผ ์์งํ์ต๋๋ค."
|
293 |
+
else:
|
294 |
+
response = "์น ๊ฒ์์ ํตํด ์ต์ ์ ๋ณด๋ฅผ ์์งํ์ต๋๋ค. ์ฃผ์ ํธ๋ ๋์ ์ฌ๋ก๋ฅผ ์ ๋ฆฌํ์ต๋๋ค."
|
295 |
+
elif role == "executor":
|
296 |
+
if "์ต์ข
๋ณด๊ณ ์" in messages[0]["content"]:
|
297 |
+
response = "ํผ๋๋ฐฑ์ ๋ฐ์ํ ์ต์ข
๋ณด๊ณ ์์
๋๋ค. ์ ์ฒด ํ๋ก์ ํธ ๊ณํ๊ณผ ์์ ์ฑ๊ณผ๋ฅผ ํฌํจํฉ๋๋ค."
|
298 |
+
else:
|
299 |
+
response = "๊ตฌ์ฒด์ ์ธ ์คํ ๊ณํ์ ์๋ฆฝํ์ต๋๋ค. ์ฃผ์ฐจ๋ณ ์์ธ ์ผ์ ๊ณผ ๋๊ตฌ ์ ํ์ ํฌํจํฉ๋๋ค."
|
300 |
else:
|
301 |
+
response = "ํ
์คํธ ์๋ต์
๋๋ค."
|
302 |
|
303 |
yield from self.simulate_streaming(response, role)
|
304 |
return
|
305 |
+
|
306 |
+
# ์ค์ API ํธ์ถ (๊ธฐ์กด ์ฝ๋์ ๋์ผ)
|
307 |
+
try:
|
308 |
+
system_prompts = {
|
309 |
+
"supervisor": "๋น์ ์ ๊ฑฐ์์ ๊ด์ ์์ ๋ถ์ํ๊ณ ์ง๋ํ๋ ๊ฐ๋
์ AI์
๋๋ค.",
|
310 |
+
"researcher": "๋น์ ์ ์ ๋ณด๋ฅผ ์กฐ์ฌํ๊ณ ์ฒด๊ณ์ ์ผ๋ก ์ ๋ฆฌํ๋ ์กฐ์ฌ์ AI์
๋๋ค.",
|
311 |
+
"executor": "๋น์ ์ ์ธ๋ถ์ ์ธ ๋ด์ฉ์ ๊ตฌํํ๋ ์คํ์ AI์
๋๋ค."
|
312 |
+
}
|
313 |
+
|
314 |
+
full_messages = [
|
315 |
+
{"role": "system", "content": system_prompts.get(role, "")},
|
316 |
+
*messages
|
317 |
+
]
|
318 |
+
|
319 |
+
payload = {
|
320 |
+
"model": self.model_id,
|
321 |
+
"messages": full_messages,
|
322 |
+
"max_tokens": 2048,
|
323 |
+
"temperature": 0.7,
|
324 |
+
"top_p": 0.8,
|
325 |
+
"stream": True,
|
326 |
+
"stream_options": {"include_usage": True}
|
327 |
+
}
|
328 |
+
|
329 |
+
logger.info(f"API ์คํธ๋ฆฌ๋ฐ ํธ์ถ ์์ - Role: {role}")
|
330 |
+
|
331 |
+
response = requests.post(
|
332 |
+
self.api_url,
|
333 |
+
headers=self.create_headers(),
|
334 |
+
json=payload,
|
335 |
+
stream=True,
|
336 |
+
timeout=10
|
337 |
+
)
|
338 |
+
|
339 |
+
if response.status_code != 200:
|
340 |
+
logger.error(f"API ์ค๋ฅ: {response.status_code}")
|
341 |
+
yield f"โ API ์ค๋ฅ ({response.status_code}): {response.text[:200]}"
|
342 |
+
return
|
343 |
+
|
344 |
+
for line in response.iter_lines():
|
345 |
+
if line:
|
346 |
+
line = line.decode('utf-8')
|
347 |
+
if line.startswith("data: "):
|
348 |
+
data = line[6:]
|
349 |
+
if data == "[DONE]":
|
350 |
+
break
|
351 |
+
try:
|
352 |
+
chunk = json.loads(data)
|
353 |
+
if "choices" in chunk and chunk["choices"]:
|
354 |
+
content = chunk["choices"][0].get("delta", {}).get("content", "")
|
355 |
+
if content:
|
356 |
+
yield content
|
357 |
+
except json.JSONDecodeError:
|
358 |
+
continue
|
359 |
+
|
360 |
+
except requests.exceptions.Timeout:
|
361 |
+
yield "โฑ๏ธ API ํธ์ถ ์๊ฐ์ด ์ด๊ณผ๋์์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์."
|
362 |
+
except requests.exceptions.ConnectionError:
|
363 |
+
yield "๐ API ์๋ฒ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค. ์ธํฐ๋ท ์ฐ๊ฒฐ์ ํ์ธํด์ฃผ์ธ์."
|
364 |
+
except Exception as e:
|
365 |
+
logger.error(f"์คํธ๋ฆฌ๋ฐ ์ค ์ค๋ฅ: {str(e)}")
|
366 |
+
yield f"โ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
367 |
|
368 |
# ๐ฏ ML ๋ชจ๋ธ ์ต์ ํ ํ๋ก์ ํธ ์ต์ข
์คํ ๋ณด๊ณ ์
|
369 |
|
|
|
1131 |
server_port=7860,
|
1132 |
share=True,
|
1133 |
show_error=True
|
1134 |
+
)
|