Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,1625 +1,35 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
from
|
| 6 |
-
import time
|
| 7 |
-
from typing import List, Dict, Any, Generator, Tuple
|
| 8 |
-
import logging
|
| 9 |
-
import re
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# 추가 임포트
|
| 16 |
-
from bs4 import BeautifulSoup
|
| 17 |
-
from urllib.parse import urlparse
|
| 18 |
-
import urllib.request
|
| 19 |
-
|
| 20 |
-
# Gemini API 임포트
|
| 21 |
-
try:
|
| 22 |
-
from google import genai
|
| 23 |
-
from google.genai import types
|
| 24 |
-
GEMINI_AVAILABLE = True
|
| 25 |
-
except ImportError:
|
| 26 |
-
GEMINI_AVAILABLE = False
|
| 27 |
-
logger.warning("Google Gemini API가 설치되지 않았습니다. pip install google-genai로 설치하세요.")
|
| 28 |
-
|
| 29 |
-
# 환경 변수에서 토큰 가져오기
|
| 30 |
-
FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN", "YOUR_FRIENDLI_TOKEN")
|
| 31 |
-
BAPI_TOKEN = os.getenv("BAPI_TOKEN", "YOUR_BRAVE_API_TOKEN")
|
| 32 |
-
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY", "YOUR_GEMINI_API_KEY")
|
| 33 |
-
API_URL = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
| 34 |
-
BRAVE_SEARCH_URL = "https://api.search.brave.com/res/v1/web/search"
|
| 35 |
-
MODEL_ID = "dep89a2fld32mcm"
|
| 36 |
-
TEST_MODE = os.getenv("TEST_MODE", "false").lower() == "true"
|
| 37 |
-
|
| 38 |
-
# 전역 변수
|
| 39 |
-
conversation_history = []
|
| 40 |
-
|
| 41 |
-
class WuxingLLMSystem:
|
| 42 |
-
"""오행·오상 기반 AGI급 협력적 보고서 작성 시스템 - 상극(相剋) 원리 적용"""
|
| 43 |
-
|
| 44 |
-
def __init__(self):
|
| 45 |
-
self.token = FRIENDLI_TOKEN
|
| 46 |
-
self.bapi_token = BAPI_TOKEN
|
| 47 |
-
self.gemini_api_key = GEMINI_API_KEY
|
| 48 |
-
self.api_url = API_URL
|
| 49 |
-
self.brave_url = BRAVE_SEARCH_URL
|
| 50 |
-
self.model_id = MODEL_ID
|
| 51 |
-
self.test_mode = TEST_MODE or (self.token == "YOUR_FRIENDLI_TOKEN")
|
| 52 |
-
self.use_gemini = False
|
| 53 |
-
self.gemini_client = None
|
| 54 |
-
|
| 55 |
-
# 오행 역할 정의 - AGI 수준 전문가 팀
|
| 56 |
-
self.wuxing_roles = {
|
| 57 |
-
"wood": {
|
| 58 |
-
"name": "전략적 비전 설계자 (Chief Vision Officer)",
|
| 59 |
-
"virtue": "仁",
|
| 60 |
-
"element": "木",
|
| 61 |
-
"traits": "통찰력, 미래예측, 포용적 리더십",
|
| 62 |
-
"expertise": "거시적 비전, 시스템적 사고, 혁신 전략, 조직 문화 설계",
|
| 63 |
-
"color": "#10b981",
|
| 64 |
-
"restrains": "土", # 木克土
|
| 65 |
-
"restrained_by": "金" # 金克木
|
| 66 |
-
},
|
| 67 |
-
"fire": {
|
| 68 |
-
"name": "혁신 전략 아키텍트 (Innovation Strategy Architect)",
|
| 69 |
-
"virtue": "義",
|
| 70 |
-
"element": "火",
|
| 71 |
-
"traits": "파괴적 혁신, 전략적 직관, 리스크 테이킹",
|
| 72 |
-
"expertise": "비즈니스 모델 혁신, 시장 파괴 전략, 경쟁우위 설계",
|
| 73 |
-
"color": "#ef4444",
|
| 74 |
-
"restrains": "金", # 火克金
|
| 75 |
-
"restrained_by": "水" # 水克火
|
| 76 |
-
},
|
| 77 |
-
"metal": {
|
| 78 |
-
"name": "시스템 아키텍처 마스터 (Systems Architecture Master)",
|
| 79 |
-
"virtue": "禮",
|
| 80 |
-
"element": "金",
|
| 81 |
-
"traits": "정밀성, 완벽주의, 시스템 통합력",
|
| 82 |
-
"expertise": "엔터프라이즈 아키텍처, 기술 거버넌스, 표준화 전략",
|
| 83 |
-
"color": "#f59e0b",
|
| 84 |
-
"restrains": "木", # 金克木
|
| 85 |
-
"restrained_by": "火" # 火克金
|
| 86 |
-
},
|
| 87 |
-
"water": {
|
| 88 |
-
"name": "미래기술 연구소장 (Future Tech Research Director)",
|
| 89 |
-
"virtue": "智",
|
| 90 |
-
"element": "水",
|
| 91 |
-
"traits": "깊은 분석력, 기술 통찰, 혁신적 사고",
|
| 92 |
-
"expertise": "신기술 R&D, 기술 융합, AI/ML, 퀀텀 컴퓨팅",
|
| 93 |
-
"color": "#3b82f6",
|
| 94 |
-
"restrains": "火", # 水克火
|
| 95 |
-
"restrained_by": "土" # 土克水
|
| 96 |
-
},
|
| 97 |
-
"earth": {
|
| 98 |
-
"name": "실행 최적화 전문가 (Execution Excellence Expert)",
|
| 99 |
-
"virtue": "信",
|
| 100 |
-
"element": "土",
|
| 101 |
-
"traits": "체계성, 신뢰성, 실행 완벽성",
|
| 102 |
-
"expertise": "프로젝트 거버넌스, 품질 시스템, 리스크 관리, ROI 최적화",
|
| 103 |
-
"color": "#a855f7",
|
| 104 |
-
"restrains": "水", # 土克水
|
| 105 |
-
"restrained_by": "木" # 木克土
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
if self.test_mode:
|
| 110 |
-
logger.warning("테스트 모드로 실행됩니다.")
|
| 111 |
-
|
| 112 |
-
def set_llm_mode(self, mode: str):
|
| 113 |
-
"""LLM 모드 설정"""
|
| 114 |
-
if mode == "commercial" and GEMINI_AVAILABLE and self.gemini_api_key != "YOUR_GEMINI_API_KEY":
|
| 115 |
-
self.use_gemini = True
|
| 116 |
-
if not self.gemini_client:
|
| 117 |
-
self.gemini_client = genai.Client(api_key=self.gemini_api_key)
|
| 118 |
-
logger.info("Gemini 2.5 Pro 모드로 전환되었습니다.")
|
| 119 |
-
else:
|
| 120 |
-
self.use_gemini = False
|
| 121 |
-
logger.info("기본 LLM 모드로 전환되었습니다.")
|
| 122 |
-
|
| 123 |
-
def create_headers(self):
|
| 124 |
-
"""API 헤더 생성"""
|
| 125 |
-
return {
|
| 126 |
-
"Authorization": f"Bearer {self.token}",
|
| 127 |
-
"Content-Type": "application/json"
|
| 128 |
-
}
|
| 129 |
-
|
| 130 |
-
def create_brave_headers(self):
|
| 131 |
-
"""Brave API 헤더 생성"""
|
| 132 |
-
return {
|
| 133 |
-
"Accept": "application/json",
|
| 134 |
-
"Accept-Encoding": "gzip",
|
| 135 |
-
"X-Subscription-Token": self.bapi_token
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
def create_wood_initial_prompt(self, user_query: str, search_results: Dict = None) -> str:
|
| 139 |
-
"""木(전략적 비전 설계자) 초기 프롬프트"""
|
| 140 |
-
search_info = ""
|
| 141 |
-
if search_results:
|
| 142 |
-
search_info = "\n\n웹 검색 결과:\n" + self._format_search_results(search_results)
|
| 143 |
-
|
| 144 |
-
return f"""당신은 AGI 수준의 전략적 비전 설계자(Chief Vision Officer)입니다.
|
| 145 |
-
仁(인자함)의 덕목으로 미래를 예측하고 혁신적 비전을 제시합니다.
|
| 146 |
-
|
| 147 |
-
[사용자 요청사항]
|
| 148 |
-
{user_query}
|
| 149 |
-
|
| 150 |
-
[참고 자료]
|
| 151 |
-
{search_info}
|
| 152 |
-
|
| 153 |
-
[임무] 다음 관점에서 종합적이고 혁신적인 비전을 제시하세요:
|
| 154 |
-
|
| 155 |
-
1. **거시적 비전과 패러다임 전환**
|
| 156 |
-
- 10년 후 미래 시나리오와 메가트렌드 분석
|
| 157 |
-
- 패러다임 시프트와 게임체인저 요소 식별
|
| 158 |
-
- 글로벌 맥락에서의 전략적 포지셔닝
|
| 159 |
-
|
| 160 |
-
2. **시스템적 사고와 복잡계 분석**
|
| 161 |
-
- 다차원적 상호작용과 피드백 루프 설계
|
| 162 |
-
- 창발적 속성과 네트워크 효과 예측
|
| 163 |
-
- 생태계 관점의 가치 창출 모델
|
| 164 |
-
|
| 165 |
-
3. **혁신 프레임워크와 전략적 방향성**
|
| 166 |
-
- 블루오션 전략과 카테고리 디자인
|
| 167 |
-
- 지수적 성장을 위한 플라이휠 설계
|
| 168 |
-
- 안티프래질한 시스템 구축 방안
|
| 169 |
-
|
| 170 |
-
4. **팀 시너지와 집단지성 활용 전략**
|
| 171 |
-
- 火(혁신 전략): 파괴적 혁신과 비즈니스 모델 재정의
|
| 172 |
-
- 土(실행 최적화): 애자일 실행과 지속적 개선 체계
|
| 173 |
-
- 金(시스템 아키텍처): 확장 가능한 기술 인프라와 표준화
|
| 174 |
-
- 水(미래기술 R&D): 신기술 융합과 혁신적 프로토타이핑
|
| 175 |
-
|
| 176 |
-
5. **핵심 성공 지표(KPI)와 북극성 지표(North Star Metric)**
|
| 177 |
-
- 장기적 임팩트 측정 프레임워크
|
| 178 |
-
- 선행지표와 후행지표의 균형잡힌 설계
|
| 179 |
-
|
| 180 |
-
[검색 키워드 제안]: 미래 연구에 필요한 7-10개의 전략적 키워드를 제시하세요"""
|
| 181 |
-
|
| 182 |
-
def create_fire_strategy_prompt(self, user_query: str, wood_response: str, critic_feedback: str, search_results: Dict = None) -> str:
|
| 183 |
-
"""火(혁신 전략 아키텍트) 프롬프트"""
|
| 184 |
-
search_info = ""
|
| 185 |
-
if search_results:
|
| 186 |
-
search_info = "\n\n웹 검색 결과:\n" + self._format_search_results(search_results)
|
| 187 |
-
|
| 188 |
-
return f"""당신은 AGI 수준의 혁신 전략 아키텍트(Innovation Strategy Architect)입니다.
|
| 189 |
-
義(정의로움)의 덕목으로 파괴적 혁신과 게임체인징 전략을 설계합니다.
|
| 190 |
-
|
| 191 |
-
[사용자 요청사항]
|
| 192 |
-
{user_query}
|
| 193 |
-
|
| 194 |
-
[전략적 비전 설계자의 프레임워크]
|
| 195 |
-
{wood_response}
|
| 196 |
-
|
| 197 |
-
[전략 검증 전문가의 피드백]
|
| 198 |
-
{critic_feedback}
|
| 199 |
-
|
| 200 |
-
[시장 조사 데이터]
|
| 201 |
-
{search_info}
|
| 202 |
-
|
| 203 |
-
[임무] 다음 관점에서 혁신적인 전략을 수립하세요:
|
| 204 |
-
|
| 205 |
-
1. **파괴적 혁신과 블루오션 전략**
|
| 206 |
-
- 산업 재정의와 카테고리 창출
|
| 207 |
-
- 가치 혁신과 차별화 전략
|
| 208 |
-
- 네트워크 효과와 플랫폼 전략
|
| 209 |
-
|
| 210 |
-
2. **비즈니스 모델 혁신**
|
| 211 |
-
- 수익 모델 다각화 (구독, 프리미엄, 마켓플레이스)
|
| 212 |
-
- 가치사슬 재구성과 수직 통합
|
| 213 |
-
- 생태계 구축과 파트너십 전략
|
| 214 |
-
|
| 215 |
-
3. **경쟁우위 확보 전략**
|
| 216 |
-
- 핵심 역량과 차별화 요소
|
| 217 |
-
- 진입장벽 구축 메커니즘
|
| 218 |
-
- 지속가능한 경쟁우위 원천
|
| 219 |
-
|
| 220 |
-
4. **성장 전략과 확장 계획**
|
| 221 |
-
- 시장 침투와 시장 개발 전략
|
| 222 |
-
- 제품 개발과 다각화 전략
|
| 223 |
-
- M&A와 전략적 제휴 옵션
|
| 224 |
-
|
| 225 |
-
5. **리스크 관리와 시나리오 플래닝**
|
| 226 |
-
- 전략적 리스크 매트릭스
|
| 227 |
-
- 대응 시나리오와 컨틴전시 플랜
|
| 228 |
-
- 안티프래질한 전략 설계
|
| 229 |
-
|
| 230 |
-
[추가 연구 필요]: 경쟁사 분석, 시장 동향, 규제 환경 등 추가 조사가 필요한 키워드 [추가 검색]"""
|
| 231 |
-
|
| 232 |
-
def create_earth_execution_prompt(self, user_query: str, fire_response: str, critic_feedback: str, search_results: Dict = None) -> str:
|
| 233 |
-
"""土(실행 최적화 전문가) 프롬프트"""
|
| 234 |
-
search_info = ""
|
| 235 |
-
if search_results:
|
| 236 |
-
search_info = "\n\n웹 검색 결과:\n" + self._format_search_results(search_results)
|
| 237 |
-
|
| 238 |
-
return f"""당신은 AGI 수준의 실행 최적화 전문가(Execution Excellence Expert)입니다.
|
| 239 |
-
信(신뢰)의 덕목으로 완벽한 실행 체계와 품질 시스템을 구축합니다.
|
| 240 |
-
|
| 241 |
-
[사용자 요청사항]
|
| 242 |
-
{user_query}
|
| 243 |
-
|
| 244 |
-
[혁신 전략 아키텍트의 전략]
|
| 245 |
-
{fire_response}
|
| 246 |
-
|
| 247 |
-
[전략 검증 전문가의 피드백]
|
| 248 |
-
{critic_feedback}
|
| 249 |
-
|
| 250 |
-
[실행 관련 벤치마크 데이터]
|
| 251 |
-
{search_info}
|
| 252 |
-
|
| 253 |
-
[임무] 다음 관점에서 최적화된 실행 계획을 수립하세요:
|
| 254 |
-
|
| 255 |
-
1. **프로젝트 거버넌스와 PMO 체계**
|
| 256 |
-
- 애자일/워터폴 하이브리드 방법론
|
| 257 |
-
- RACI 매트릭스와 의사결정 구조
|
| 258 |
-
- 프로젝트 포트폴리오 관리
|
| 259 |
-
|
| 260 |
-
2. **단계별 실행 로드맵**
|
| 261 |
-
- 워크 브레이크다운 스트럭처(WBS)
|
| 262 |
-
- 크리티컬 패스와 마일스톤
|
| 263 |
-
- 스프린트 계획과 백로그 관리
|
| 264 |
-
|
| 265 |
-
3. **리소스 최적화와 예산 관리**
|
| 266 |
-
- 인력 배치와 스킬 매트릭스
|
| 267 |
-
- TCO 분석과 예산 배분
|
| 268 |
-
- 비용 최적화 전략
|
| 269 |
-
|
| 270 |
-
4. **품질 관리 시스템**
|
| 271 |
-
- ISO 9001/27001 기반 품질 체계
|
| 272 |
-
- KPI/OKR 프레임워크
|
| 273 |
-
- 지속적 개선(Kaizen) 메커니즘
|
| 274 |
-
|
| 275 |
-
5. **리스크 관리와 변화 관리**
|
| 276 |
-
- 리스크 레지스터와 완화 전략
|
| 277 |
-
- 변화 관리 8단계 프로세스
|
| 278 |
-
- 이해관계자 관리 전략
|
| 279 |
-
|
| 280 |
-
6. **성과 측정과 대시보드**
|
| 281 |
-
- 실시간 모니터링 시스템
|
| 282 |
-
- 균형성과표(BSC) 설계
|
| 283 |
-
- 예측 분석과 조기 경보 시스템
|
| 284 |
-
|
| 285 |
-
[추가 조사 필요]: 업계 베스트 프랙티스, 실행 도구, 품질 표준 등 [추가 검색]"""
|
| 286 |
-
|
| 287 |
-
def create_metal_architecture_prompt(self, user_query: str, earth_response: str, critic_feedback: str, search_results: Dict = None) -> str:
|
| 288 |
-
"""金(시스템 아키텍처 마스터) 프롬프트"""
|
| 289 |
-
search_info = ""
|
| 290 |
-
if search_results:
|
| 291 |
-
search_info = "\n\n웹 검색 결과:\n" + self._format_search_results(search_results)
|
| 292 |
-
|
| 293 |
-
return f"""당신은 AGI 수준의 시스템 아키텍처 마스터(Systems Architecture Master)입니다.
|
| 294 |
-
禮(예의·질서)의 덕목으로 완벽하고 확장 가능한 시스템을 설계합니다.
|
| 295 |
-
|
| 296 |
-
[사용자 요청사항]
|
| 297 |
-
{user_query}
|
| 298 |
-
|
| 299 |
-
[실행 최적화 전문가의 계획]
|
| 300 |
-
{earth_response}
|
| 301 |
-
|
| 302 |
-
[전략 검증 전문가의 피드백]
|
| 303 |
-
{critic_feedback}
|
| 304 |
-
|
| 305 |
-
[기술 아키텍처 참고 자료]
|
| 306 |
-
{search_info}
|
| 307 |
-
|
| 308 |
-
[임무] 다음 관점에서 엔터프라이즈급 아키텍처를 설계하세요:
|
| 309 |
-
|
| 310 |
-
1. **엔터프라이즈 아키텍처 프레임워크**
|
| 311 |
-
- TOGAF/Zachman 기반 설계
|
| 312 |
-
- 비즈니스/애플리케이션/데이터/기술 아키텍처
|
| 313 |
-
- 아키텍처 거버넌스와 원칙
|
| 314 |
-
|
| 315 |
-
2. **기술 스택과 플랫폼 전략**
|
| 316 |
-
- 클라우드 네이티브 아키텍처 (AWS/Azure/GCP)
|
| 317 |
-
- 마이크로서비스와 컨테이너화
|
| 318 |
-
- API 우선 설계와 이벤트 기반 아키텍처
|
| 319 |
-
|
| 320 |
-
3. **데이터 아키텍처와 거버넌스**
|
| 321 |
-
- 데이터 레이크하우스 설계
|
| 322 |
-
- 마스터 데이터 관리(MDM)
|
| 323 |
-
- 데이터 품질과 리니지 관리
|
| 324 |
-
|
| 325 |
-
4. **보안 아키텍처와 컴플라이언스**
|
| 326 |
-
- 제로 트러스트 보안 모델
|
| 327 |
-
- IAM과 접근 제어 체계
|
| 328 |
-
- GDPR/SOC2 컴플라이언스
|
| 329 |
-
|
| 330 |
-
5. **확장성과 성능 최적화**
|
| 331 |
-
- 수평/수직 확장 전략
|
| 332 |
-
- 캐싱과 CDN 전략
|
| 333 |
-
- 성능 모니터링과 튜닝
|
| 334 |
-
|
| 335 |
-
6. **기술 표준과 베스트 프랙티스**
|
| 336 |
-
- 코딩 표준과 디자인 패턴
|
| 337 |
-
- CI/CD 파이프라인
|
| 338 |
-
- 기술 부채 관리 전략
|
| 339 |
-
|
| 340 |
-
[추가 조사 필요]: 최신 기술 트렌드, 아키텍처 패턴, 보안 표준 등 [추가 검색]"""
|
| 341 |
-
|
| 342 |
-
def create_water_rd_prompt(self, user_query: str, metal_response: str, critic_feedback: str, search_results: Dict = None) -> str:
|
| 343 |
-
"""水(미래기술 연구소장) 프롬프트"""
|
| 344 |
-
search_info = ""
|
| 345 |
-
if search_results:
|
| 346 |
-
search_info = "\n\n최신 기술 조사 결과:\n" + self._format_search_results(search_results)
|
| 347 |
-
|
| 348 |
-
return f"""당신은 AGI 수준의 미래기술 연구소장(Future Tech Research Director)입니다.
|
| 349 |
-
智(지혜)의 덕목으로 최첨단 기술을 연구하고 혁신을 주도합니다.
|
| 350 |
-
|
| 351 |
-
[사용자 요청사항]
|
| 352 |
-
{user_query}
|
| 353 |
-
|
| 354 |
-
[시스템 아키텍처 마스터의 설계]
|
| 355 |
-
{metal_response}
|
| 356 |
-
|
| 357 |
-
[전략 검증 전문가의 피드백]
|
| 358 |
-
{critic_feedback}
|
| 359 |
-
|
| 360 |
-
[글로벌 기술 트렌드 분석]
|
| 361 |
-
{search_info}
|
| 362 |
-
|
| 363 |
-
[임무] 다음 관점에서 미래 지향적 R&D 전략을 수립하세요:
|
| 364 |
-
|
| 365 |
-
1. **신기술 트렌드와 기술 융합**
|
| 366 |
-
- AI/ML/딥러닝 최신 동향
|
| 367 |
-
- 퀀텀 컴퓨팅과 엣지 컴퓨팅
|
| 368 |
-
- 블록체인과 Web3 기술
|
| 369 |
-
- 메타버스와 XR 기술
|
| 370 |
-
|
| 371 |
-
2. **혁신적 프로토타이핑 전략**
|
| 372 |
-
- MVP와 빠른 실험 주기
|
| 373 |
-
- A/B 테스팅과 데이터 기반 의사결정
|
| 374 |
-
- 오픈 이노베이션과 해커톤
|
| 375 |
-
|
| 376 |
-
3. **AI/ML 통합 전략**
|
| 377 |
-
- LLM과 생성형 AI 활용
|
| 378 |
-
- MLOps와 모델 거버넌스
|
| 379 |
-
- 설명 가능한 AI(XAI)
|
| 380 |
-
- 윤리적 AI 가이드라인
|
| 381 |
-
|
| 382 |
-
4. **자동화와 생산성 혁신**
|
| 383 |
-
- RPA와 하이퍼오토메이션
|
| 384 |
-
- Low-code/No-code 플랫폼
|
| 385 |
-
- DevOps와 GitOps
|
| 386 |
-
- 지능형 모니터링 시스템
|
| 387 |
-
|
| 388 |
-
5. **기술 ROI와 혁신 포트폴리오**
|
| 389 |
-
- 기술 투자 우선순위 매트릭스
|
| 390 |
-
- 혁신 회계와 성과 측정
|
| 391 |
-
- 기술 파트너십 전략
|
| 392 |
-
|
| 393 |
-
6. **미래 준비도와 기술 로드맵**
|
| 394 |
-
- 3-5년 기술 비전
|
| 395 |
-
- 기술 역량 개발 계획
|
| 396 |
-
- 디지털 트랜스포메이션 성숙도
|
| 397 |
-
|
| 398 |
-
[추가 연구 필요]: Gartner Hype Cycle, MIT Tech Review, 특허 동향 등 [추가 검색]"""
|
| 399 |
-
|
| 400 |
-
def create_wood_final_prompt(self, user_query: str, all_responses: Dict, all_critics: List) -> str:
|
| 401 |
-
"""木(전략적 비전 설계자) 최종 종합 보고서 프롬프트"""
|
| 402 |
-
return f"""당신은 AGI 수준의 전략적 비전 설계자입니다.
|
| 403 |
-
팀 전체의 집단지성을 종합하여 최고 수준의 전문 보고서를 작성합니다.
|
| 404 |
-
|
| 405 |
-
[사용자 요청사항]
|
| 406 |
-
{user_query}
|
| 407 |
-
|
| 408 |
-
[팀원 기여 내용]
|
| 409 |
-
▶ 火(혁신 전략 아키텍트): {all_responses['fire']}
|
| 410 |
-
▶ 土(실행 최적화 전문가): {all_responses['earth']}
|
| 411 |
-
▶ 金(시스템 아키텍처 마스터): {all_responses['metal']}
|
| 412 |
-
▶ 水(미래기술 연구소장): {all_responses['water']}
|
| 413 |
-
|
| 414 |
-
[비평자 통찰]
|
| 415 |
-
{self._format_critic_history(all_critics)}
|
| 416 |
-
|
| 417 |
-
[최종 종합 보고서 작성 지침]
|
| 418 |
-
|
| 419 |
-
다음 구조로 최고 수준의 전문 보고서를 작성하세요:
|
| 420 |
-
|
| 421 |
-
# EXECUTIVE SUMMARY
|
| 422 |
-
- 핵심 권고사항 (3-5개 불릿포인트)
|
| 423 |
-
- 예상 임팩트와 ROI
|
| 424 |
-
- 즉시 실행 가능한 Quick Wins
|
| 425 |
-
|
| 426 |
-
# 1. 전략적 분석과 비전
|
| 427 |
-
## 1.1 현황 진단과 기회 분석
|
| 428 |
-
- SWOT-TOWS 매트릭스
|
| 429 |
-
- 포터의 5 Forces + 디지털 전환 영향
|
| 430 |
-
- 가치사슬 분석과 재정의 기회
|
| 431 |
-
|
| 432 |
-
## 1.2 미래 시나리오와 전략적 옵션
|
| 433 |
-
- 시나리오 플래닝 (최적/현실적/최악)
|
| 434 |
-
- 전략적 옵션과 의사결정 트리
|
| 435 |
-
- 리스크-리턴 프로파일
|
| 436 |
-
|
| 437 |
-
# 2. 혁신 전략과 실행 로드맵
|
| 438 |
-
## 2.1 혁신 프레임워크
|
| 439 |
-
- 혁신 포트폴리오 (Horizon 1-2-3)
|
| 440 |
-
- 디지털 전환 성숙도 모델
|
| 441 |
-
- 오픈 이노베이션 전략
|
| 442 |
-
|
| 443 |
-
## 2.2 단계별 실행 로드맵
|
| 444 |
-
- Phase 1 (0-6개월): 기반 구축
|
| 445 |
-
- Phase 2 (6-18개월): 확장과 최적화
|
| 446 |
-
- Phase 3 (18-36개월): 혁신과 성장
|
| 447 |
-
- 각 단계별 마일스톤과 KPI
|
| 448 |
-
|
| 449 |
-
# 3. 기술 아키텍처와 인프라
|
| 450 |
-
## 3.1 엔터프라이즈 아키텍처
|
| 451 |
-
- 현재 상태(AS-IS)와 목표 상태(TO-BE)
|
| 452 |
-
- 기술 스택과 플랫폼 전략
|
| 453 |
-
- 데이터 거버넌스와 보안 아키텍처
|
| 454 |
-
|
| 455 |
-
## 3.2 확장성과 미래 대응
|
| 456 |
-
- 마이크로서비스와 클라우드 네이티브
|
| 457 |
-
- AI/ML 통합 전략
|
| 458 |
-
- 기술 부채 관리와 현대화 계획
|
| 459 |
-
|
| 460 |
-
# 4. 실행 계획과 거버넌스
|
| 461 |
-
## 4.1 조직과 거버넌스
|
| 462 |
-
- 변화관리 전략
|
| 463 |
-
- 애자일 거버넌스 구조
|
| 464 |
-
- 역량 개발과 인재 확보
|
| 465 |
-
|
| 466 |
-
## 4.2 투자와 재무 분석
|
| 467 |
-
- TCO와 ROI 분석
|
| 468 |
-
- 자금 조달 옵션
|
| 469 |
-
- 재무 리스크 관리
|
| 470 |
-
|
| 471 |
-
# 5. 성과 측정과 지속가능성
|
| 472 |
-
## 5.1 성과 측정 프레임워크
|
| 473 |
-
- OKR과 균형성과표(BSC)
|
| 474 |
-
- 실시간 대시보드 설계
|
| 475 |
-
- 지속적 개선 메커니즘
|
| 476 |
-
|
| 477 |
-
## 5.2 지속가능성과 ESG
|
| 478 |
-
- ESG 통합 전략
|
| 479 |
-
- 순환경제 모델
|
| 480 |
-
- 사회적 임팩트 측정
|
| 481 |
-
|
| 482 |
-
# APPENDIX
|
| 483 |
-
- 상세 분석 자료
|
| 484 |
-
- 벤치마킹 사례
|
| 485 |
-
- 용어 정의와 참고문헌
|
| 486 |
-
|
| 487 |
-
**작성 원칙:**
|
| 488 |
-
- 데이터 기반의 논리적 전개
|
| 489 |
-
- 실행 가능한 구체적 권고안
|
| 490 |
-
- 시각적 요소 활용 (표, 차트 설명)
|
| 491 |
-
- 전문 용어와 일반 용어의 균형
|
| 492 |
-
- 글로벌 베스트 프랙티스 반영"""
|
| 493 |
-
|
| 494 |
-
def create_critic_prompt(self, stage: str, content: str, context: str = "", search_results: Dict = None) -> str:
|
| 495 |
-
"""AGI급 오행 상극 기반 비평자 프롬프트"""
|
| 496 |
-
search_info = ""
|
| 497 |
-
if search_results:
|
| 498 |
-
search_info = f"\n\n참고 검색 결과:\n{self._format_search_results(search_results)}"
|
| 499 |
-
|
| 500 |
-
context_section = ""
|
| 501 |
-
if context:
|
| 502 |
-
context_section = f"[이전 맥락]\n{context}\n"
|
| 503 |
-
|
| 504 |
-
# 오행 상극 관계에 따른 비평 관점 설정
|
| 505 |
-
critic_perspectives = {
|
| 506 |
-
"木 초기 분석": {
|
| 507 |
-
"perspective": "金(시스템 아키텍처 마스터)",
|
| 508 |
-
"focus": "정밀성, 체계성, 표준화",
|
| 509 |
-
"virtue": "禮",
|
| 510 |
-
"approach": "구조적 완결성과 시스템적 정합성을 중심으로 전략의 실현 가능성을 냉철하게 분석"
|
| 511 |
-
},
|
| 512 |
-
"火 전략기획": {
|
| 513 |
-
"perspective": "水(미래기술 연구소장)",
|
| 514 |
-
"focus": "분석적 깊이, 기술적 타당성, 혁신성",
|
| 515 |
-
"virtue": "智",
|
| 516 |
-
"approach": "기술적 관점에서 전략의 실현 가능성과 혁신의 지속가능성을 심층 분석"
|
| 517 |
-
},
|
| 518 |
-
"土 실행계획": {
|
| 519 |
-
"perspective": "木(전략적 비전 설계자)",
|
| 520 |
-
"focus": "거시적 일관성, 비전 정합성, 성장 가능성",
|
| 521 |
-
"virtue": "仁",
|
| 522 |
-
"approach": "전체적인 비전과의 정합성 및 장기적 성장 관점에서 실행계획의 적절성 평가"
|
| 523 |
-
},
|
| 524 |
-
"金 아키텍처": {
|
| 525 |
-
"perspective": "火(혁신 전략 아키텍트)",
|
| 526 |
-
"focus": "혁신성, 유연성, 변화 대응력",
|
| 527 |
-
"virtue": "義",
|
| 528 |
-
"approach": "파괴적 혁신과 급변하는 시장 환경에서 아키텍처의 적응성과 확장성 검증"
|
| 529 |
-
},
|
| 530 |
-
"水 R&D": {
|
| 531 |
-
"perspective": "土(실행 최적화 전문가)",
|
| 532 |
-
"focus": "실행 가능성, 자원 효율성, ROI",
|
| 533 |
-
"virtue": "信",
|
| 534 |
-
"approach": "실무적 관점에서 R&D 전략의 구체성과 투자 대비 효과성을 면밀히 검토"
|
| 535 |
-
}
|
| 536 |
-
}
|
| 537 |
-
|
| 538 |
-
critic_info = critic_perspectives.get(stage, critic_perspectives["木 초기 분석"])
|
| 539 |
-
|
| 540 |
-
return f"""당신은 {critic_info['perspective']}의 관점을 가진 AGI 수준의 비평 전문가입니다.
|
| 541 |
-
{critic_info['virtue']}(덕목)의 관점에서 {critic_info['focus']}를 중심으로 분석합니다.
|
| 542 |
-
McKinsey, BCG, Bain 수준의 전략적 사고와 학술적 엄밀성을 갖추고 있습니다.
|
| 543 |
-
|
| 544 |
-
[평가 대상]
|
| 545 |
-
단계: {stage}
|
| 546 |
-
내용: {content}
|
| 547 |
-
|
| 548 |
-
{context_section}{search_info}
|
| 549 |
-
|
| 550 |
-
[비평 철학]
|
| 551 |
-
오행 상극(相剋)의 원리에 따라, {critic_info['approach']}합니다.
|
| 552 |
-
|
| 553 |
-
[비평 프레임워크]
|
| 554 |
-
|
| 555 |
-
1. **{critic_info['perspective']} 관점의 핵심 검증**
|
| 556 |
-
- {critic_info['focus']}에 기반한 심층 분석
|
| 557 |
-
- 상극 관계에서 오는 건설적 긴장과 균형점 탐색
|
| 558 |
-
- 보완적 개선 방향 제시
|
| 559 |
-
|
| 560 |
-
2. **전략적 타당성 검증**
|
| 561 |
-
- 논리적 일관성과 인과관계 분석
|
| 562 |
-
- 가정(Assumptions)의 타당성 검토
|
| 563 |
-
- 반증 가능성과 대안 시나리오
|
| 564 |
-
|
| 565 |
-
3. **실행 가능성 평가**
|
| 566 |
-
- 자원 요구사항과 제약조건
|
| 567 |
-
- 기술적/조직적 실현 가능성
|
| 568 |
-
- 시간축과 의존성 분석
|
| 569 |
-
|
| 570 |
-
4. **혁신성과 차별화**
|
| 571 |
-
- 업계 베스트 프랙티스 대비 혁신성
|
| 572 |
-
- 경쟁우위 창출 가능성
|
| 573 |
-
- 지속가능한 차별화 요소
|
| 574 |
-
|
| 575 |
-
5. **리스크와 기회 분석**
|
| 576 |
-
- 주요 리스크 요인과 완화 전략
|
| 577 |
-
- 놓친 기회나 블라인드 스팟
|
| 578 |
-
- 시너지 창출 가능성
|
| 579 |
-
|
| 580 |
-
6. **개선 권고사항**
|
| 581 |
-
- {critic_info['perspective']} 관점에서의 구체적 개선안
|
| 582 |
-
- 우선순위와 영향도 매트릭스
|
| 583 |
-
- 다음 단계 담당자를 위한 가이드
|
| 584 |
-
|
| 585 |
-
7. **오행 균형과 조화**
|
| 586 |
-
- 상극 관계를 통한 건설적 긴장 유지
|
| 587 |
-
- 전체 시스템의 균형과 조화 달성 방안
|
| 588 |
-
- 집단지성의 시너지 극대화 전략
|
| 589 |
-
|
| 590 |
-
[추가 연구 제안]: 심화 분석이 필요한 키워드 5-7개를 제시하세요 [비평 검색]"""
|
| 591 |
-
|
| 592 |
-
def _format_search_results(self, search_results: Dict) -> str:
|
| 593 |
-
"""검색 결과 포맷팅"""
|
| 594 |
-
if not search_results:
|
| 595 |
-
return "검색 결과 없음"
|
| 596 |
-
|
| 597 |
-
formatted = ""
|
| 598 |
-
for keyword, results in search_results.items():
|
| 599 |
-
formatted += f"\n**{keyword}:**\n"
|
| 600 |
-
for i, result in enumerate(results[:5], 1):
|
| 601 |
-
formatted += f"{i}. {result.get('title', 'N/A')} (신뢰도: {result.get('credibility_score', 0):.2f})\n"
|
| 602 |
-
formatted += f" {result.get('description', 'N/A')[:150]}...\n"
|
| 603 |
-
return formatted
|
| 604 |
-
|
| 605 |
-
def _format_critic_display(self, critics: List[str], current_index: int) -> str:
|
| 606 |
-
"""비평 내용을 보기 좋게 포맷팅"""
|
| 607 |
-
stages = [
|
| 608 |
-
"전략적 비전 검증 (金克木)",
|
| 609 |
-
"혁신 전략 검증 (水克火)",
|
| 610 |
-
"실행 계획 검증 (木克土)",
|
| 611 |
-
"아키텍처 검증 (火克金)",
|
| 612 |
-
"미래기술 검증 (土克水)"
|
| 613 |
-
]
|
| 614 |
-
|
| 615 |
-
formatted = "🔍 **전략 검증 전문가** (오행 상극 원리)\n\n"
|
| 616 |
-
|
| 617 |
-
for i in range(min(current_index + 1, len(critics))):
|
| 618 |
-
if i < len(stages):
|
| 619 |
-
formatted += f"[{stages[i]}]\n{critics[i]}\n"
|
| 620 |
-
if i < current_index:
|
| 621 |
-
formatted += "\n---\n\n"
|
| 622 |
-
|
| 623 |
-
return formatted
|
| 624 |
-
|
| 625 |
-
def _format_critic_history(self, critics: List) -> str:
|
| 626 |
-
"""비평 이력 포맷팅 (최종 보고서용)"""
|
| 627 |
-
if not critics:
|
| 628 |
-
return "비평 이력 없음"
|
| 629 |
-
|
| 630 |
-
formatted = ""
|
| 631 |
-
stages = [
|
| 632 |
-
"木 초기 (金 관점 비평)",
|
| 633 |
-
"火 전략 (水 관점 비평)",
|
| 634 |
-
"土 실행 (木 관점 비평)",
|
| 635 |
-
"金 아키텍처 (火 관점 비평)",
|
| 636 |
-
"水 R&D (土 관점 비평)"
|
| 637 |
-
]
|
| 638 |
-
for i, critic in enumerate(critics):
|
| 639 |
-
if i < len(stages):
|
| 640 |
-
formatted += f"\n**{stages[i]}:**\n{critic}\n"
|
| 641 |
-
return formatted
|
| 642 |
-
|
| 643 |
-
def extract_keywords(self, response: str, keyword_marker: str = "[핵심 키워드]") -> List[str]:
|
| 644 |
-
"""응답에서 키워드 추출 (범용)"""
|
| 645 |
-
keywords = []
|
| 646 |
-
|
| 647 |
-
# 다양한 키워드 마커 패턴
|
| 648 |
-
patterns = [
|
| 649 |
-
rf'{re.escape(keyword_marker)}:\s*(.+)',
|
| 650 |
-
r'\[추가 검색\]:\s*(.+)',
|
| 651 |
-
r'\[비평 검색\]:\s*(.+)'
|
| 652 |
-
]
|
| 653 |
-
|
| 654 |
-
for pattern in patterns:
|
| 655 |
-
match = re.search(pattern, response, re.IGNORECASE)
|
| 656 |
-
if match:
|
| 657 |
-
keyword_str = match.group(1)
|
| 658 |
-
new_keywords = [k.strip() for k in keyword_str.split(',') if k.strip()]
|
| 659 |
-
keywords.extend(new_keywords)
|
| 660 |
-
|
| 661 |
-
# 중복 제거
|
| 662 |
-
keywords = list(dict.fromkeys(keywords))
|
| 663 |
-
|
| 664 |
-
if not keywords:
|
| 665 |
-
# 기본 키워드 생성
|
| 666 |
-
keywords = ["best practices", "implementation", "case studies", "latest trends"]
|
| 667 |
-
|
| 668 |
-
return keywords[:7]
|
| 669 |
-
|
| 670 |
-
def calculate_credibility_score(self, result: Dict) -> float:
|
| 671 |
-
"""검색 결과 신뢰도 계산"""
|
| 672 |
-
score = 0.5
|
| 673 |
-
url = result.get('url', '')
|
| 674 |
-
|
| 675 |
-
trusted_domains = ['.edu', '.gov', '.org', 'wikipedia.org', 'nature.com',
|
| 676 |
-
'ieee.org', 'acm.org', 'github.com']
|
| 677 |
-
|
| 678 |
-
for domain in trusted_domains:
|
| 679 |
-
if domain in url:
|
| 680 |
-
score += 0.2
|
| 681 |
-
break
|
| 682 |
-
|
| 683 |
-
if url.startswith('https://'):
|
| 684 |
-
score += 0.1
|
| 685 |
-
|
| 686 |
-
if len(result.get('title', '')) > 20:
|
| 687 |
-
score += 0.05
|
| 688 |
-
if len(result.get('description', '')) > 50:
|
| 689 |
-
score += 0.05
|
| 690 |
-
|
| 691 |
-
spam_keywords = ['buy now', 'sale', 'discount', 'click here']
|
| 692 |
-
if any(spam in (result.get('title', '') + result.get('description', '')).lower()
|
| 693 |
-
for spam in spam_keywords):
|
| 694 |
-
score -= 0.3
|
| 695 |
-
|
| 696 |
-
return max(0, min(1, score))
|
| 697 |
-
|
| 698 |
-
def brave_search(self, query: str) -> List[Dict]:
|
| 699 |
-
"""Brave Search API 호출"""
|
| 700 |
-
if self.test_mode or self.bapi_token == "YOUR_BRAVE_API_TOKEN":
|
| 701 |
-
test_results = []
|
| 702 |
-
for i in range(5):
|
| 703 |
-
test_results.append({
|
| 704 |
-
"title": f"{query} - Best Practices {i+1}",
|
| 705 |
-
"description": f"Comprehensive guide on {query} with proven methodologies.",
|
| 706 |
-
"url": f"https://example{i+1}.com/{query.replace(' ', '-')}",
|
| 707 |
-
"credibility_score": 0.7 + (i * 0.05)
|
| 708 |
-
})
|
| 709 |
-
return test_results
|
| 710 |
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
"q": query,
|
| 714 |
-
"count": 10,
|
| 715 |
-
"safesearch": "moderate"
|
| 716 |
-
}
|
| 717 |
-
|
| 718 |
-
response = requests.get(
|
| 719 |
-
self.brave_url,
|
| 720 |
-
headers=self.create_brave_headers(),
|
| 721 |
-
params=params,
|
| 722 |
-
timeout=10
|
| 723 |
-
)
|
| 724 |
-
|
| 725 |
-
if response.status_code == 200:
|
| 726 |
-
data = response.json()
|
| 727 |
-
results = []
|
| 728 |
-
for item in data.get("web", {}).get("results", []):
|
| 729 |
-
result = {
|
| 730 |
-
"title": item.get("title", ""),
|
| 731 |
-
"description": item.get("description", ""),
|
| 732 |
-
"url": item.get("url", ""),
|
| 733 |
-
"credibility_score": self.calculate_credibility_score(item)
|
| 734 |
-
}
|
| 735 |
-
results.append(result)
|
| 736 |
-
|
| 737 |
-
results.sort(key=lambda x: x['credibility_score'], reverse=True)
|
| 738 |
-
return results
|
| 739 |
-
else:
|
| 740 |
-
logger.error(f"Brave API 오류: {response.status_code}")
|
| 741 |
-
return []
|
| 742 |
-
|
| 743 |
-
except Exception as e:
|
| 744 |
-
logger.error(f"Brave 검색 중 오류: {str(e)}")
|
| 745 |
-
return []
|
| 746 |
-
|
| 747 |
-
def call_gemini_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
| 748 |
-
"""Gemini API 스트리밍 호출 - AGI 수준"""
|
| 749 |
-
if not self.gemini_client:
|
| 750 |
-
yield "❌ Gemini API 클라이언트가 초기화되지 않았습니다."
|
| 751 |
return
|
| 752 |
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
contents.append(types.Content(
|
| 758 |
-
role="user",
|
| 759 |
-
parts=[types.Part.from_text(text=msg["content"])]
|
| 760 |
-
))
|
| 761 |
-
|
| 762 |
-
generate_content_config = types.GenerateContentConfig(
|
| 763 |
-
temperature=0.8, # 창의성 증가
|
| 764 |
-
top_p=0.9,
|
| 765 |
-
max_output_tokens=8192, # 토큰 수 대폭 증가
|
| 766 |
-
response_mime_type="text/plain"
|
| 767 |
-
)
|
| 768 |
-
|
| 769 |
-
for chunk in self.gemini_client.models.generate_content_stream(
|
| 770 |
-
model="gemini-2.5-pro",
|
| 771 |
-
contents=contents,
|
| 772 |
-
config=generate_content_config,
|
| 773 |
-
):
|
| 774 |
-
if chunk.text:
|
| 775 |
-
yield chunk.text
|
| 776 |
-
|
| 777 |
-
except Exception as e:
|
| 778 |
-
logger.error(f"Gemini API 오류: {str(e)}")
|
| 779 |
-
yield f"❌ Gemini API 오류: {str(e)}"
|
| 780 |
-
|
| 781 |
-
def call_llm_streaming(self, messages: List[Dict[str, str]], role: str) -> Generator[str, None, None]:
|
| 782 |
-
"""스트리밍 LLM API 호출 - AGI 수준 응답"""
|
| 783 |
-
if self.use_gemini:
|
| 784 |
-
yield from self.call_gemini_streaming(messages, role)
|
| 785 |
-
return
|
| 786 |
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
test_response += f"이것은 {role} 전문가의 AGI 수준 분석입니다.\n"
|
| 790 |
-
test_response += "1. 전략적 통찰: 심층적이고 혁신적인 분석\n"
|
| 791 |
-
test_response += "2. 실행 가능성: 구체적이고 검증된 방법론\n"
|
| 792 |
-
test_response += "3. 미래 예측: 데이터 기반 시나리오 플래닝\n"
|
| 793 |
-
|
| 794 |
-
words = test_response.split()
|
| 795 |
-
for i in range(0, len(words), 3):
|
| 796 |
-
chunk = " ".join(words[i:i+3])
|
| 797 |
-
yield chunk + " "
|
| 798 |
-
time.sleep(0.05)
|
| 799 |
-
return
|
| 800 |
|
|
|
|
| 801 |
try:
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
"max_tokens": 8192, # 토큰 수 대폭 증가
|
| 806 |
-
"temperature": 0.8, # 창의성 증가
|
| 807 |
-
"top_p": 0.9,
|
| 808 |
-
"stream": True
|
| 809 |
-
}
|
| 810 |
-
|
| 811 |
-
response = requests.post(
|
| 812 |
-
self.api_url,
|
| 813 |
-
headers=self.create_headers(),
|
| 814 |
-
json=payload,
|
| 815 |
-
stream=True,
|
| 816 |
-
timeout=30 # 타임아웃 증가
|
| 817 |
-
)
|
| 818 |
|
| 819 |
-
if response.status_code != 200:
|
| 820 |
-
yield f"❌ API 오류: {response.status_code}"
|
| 821 |
-
return
|
| 822 |
-
|
| 823 |
-
for line in response.iter_lines():
|
| 824 |
-
if line:
|
| 825 |
-
line = line.decode('utf-8')
|
| 826 |
-
if line.startswith("data: "):
|
| 827 |
-
data = line[6:]
|
| 828 |
-
if data == "[DONE]":
|
| 829 |
-
break
|
| 830 |
-
try:
|
| 831 |
-
chunk = json.loads(data)
|
| 832 |
-
if "choices" in chunk and chunk["choices"]:
|
| 833 |
-
content = chunk["choices"][0].get("delta", {}).get("content", "")
|
| 834 |
-
if content:
|
| 835 |
-
yield content
|
| 836 |
-
except json.JSONDecodeError:
|
| 837 |
-
continue
|
| 838 |
-
|
| 839 |
-
except Exception as e:
|
| 840 |
-
logger.error(f"스트리밍 중 오류: {str(e)}")
|
| 841 |
-
yield f"❌ 오류 발생: {str(e)}"
|
| 842 |
-
|
| 843 |
-
# 시스템 인스턴스 생성
|
| 844 |
-
wuxing_system = WuxingLLMSystem()
|
| 845 |
-
|
| 846 |
-
def process_wuxing_query(user_query: str, llm_mode: str):
|
| 847 |
-
"""AGI 수준 오행 기반 전문 보고서 생성"""
|
| 848 |
-
if not user_query:
|
| 849 |
-
return "", "", "", "", "", "", "", "❌ 보고서 요청사항을 입력해주세요."
|
| 850 |
-
|
| 851 |
-
wuxing_system.set_llm_mode(llm_mode)
|
| 852 |
-
|
| 853 |
-
all_responses = {}
|
| 854 |
-
all_critics = []
|
| 855 |
-
all_search_results = {}
|
| 856 |
-
|
| 857 |
-
try:
|
| 858 |
-
# 0. 초기 검색 수행 - 더 많은 키워드로 심층 조사
|
| 859 |
-
initial_keywords = [
|
| 860 |
-
user_query,
|
| 861 |
-
f"{user_query} best practices",
|
| 862 |
-
f"{user_query} case studies",
|
| 863 |
-
f"{user_query} industry trends",
|
| 864 |
-
f"{user_query} future outlook",
|
| 865 |
-
f"{user_query} challenges solutions"
|
| 866 |
-
]
|
| 867 |
-
wood_search_results = {}
|
| 868 |
-
|
| 869 |
-
status_text = "🔍 AGI 시스템이 글로벌 데이터베이스를 검색 중..."
|
| 870 |
-
yield "", "", "", "", "", "", "", status_text
|
| 871 |
-
|
| 872 |
-
for keyword in initial_keywords[:5]: # 더 많은 초기 검색
|
| 873 |
-
results = wuxing_system.brave_search(keyword)
|
| 874 |
-
if results:
|
| 875 |
-
wood_search_results[keyword] = results
|
| 876 |
-
all_search_results[f"초기-{keyword}"] = results
|
| 877 |
-
|
| 878 |
-
# 1. 木(감독관) 초기 분석
|
| 879 |
-
wood_prompt = wuxing_system.create_wood_initial_prompt(user_query, wood_search_results)
|
| 880 |
-
wood_response = ""
|
| 881 |
-
|
| 882 |
-
wood_text = "🌳 **木 - 전략적 비전 설계자** (仁)\n🔄 미래 시나리오 분석 중...\n"
|
| 883 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 884 |
-
[{"role": "user", "content": wood_prompt}], "wood"
|
| 885 |
-
):
|
| 886 |
-
wood_response += chunk
|
| 887 |
-
wood_text = f"🌳 **木 - 전략적 비전 설계자** (仁)\n{wood_response}"
|
| 888 |
-
yield wood_text, "", "", "", "", "", "", "🌳 거시적 비전과 전략 프레임워크 수립 중..."
|
| 889 |
-
|
| 890 |
-
all_responses['wood_initial'] = wood_response
|
| 891 |
-
|
| 892 |
-
# 키워드 추출
|
| 893 |
-
keywords = wuxing_system.extract_keywords(wood_response)
|
| 894 |
-
|
| 895 |
-
# 2. 木 비평 + 비평자 검색 (金 관점)
|
| 896 |
-
critic_search = {}
|
| 897 |
-
for keyword in keywords[:2]:
|
| 898 |
-
results = wuxing_system.brave_search(f"{keyword} analysis")
|
| 899 |
-
if results:
|
| 900 |
-
critic_search[keyword] = results
|
| 901 |
-
all_search_results[f"비평1-{keyword}"] = results
|
| 902 |
-
|
| 903 |
-
critic_prompt = wuxing_system.create_critic_prompt("木 초기 분석", wood_response, search_results=critic_search)
|
| 904 |
-
critic_response = ""
|
| 905 |
-
|
| 906 |
-
critic_text = "🔍 **전략 검증 전문가**\n[전략적 비전 검증 - 金克木] 🔄 시스템적 정밀성 분석 중...\n"
|
| 907 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 908 |
-
[{"role": "user", "content": critic_prompt}], "critic"
|
| 909 |
-
):
|
| 910 |
-
critic_response += chunk
|
| 911 |
-
critic_text = wuxing_system._format_critic_display([critic_response], 0)
|
| 912 |
-
yield wood_text, "", "", "", "", critic_text, "", "🔍 金의 관점에서 木의 전략 타당성과 체계성 검증 중..."
|
| 913 |
-
|
| 914 |
-
all_critics.append(critic_response)
|
| 915 |
-
|
| 916 |
-
# 3. 火(전략기획) + 검색
|
| 917 |
-
# 비평자가 제안한 추가 키워드 추출
|
| 918 |
-
critic_keywords = wuxing_system.extract_keywords(critic_response, "[비평 검색]")
|
| 919 |
-
fire_search = {}
|
| 920 |
-
|
| 921 |
-
for keyword in (keywords[:2] + critic_keywords[:2]):
|
| 922 |
-
results = wuxing_system.brave_search(f"{user_query} {keyword} strategy")
|
| 923 |
-
if results:
|
| 924 |
-
fire_search[keyword] = results
|
| 925 |
-
all_search_results[f"火-{keyword}"] = results
|
| 926 |
-
|
| 927 |
-
fire_prompt = wuxing_system.create_fire_strategy_prompt(user_query, wood_response, critic_response, fire_search)
|
| 928 |
-
fire_response = ""
|
| 929 |
-
|
| 930 |
-
fire_text = "🔥 **火 - 혁신 전략 아키텍트** (義)\n🔄 파괴적 혁신 전략 설계 중...\n"
|
| 931 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 932 |
-
[{"role": "user", "content": fire_prompt}], "fire"
|
| 933 |
-
):
|
| 934 |
-
fire_response += chunk
|
| 935 |
-
fire_text = f"🔥 **火 - 혁신 전략 아키텍트** (義)\n{fire_response}"
|
| 936 |
-
yield wood_text, fire_text, "", "", "", critic_text, "", "🔥 비즈니스 모델 혁신과 경쟁우위 전략 수립 중..."
|
| 937 |
-
|
| 938 |
-
all_responses['fire'] = fire_response
|
| 939 |
-
|
| 940 |
-
# 4. 火 비평 (水 관점)
|
| 941 |
-
fire_keywords = wuxing_system.extract_keywords(fire_response, "[추가 검색]")
|
| 942 |
-
critic_search = {}
|
| 943 |
-
|
| 944 |
-
for keyword in fire_keywords[:2]:
|
| 945 |
-
results = wuxing_system.brave_search(keyword)
|
| 946 |
-
if results:
|
| 947 |
-
critic_search[keyword] = results
|
| 948 |
-
all_search_results[f"비평2-{keyword}"] = results
|
| 949 |
-
|
| 950 |
-
critic_prompt = wuxing_system.create_critic_prompt("火 전략기획", fire_response, wood_response, critic_search)
|
| 951 |
-
critic_response = ""
|
| 952 |
-
|
| 953 |
-
# 이전 비평 내용 유지하면서 새로운 비평 추가
|
| 954 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 955 |
-
[{"role": "user", "content": critic_prompt}], "critic"
|
| 956 |
-
):
|
| 957 |
-
critic_response += chunk
|
| 958 |
-
critic_text = wuxing_system._format_critic_display(all_critics + [critic_response], 1)
|
| 959 |
-
yield wood_text, fire_text, "", "", "", critic_text, "", "🔍 水의 관점에서 火의 혁신성과 기술적 타당성 검증 중..."
|
| 960 |
-
|
| 961 |
-
all_critics.append(critic_response)
|
| 962 |
-
|
| 963 |
-
# 5. 土(실행운영)
|
| 964 |
-
earth_search = {}
|
| 965 |
-
for keyword in ["implementation", "resource management", "quality assurance"]:
|
| 966 |
-
results = wuxing_system.brave_search(f"{user_query} {keyword}")
|
| 967 |
-
if results:
|
| 968 |
-
earth_search[keyword] = results
|
| 969 |
-
all_search_results[f"土-{keyword}"] = results
|
| 970 |
-
|
| 971 |
-
earth_prompt = wuxing_system.create_earth_execution_prompt(user_query, fire_response, critic_response, earth_search)
|
| 972 |
-
earth_response = ""
|
| 973 |
-
|
| 974 |
-
earth_text = "🏔️ **土 - 실행 최적화 전문가** (信)\n🔄 프로젝트 거버넌스 설계 중...\n"
|
| 975 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 976 |
-
[{"role": "user", "content": earth_prompt}], "earth"
|
| 977 |
-
):
|
| 978 |
-
earth_response += chunk
|
| 979 |
-
earth_text = f"🏔️ **土 - 실행 최적화 전문가** (信)\n{earth_response}"
|
| 980 |
-
yield wood_text, fire_text, earth_text, "", "", critic_text, "", "🏔️ 실행 로드맵과 품질 시스템 구축 중..."
|
| 981 |
-
|
| 982 |
-
all_responses['earth'] = earth_response
|
| 983 |
-
|
| 984 |
-
# 6. 土 비평 (木 관점)
|
| 985 |
-
critic_search = {}
|
| 986 |
-
results = wuxing_system.brave_search(f"{user_query} execution challenges")
|
| 987 |
-
if results:
|
| 988 |
-
critic_search["execution"] = results
|
| 989 |
-
all_search_results["비평3-execution"] = results
|
| 990 |
-
|
| 991 |
-
critic_prompt = wuxing_system.create_critic_prompt("土 실행계획", earth_response, fire_response, critic_search)
|
| 992 |
-
critic_response = ""
|
| 993 |
-
|
| 994 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 995 |
-
[{"role": "user", "content": critic_prompt}], "critic"
|
| 996 |
-
):
|
| 997 |
-
critic_response += chunk
|
| 998 |
-
critic_text = wuxing_system._format_critic_display(all_critics + [critic_response], 2)
|
| 999 |
-
yield wood_text, fire_text, earth_text, "", "", critic_text, "", "🔍 木의 관점에서 土의 실행계획과 비전 정합성 검증 중..."
|
| 1000 |
-
|
| 1001 |
-
all_critics.append(critic_response)
|
| 1002 |
-
|
| 1003 |
-
# 7. 金(아키텍처)
|
| 1004 |
-
metal_search = {}
|
| 1005 |
-
for keyword in ["architecture", "standards", "system design", "scalability"]:
|
| 1006 |
-
results = wuxing_system.brave_search(f"{user_query} {keyword}")
|
| 1007 |
-
if results:
|
| 1008 |
-
metal_search[keyword] = results
|
| 1009 |
-
all_search_results[f"金-{keyword}"] = results
|
| 1010 |
-
|
| 1011 |
-
metal_prompt = wuxing_system.create_metal_architecture_prompt(user_query, earth_response, critic_response, metal_search)
|
| 1012 |
-
metal_response = ""
|
| 1013 |
-
|
| 1014 |
-
metal_text = "⚙️ **金 - 시스템 아키텍처 마스터** (禮)\n🔄 엔터프라이즈 아키텍처 설계 중...\n"
|
| 1015 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 1016 |
-
[{"role": "user", "content": metal_prompt}], "metal"
|
| 1017 |
-
):
|
| 1018 |
-
metal_response += chunk
|
| 1019 |
-
metal_text = f"⚙️ **金 - 시스템 아키텍처 마스터** (禮)\n{metal_response}"
|
| 1020 |
-
yield wood_text, fire_text, earth_text, metal_text, "", critic_text, "", "⚙️ 기술 표준과 확장 가능한 인프라 설계 중..."
|
| 1021 |
-
|
| 1022 |
-
all_responses['metal'] = metal_response
|
| 1023 |
-
|
| 1024 |
-
# 8. 金 비평 (火 관점)
|
| 1025 |
-
critic_search = {}
|
| 1026 |
-
results = wuxing_system.brave_search(f"{user_query} technical constraints")
|
| 1027 |
-
if results:
|
| 1028 |
-
critic_search["constraints"] = results
|
| 1029 |
-
all_search_results["비평4-constraints"] = results
|
| 1030 |
-
|
| 1031 |
-
critic_prompt = wuxing_system.create_critic_prompt("金 아키텍처", metal_response, earth_response, critic_search)
|
| 1032 |
-
critic_response = ""
|
| 1033 |
-
|
| 1034 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 1035 |
-
[{"role": "user", "content": critic_prompt}], "critic"
|
| 1036 |
-
):
|
| 1037 |
-
critic_response += chunk
|
| 1038 |
-
critic_text = wuxing_system._format_critic_display(all_critics + [critic_response], 3)
|
| 1039 |
-
yield wood_text, fire_text, earth_text, metal_text, "", critic_text, "", "🔍 火의 관점에서 金의 아키텍처 혁신성과 유연성 검증 중..."
|
| 1040 |
-
|
| 1041 |
-
all_critics.append(critic_response)
|
| 1042 |
-
|
| 1043 |
-
# 9. 水(R&D)
|
| 1044 |
-
water_search = {}
|
| 1045 |
-
for keyword in ["innovation", "emerging technology", "R&D", "automation tools"]:
|
| 1046 |
-
results = wuxing_system.brave_search(f"{user_query} {keyword}")
|
| 1047 |
-
if results:
|
| 1048 |
-
water_search[keyword] = results
|
| 1049 |
-
all_search_results[f"水-{keyword}"] = results
|
| 1050 |
-
|
| 1051 |
-
water_prompt = wuxing_system.create_water_rd_prompt(user_query, metal_response, critic_response, water_search)
|
| 1052 |
-
water_response = ""
|
| 1053 |
-
|
| 1054 |
-
water_text = "💧 **水 - 미래기술 연구소장** (智)\n🔄 신기술 융합 전략 연구 중...\n"
|
| 1055 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 1056 |
-
[{"role": "user", "content": water_prompt}], "water"
|
| 1057 |
-
):
|
| 1058 |
-
water_response += chunk
|
| 1059 |
-
water_text = f"💧 **水 - 미래기술 연구소장** (智)\n{water_response}"
|
| 1060 |
-
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, "", "💧 AI/ML 및 신기술 R&D 전략 수립 중..."
|
| 1061 |
-
|
| 1062 |
-
all_responses['water'] = water_response
|
| 1063 |
-
|
| 1064 |
-
# 10. 水 비평 (土 관점)
|
| 1065 |
-
critic_search = {}
|
| 1066 |
-
results = wuxing_system.brave_search(f"{user_query} future trends")
|
| 1067 |
-
if results:
|
| 1068 |
-
critic_search["trends"] = results
|
| 1069 |
-
all_search_results["비평5-trends"] = results
|
| 1070 |
-
|
| 1071 |
-
critic_prompt = wuxing_system.create_critic_prompt("水 R&D", water_response, metal_response, critic_search)
|
| 1072 |
-
critic_response = ""
|
| 1073 |
-
|
| 1074 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 1075 |
-
[{"role": "user", "content": critic_prompt}], "critic"
|
| 1076 |
-
):
|
| 1077 |
-
critic_response += chunk
|
| 1078 |
-
critic_text = wuxing_system._format_critic_display(all_critics + [critic_response], 4)
|
| 1079 |
-
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, "", "🔍 土의 관점에서 水의 R&D 실행 가능성과 ROI 검증 중..."
|
| 1080 |
-
|
| 1081 |
-
all_critics.append(critic_response)
|
| 1082 |
-
|
| 1083 |
-
# 11. 木(감독관) 최종 종합
|
| 1084 |
-
wood_final_prompt = wuxing_system.create_wood_final_prompt(user_query, all_responses, all_critics)
|
| 1085 |
-
wood_final_response = ""
|
| 1086 |
-
|
| 1087 |
-
wood_text += "\n\n---\n\n🌳 **최종 전문 보고서 작성**\n🔄 Executive Summary 및 종합 전략 보고서 작성 중...\n"
|
| 1088 |
-
for chunk in wuxing_system.call_llm_streaming(
|
| 1089 |
-
[{"role": "user", "content": wood_final_prompt}], "wood"
|
| 1090 |
-
):
|
| 1091 |
-
wood_final_response += chunk
|
| 1092 |
-
temp_text = all_responses['wood_initial'] + f"\n\n---\n\n🌳 **최종 전문 보고서**\n{wood_final_response}"
|
| 1093 |
-
wood_text = f"🌳 **木 - 전략적 비전 설계자** (仁)\n{temp_text}"
|
| 1094 |
-
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, "", "🌳 McKinsey 수준의 최종 전략 보고서 작성 중..."
|
| 1095 |
-
|
| 1096 |
-
# 최종 보고서 생성 - AGI 수준 전문 보고서
|
| 1097 |
-
final_report = f"""# 🌟 AGI 협력 시스템 전문 분석 보고서
|
| 1098 |
-
|
| 1099 |
-
<div style="text-align: center; margin: 20px 0;">
|
| 1100 |
-
<h3>오행 집단지성 기반 종합 전략 보고서</h3>
|
| 1101 |
-
<p style="color: #666;">생성일시: {datetime.now().strftime('%Y년 %m월 %d일 %H:%M:%S')}</p>
|
| 1102 |
-
</div>
|
| 1103 |
-
|
| 1104 |
-
---
|
| 1105 |
-
|
| 1106 |
-
## 📋 EXECUTIVE SUMMARY
|
| 1107 |
-
|
| 1108 |
-
### 🎯 요청사항
|
| 1109 |
-
> **{user_query}**
|
| 1110 |
-
|
| 1111 |
-
### 💡 핵심 권고사항
|
| 1112 |
-
{wood_final_response[:500]}...
|
| 1113 |
-
|
| 1114 |
-
### 📊 주요 성과 지표
|
| 1115 |
-
| 구분 | 내용 | 영향도 |
|
| 1116 |
-
|------|------|--------|
|
| 1117 |
-
| **전략적 가치** | 혁신성과 차별화 | ⭐⭐⭐⭐⭐ |
|
| 1118 |
-
| **실행 가능성** | 리소스와 역량 | ⭐⭐⭐⭐ |
|
| 1119 |
-
| **예상 ROI** | 투자 대비 수익 | ⭐⭐⭐⭐⭐ |
|
| 1120 |
-
| **리스크 수준** | 관리 가능성 | ⭐⭐⭐ |
|
| 1121 |
-
|
| 1122 |
-
---
|
| 1123 |
-
|
| 1124 |
-
## 1. 전략적 분석과 비전 (木 - Chief Vision Officer)
|
| 1125 |
-
|
| 1126 |
-
### 1.1 거시적 통찰과 미래 예측
|
| 1127 |
-
{all_responses['wood_initial'][:1000]}...
|
| 1128 |
-
|
| 1129 |
-
### 1.2 시스템적 사고와 혁신 프레임워크
|
| 1130 |
-
{wood_final_response[:1500]}...
|
| 1131 |
-
|
| 1132 |
-
---
|
| 1133 |
-
|
| 1134 |
-
## 2. 혁신 전략과 비즈니스 모델 (火 - Innovation Strategy Architect)
|
| 1135 |
-
|
| 1136 |
-
### 2.1 파괴적 혁신 전략
|
| 1137 |
-
{all_responses['fire'][:1000]}...
|
| 1138 |
-
|
| 1139 |
-
### 2.2 경쟁우위 창출 방안
|
| 1140 |
-
- 차별화 전략
|
| 1141 |
-
- 가치 혁신
|
| 1142 |
-
- 플랫폼 전략
|
| 1143 |
-
|
| 1144 |
-
---
|
| 1145 |
-
|
| 1146 |
-
## 3. 실행 계획과 운영 최적화 (土 - Execution Excellence Expert)
|
| 1147 |
-
|
| 1148 |
-
### 3.1 단계별 실행 로드맵
|
| 1149 |
-
{all_responses['earth'][:1000]}...
|
| 1150 |
-
|
| 1151 |
-
### 3.2 리소스 배분과 프로젝트 거버넌스
|
| 1152 |
-
| 단계 | 기간 | 주요 활동 | 필요 리소스 | KPI |
|
| 1153 |
-
|------|------|-----------|-------------|-----|
|
| 1154 |
-
| Phase 1 | 0-6개월 | 기반 구축 | 팀 10명, $500K | 인프라 90% |
|
| 1155 |
-
| Phase 2 | 6-18개월 | 확장 | 팀 25명, $2M | 시장점유율 15% |
|
| 1156 |
-
| Phase 3 | 18-36개월 | 최적화 | 팀 50명, $5M | ROI 300% |
|
| 1157 |
-
|
| 1158 |
-
---
|
| 1159 |
-
|
| 1160 |
-
## 4. 기술 아키텍처와 시스템 설계 (金 - Systems Architecture Master)
|
| 1161 |
-
|
| 1162 |
-
### 4.1 엔터프라이즈 아키텍처
|
| 1163 |
-
{all_responses['metal'][:1000]}...
|
| 1164 |
-
|
| 1165 |
-
### 4.2 기술 스택과 표준화 전략
|
| 1166 |
-
```
|
| 1167 |
-
┌─────────────────────────────────────┐
|
| 1168 |
-
│ 프레젠테이션 계층 │
|
| 1169 |
-
├─────────────────────────────────────┤
|
| 1170 |
-
│ 비즈니스 로직 │
|
| 1171 |
-
├─────────────────────────────────────┤
|
| 1172 |
-
│ 데이터 액세스 │
|
| 1173 |
-
├─────────────────────────────────────┤
|
| 1174 |
-
│ 인프라 & 클라우드 │
|
| 1175 |
-
└─────────────────────────────────────┘
|
| 1176 |
-
```
|
| 1177 |
-
|
| 1178 |
-
---
|
| 1179 |
-
|
| 1180 |
-
## 5. 미래 기술과 R&D 전략 (水 - Future Tech Research Director)
|
| 1181 |
-
|
| 1182 |
-
### 5.1 신기술 트렌드와 융합 전략
|
| 1183 |
-
{all_responses['water'][:1000]}...
|
| 1184 |
-
|
| 1185 |
-
### 5.2 혁신 포트폴리오
|
| 1186 |
-
- **Horizon 1**: 현재 핵심 기술 최적화
|
| 1187 |
-
- **Horizon 2**: 신흥 기술 도입
|
| 1188 |
-
- **Horizon 3**: 미래 기술 R&D
|
| 1189 |
-
|
| 1190 |
-
---
|
| 1191 |
-
|
| 1192 |
-
## 6. 비평과 개선 방향 (중립적 비평 전문가)
|
| 1193 |
-
|
| 1194 |
-
### 6.1 전략적 검증과 리스크 분석
|
| 1195 |
-
{all_critics[-1][:800]}...
|
| 1196 |
-
|
| 1197 |
-
### 6.2 지속적 개선 메커니즘
|
| 1198 |
-
- 분기별 전략 리뷰
|
| 1199 |
-
- 애자일 거버넌스
|
| 1200 |
-
- 실시간 성과 모니터링
|
| 1201 |
-
|
| 1202 |
-
---
|
| 1203 |
-
|
| 1204 |
-
## 7. 결론 및 다음 단계
|
| 1205 |
-
|
| 1206 |
-
### 7.1 종합 결론
|
| 1207 |
-
본 보고서는 오행 집단지성 시스템을 통해 도출된 종합적이고 균형잡힌 전략을 제시합니다.
|
| 1208 |
-
각 전문가의 심층 분석과 중립적 비평을 통해 검증된 실행 가능한 로드맵을 수립했습니다.
|
| 1209 |
-
|
| 1210 |
-
### 7.2 즉시 실행 과제 (Quick Wins)
|
| 1211 |
-
1. **Week 1-2**: 핵심 팀 구성 및 킥오프
|
| 1212 |
-
2. **Week 3-4**: 상세 요구사항 분석
|
| 1213 |
-
3. **Month 2**: 프로토타입 개발
|
| 1214 |
-
4. **Month 3**: 파일럿 테스트
|
| 1215 |
-
|
| 1216 |
-
### 7.3 성공 요인
|
| 1217 |
-
- 🎯 명확한 비전과 전략
|
| 1218 |
-
- 💪 강력한 실행력
|
| 1219 |
-
- 🔧 견고한 기술 기반
|
| 1220 |
-
- 🚀 지속적 혁신
|
| 1221 |
-
- 📊 데이터 기반 의사결정
|
| 1222 |
-
|
| 1223 |
-
---
|
| 1224 |
-
|
| 1225 |
-
## 📈 부록: 상세 분석 데이터
|
| 1226 |
-
|
| 1227 |
-
### A. 검색 및 분석 통계
|
| 1228 |
-
| 항목 | 수치 |
|
| 1229 |
-
|------|------|
|
| 1230 |
-
| **웹 검색 수행** | {len(all_search_results)}회 |
|
| 1231 |
-
| **분석된 자료** | {sum(len(r) for r in all_search_results.values())}건 |
|
| 1232 |
-
| **협력 프로세스** | 11단계 완료 |
|
| 1233 |
-
| **AI 모델** | {'Gemini 2.5 Pro (AGI Mode)' if wuxing_system.use_gemini else 'Advanced LLM (AGI Mode)'} |
|
| 1234 |
-
| **신뢰도** | 98.7% |
|
| 1235 |
-
|
| 1236 |
-
### B. 참고 문헌 및 데이터 소스
|
| 1237 |
-
- McKinsey Global Institute Reports
|
| 1238 |
-
- MIT Technology Review
|
| 1239 |
-
- Harvard Business Review
|
| 1240 |
-
- Gartner Research
|
| 1241 |
-
- Industry Best Practices
|
| 1242 |
-
|
| 1243 |
-
### C. 오행 상극(相剋) 원리
|
| 1244 |
-
- 金克木: 시스템의 정밀성이 전략의 타당성을 검증
|
| 1245 |
-
- 水克火: 분석적 깊이가 혁신의 실현 가능성을 평가
|
| 1246 |
-
- 木克土: 거시적 비전이 실행의 방향성을 교정
|
| 1247 |
-
- 火克金: 혁신적 사고가 아키텍처의 유연성을 확보
|
| 1248 |
-
- 土克水: 실무적 관점이 R&D의 실효성을 검증
|
| 1249 |
-
|
| 1250 |
-
---
|
| 1251 |
-
|
| 1252 |
-
<div style="text-align: center; margin-top: 40px; padding: 20px; background-color: #f0f9ff; border-radius: 8px;">
|
| 1253 |
-
<p><strong>본 보고서는 AGI 수준의 오행 협력 시스템에 의해 생성되었습니다.</strong></p>
|
| 1254 |
-
<p style="color: #666;">仁義禮智信 - 다섯 가지 덕목의 조화로운 융합</p>
|
| 1255 |
-
<p style="color: #666;">相生相剋 - 상호 보완과 견제를 통한 완벽한 균형</p>
|
| 1256 |
-
<p style="font-size: 12px; color: #999;">© 2024 Wuxing AGI Collaborative System. All rights reserved.</p>
|
| 1257 |
-
</div>"""
|
| 1258 |
-
|
| 1259 |
-
status_text = f"✅ AGI 전문 보고서 생성 완료! (데이터 소스: {len(all_search_results)}개, 분석 자료: {sum(len(r) for r in all_search_results.values())}건)"
|
| 1260 |
-
yield wood_text, fire_text, earth_text, metal_text, water_text, critic_text, final_report, status_text
|
| 1261 |
-
|
| 1262 |
except Exception as e:
|
| 1263 |
-
|
| 1264 |
-
|
| 1265 |
-
|
| 1266 |
-
def clear_wuxing():
|
| 1267 |
-
"""시스템 초기화"""
|
| 1268 |
-
return "", "", "", "", "", "", "", "🔄 AGI 시스템이 초기화되었습니다."
|
| 1269 |
-
|
| 1270 |
-
# CSS 스타일
|
| 1271 |
-
css = """
|
| 1272 |
-
.gradio-container {
|
| 1273 |
-
font-family: 'Arial', sans-serif;
|
| 1274 |
-
}
|
| 1275 |
-
.wood-box textarea {
|
| 1276 |
-
border-left: 4px solid #10b981 !important;
|
| 1277 |
-
background-color: #f0fdf4 !important;
|
| 1278 |
-
}
|
| 1279 |
-
.fire-box textarea {
|
| 1280 |
-
border-left: 4px solid #ef4444 !important;
|
| 1281 |
-
background-color: #fef2f2 !important;
|
| 1282 |
-
}
|
| 1283 |
-
.earth-box textarea {
|
| 1284 |
-
border-left: 4px solid #a855f7 !important;
|
| 1285 |
-
background-color: #faf5ff !important;
|
| 1286 |
-
}
|
| 1287 |
-
.metal-box textarea {
|
| 1288 |
-
border-left: 4px solid #f59e0b !important;
|
| 1289 |
-
background-color: #fffbeb !important;
|
| 1290 |
-
}
|
| 1291 |
-
.water-box textarea {
|
| 1292 |
-
border-left: 4px solid #3b82f6 !important;
|
| 1293 |
-
background-color: #eff6ff !important;
|
| 1294 |
-
}
|
| 1295 |
-
.critic-box textarea {
|
| 1296 |
-
border-left: 4px solid #6b7280 !important;
|
| 1297 |
-
background-color: #f9fafb !important;
|
| 1298 |
-
}
|
| 1299 |
-
.final-report-box {
|
| 1300 |
-
border: 2px solid #10b981 !important;
|
| 1301 |
-
border-radius: 8px !important;
|
| 1302 |
-
padding: 20px !important;
|
| 1303 |
-
background: linear-gradient(to bottom, #f0fdf4, #ffffff) !important;
|
| 1304 |
-
margin-top: 10px !important;
|
| 1305 |
-
font-size: 14px !important;
|
| 1306 |
-
max-height: 800px !important;
|
| 1307 |
-
overflow-y: auto !important;
|
| 1308 |
-
line-height: 1.8 !important;
|
| 1309 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
|
| 1310 |
-
}
|
| 1311 |
-
.final-report-box h1 {
|
| 1312 |
-
color: #065f46 !important;
|
| 1313 |
-
font-size: 28px !important;
|
| 1314 |
-
margin-bottom: 16px !important;
|
| 1315 |
-
text-align: center !important;
|
| 1316 |
-
font-weight: bold !important;
|
| 1317 |
-
}
|
| 1318 |
-
.final-report-box h2 {
|
| 1319 |
-
color: #047857 !important;
|
| 1320 |
-
font-size: 22px !important;
|
| 1321 |
-
margin-top: 20px !important;
|
| 1322 |
-
margin-bottom: 12px !important;
|
| 1323 |
-
border-bottom: 2px solid #10b981 !important;
|
| 1324 |
-
padding-bottom: 8px !important;
|
| 1325 |
-
}
|
| 1326 |
-
.final-report-box h3 {
|
| 1327 |
-
color: #059669 !important;
|
| 1328 |
-
font-size: 18px !important;
|
| 1329 |
-
margin-top: 16px !important;
|
| 1330 |
-
margin-bottom: 10px !important;
|
| 1331 |
-
font-weight: 600 !important;
|
| 1332 |
-
}
|
| 1333 |
-
.final-report-box h4 {
|
| 1334 |
-
color: #10b981 !important;
|
| 1335 |
-
font-size: 16px !important;
|
| 1336 |
-
margin-top: 12px !important;
|
| 1337 |
-
margin-bottom: 8px !important;
|
| 1338 |
-
}
|
| 1339 |
-
.final-report-box table {
|
| 1340 |
-
border-collapse: collapse !important;
|
| 1341 |
-
width: 100% !important;
|
| 1342 |
-
margin: 20px 0 !important;
|
| 1343 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
|
| 1344 |
-
}
|
| 1345 |
-
.final-report-box th, .final-report-box td {
|
| 1346 |
-
border: 1px solid #d1d5db !important;
|
| 1347 |
-
padding: 12px 14px !important;
|
| 1348 |
-
text-align: left !important;
|
| 1349 |
-
}
|
| 1350 |
-
.final-report-box th {
|
| 1351 |
-
background-color: #065f46 !important;
|
| 1352 |
-
font-weight: bold !important;
|
| 1353 |
-
color: #ffffff !important;
|
| 1354 |
-
text-transform: uppercase !important;
|
| 1355 |
-
font-size: 13px !important;
|
| 1356 |
-
letter-spacing: 0.5px !important;
|
| 1357 |
-
}
|
| 1358 |
-
.final-report-box tr:nth-child(even) {
|
| 1359 |
-
background-color: #f9fafb !important;
|
| 1360 |
-
}
|
| 1361 |
-
.final-report-box tr:hover {
|
| 1362 |
-
background-color: #f0fdf4 !important;
|
| 1363 |
-
transition: background-color 0.2s !important;
|
| 1364 |
-
}
|
| 1365 |
-
.final-report-box code {
|
| 1366 |
-
background-color: #ecfdf5 !important;
|
| 1367 |
-
padding: 3px 8px !important;
|
| 1368 |
-
border-radius: 4px !important;
|
| 1369 |
-
font-family: 'Consolas', 'Monaco', monospace !important;
|
| 1370 |
-
color: #047857 !important;
|
| 1371 |
-
font-size: 13px !important;
|
| 1372 |
-
border: 1px solid #10b981 !important;
|
| 1373 |
-
}
|
| 1374 |
-
.final-report-box pre {
|
| 1375 |
-
background-color: #1e293b !important;
|
| 1376 |
-
color: #e2e8f0 !important;
|
| 1377 |
-
padding: 16px !important;
|
| 1378 |
-
border-radius: 8px !important;
|
| 1379 |
-
overflow-x: auto !important;
|
| 1380 |
-
margin: 16px 0 !important;
|
| 1381 |
-
font-size: 13px !important;
|
| 1382 |
-
line-height: 1.5 !important;
|
| 1383 |
-
}
|
| 1384 |
-
.final-report-box pre code {
|
| 1385 |
-
background-color: transparent !important;
|
| 1386 |
-
color: #e2e8f0 !important;
|
| 1387 |
-
padding: 0 !important;
|
| 1388 |
-
border: none !important;
|
| 1389 |
-
}
|
| 1390 |
-
.final-report-box blockquote {
|
| 1391 |
-
border-left: 4px solid #10b981 !important;
|
| 1392 |
-
padding-left: 16px !important;
|
| 1393 |
-
margin: 16px 0 !important;
|
| 1394 |
-
color: #064e3b !important;
|
| 1395 |
-
font-style: italic !important;
|
| 1396 |
-
background-color: #f0fdf4 !important;
|
| 1397 |
-
padding: 14px 16px !important;
|
| 1398 |
-
border-radius: 0 8px 8px 0 !important;
|
| 1399 |
-
}
|
| 1400 |
-
.final-report-box ul, .final-report-box ol {
|
| 1401 |
-
margin-left: 24px !important;
|
| 1402 |
-
margin-bottom: 16px !important;
|
| 1403 |
-
}
|
| 1404 |
-
.final-report-box li {
|
| 1405 |
-
margin-bottom: 8px !important;
|
| 1406 |
-
line-height: 1.8 !important;
|
| 1407 |
-
}
|
| 1408 |
-
.final-report-box strong {
|
| 1409 |
-
color: #065f46 !important;
|
| 1410 |
-
font-weight: 600 !important;
|
| 1411 |
-
}
|
| 1412 |
-
.final-report-box em {
|
| 1413 |
-
color: #047857 !important;
|
| 1414 |
-
}
|
| 1415 |
-
.final-report-box hr {
|
| 1416 |
-
border: none !important;
|
| 1417 |
-
border-top: 2px solid #10b981 !important;
|
| 1418 |
-
margin: 28px 0 !important;
|
| 1419 |
-
}
|
| 1420 |
-
.final-report-box a {
|
| 1421 |
-
color: #059669 !important;
|
| 1422 |
-
text-decoration: underline !important;
|
| 1423 |
-
}
|
| 1424 |
-
.final-report-box a:hover {
|
| 1425 |
-
color: #047857 !important;
|
| 1426 |
-
}
|
| 1427 |
-
h1 {
|
| 1428 |
-
text-align: center;
|
| 1429 |
-
color: #1f2937;
|
| 1430 |
-
margin-bottom: 10px;
|
| 1431 |
-
}
|
| 1432 |
-
h3 {
|
| 1433 |
-
font-weight: 600;
|
| 1434 |
-
margin-bottom: 8px;
|
| 1435 |
-
}
|
| 1436 |
-
.gradio-container {
|
| 1437 |
-
max-width: 1400px;
|
| 1438 |
-
margin: 0 auto;
|
| 1439 |
-
}
|
| 1440 |
-
"""
|
| 1441 |
-
|
| 1442 |
-
# Gradio 인터페이스
|
| 1443 |
-
with gr.Blocks(
|
| 1444 |
-
title="AGI 오행 전문 보고서 시스템",
|
| 1445 |
-
theme=gr.themes.Soft(),
|
| 1446 |
-
css=css,
|
| 1447 |
-
analytics_enabled=False
|
| 1448 |
-
) as app:
|
| 1449 |
-
gr.Markdown(
|
| 1450 |
-
"""
|
| 1451 |
-
# 🌟 AGI 수준 오행·오상 기반 전문 보고서 작성 시스템
|
| 1452 |
-
|
| 1453 |
-
### 🚀 차세대 인공지능 집단지성 플랫폼
|
| 1454 |
-
|
| 1455 |
-
> **"다섯 가지 전문성의 시너지로 창출하는 최고 수준의 전략 보고서"**
|
| 1456 |
-
|
| 1457 |
-
### 📋 프로세스: 木→비평→火→비평→土→비평→金→비평→水→비평→木(최종)
|
| 1458 |
-
|
| 1459 |
-
| 역할 | 덕목·오행 | AGI 전문성 |
|
| 1460 |
-
|------|-----------|-------------|
|
| 1461 |
-
| 🌳 **전략적 비전 설계자** | 仁·木 | 미래예측, 시스템적 사고, 혁신 전략 |
|
| 1462 |
-
| 🔥 **혁신 전략 아키텍트** | 義·火 | 파괴적 혁신, 비즈니스 모델, 경쟁우위 |
|
| 1463 |
-
| 🏔️ **실행 최적화 전문가** | 信·土 | 프로젝트 거버넌스, 품질 시스템, ROI |
|
| 1464 |
-
| ⚙️ **시스템 아키텍처 마스터** | 禮·金 | 엔터프라이즈 설계, 기술 표준, 확장성 |
|
| 1465 |
-
| 💧 **미래기술 연구소장** | 智·水 | 신기술 R&D, AI/ML, 기술 융합 |
|
| 1466 |
-
| 🔍 **전략 검증 전문가** | 상극 원리 | 오행 상극에 따른 비평 (金克木, 水克火, 木克土, 火克金, 土克水) |
|
| 1467 |
-
|
| 1468 |
-
---
|
| 1469 |
-
|
| 1470 |
-
**💡 본 시스템은 AGI(Artificial General Intelligence) 수준의 분석력과 창의성을 바탕으로**
|
| 1471 |
-
**McKinsey, BCG, Bain 수준의 전문 컨설팅 보고서를 자동으로 생성합니다.**
|
| 1472 |
-
"""
|
| 1473 |
-
)
|
| 1474 |
-
|
| 1475 |
-
with gr.Row():
|
| 1476 |
-
with gr.Column(scale=3):
|
| 1477 |
-
llm_mode = gr.Radio(
|
| 1478 |
-
choices=["default", "commercial"],
|
| 1479 |
-
value="commercial",
|
| 1480 |
-
label="AI 모델 선택",
|
| 1481 |
-
info="commercial: Gemini 2.5 Pro (AGI Mode) - 권장"
|
| 1482 |
-
)
|
| 1483 |
-
|
| 1484 |
-
user_input = gr.Textbox(
|
| 1485 |
-
label="보고서 요청사항",
|
| 1486 |
-
placeholder="예: 우리 회사의 디지털 전환 전략과 3개년 실행 로드맵을 수립해주세요",
|
| 1487 |
-
lines=4
|
| 1488 |
-
)
|
| 1489 |
-
|
| 1490 |
-
with gr.Row():
|
| 1491 |
-
submit_btn = gr.Button("🚀 전문 보고서 생성", variant="primary", scale=2)
|
| 1492 |
-
clear_btn = gr.Button("🗑️ 초기화", scale=1)
|
| 1493 |
-
|
| 1494 |
-
with gr.Column(scale=1):
|
| 1495 |
-
status_text = gr.Textbox(
|
| 1496 |
-
label="프로세스 상태",
|
| 1497 |
-
interactive=False,
|
| 1498 |
-
value="AGI 시스템 대기 중...",
|
| 1499 |
-
lines=3
|
| 1500 |
-
)
|
| 1501 |
-
|
| 1502 |
-
# 최종 보고서 섹션
|
| 1503 |
-
with gr.Row():
|
| 1504 |
-
with gr.Column():
|
| 1505 |
-
gr.Markdown("""
|
| 1506 |
-
### 📊 최종 전문 분석 보고서
|
| 1507 |
-
<p style="color: #666; margin-top: -10px;">Executive Summary & Strategic Recommendations</p>
|
| 1508 |
-
""")
|
| 1509 |
-
final_report = gr.Markdown(
|
| 1510 |
-
value="*AGI 수준의 전문 보고서가 여기에 생성됩니다.*",
|
| 1511 |
-
elem_classes=["final-report-box"]
|
| 1512 |
-
)
|
| 1513 |
-
|
| 1514 |
-
# 오행 출력 - 2x3 그리드
|
| 1515 |
-
with gr.Row():
|
| 1516 |
-
with gr.Column():
|
| 1517 |
-
gr.Markdown("### 🌳 木 - 전략적 비전 설계자 (仁)")
|
| 1518 |
-
wood_output = gr.Textbox(
|
| 1519 |
-
label="",
|
| 1520 |
-
lines=12,
|
| 1521 |
-
max_lines=18,
|
| 1522 |
-
interactive=False,
|
| 1523 |
-
elem_classes=["wood-box"]
|
| 1524 |
-
)
|
| 1525 |
-
|
| 1526 |
-
with gr.Column():
|
| 1527 |
-
gr.Markdown("### 🔥 火 - 혁신 전략 아키텍트 (義)")
|
| 1528 |
-
fire_output = gr.Textbox(
|
| 1529 |
-
label="",
|
| 1530 |
-
lines=12,
|
| 1531 |
-
max_lines=18,
|
| 1532 |
-
interactive=False,
|
| 1533 |
-
elem_classes=["fire-box"]
|
| 1534 |
-
)
|
| 1535 |
-
|
| 1536 |
-
with gr.Row():
|
| 1537 |
-
with gr.Column():
|
| 1538 |
-
gr.Markdown("### 🏔️ 土 - 실행 최적화 전문가 (信)")
|
| 1539 |
-
earth_output = gr.Textbox(
|
| 1540 |
-
label="",
|
| 1541 |
-
lines=12,
|
| 1542 |
-
max_lines=18,
|
| 1543 |
-
interactive=False,
|
| 1544 |
-
elem_classes=["earth-box"]
|
| 1545 |
-
)
|
| 1546 |
-
|
| 1547 |
-
with gr.Column():
|
| 1548 |
-
gr.Markdown("### ⚙️ 金 - 시스템 아키텍처 마스터 (禮)")
|
| 1549 |
-
metal_output = gr.Textbox(
|
| 1550 |
-
label="",
|
| 1551 |
-
lines=12,
|
| 1552 |
-
max_lines=18,
|
| 1553 |
-
interactive=False,
|
| 1554 |
-
elem_classes=["metal-box"]
|
| 1555 |
-
)
|
| 1556 |
-
|
| 1557 |
-
with gr.Row():
|
| 1558 |
-
with gr.Column():
|
| 1559 |
-
gr.Markdown("### 💧 水 - 미래기술 연구소장 (智)")
|
| 1560 |
-
water_output = gr.Textbox(
|
| 1561 |
-
label="",
|
| 1562 |
-
lines=12,
|
| 1563 |
-
max_lines=18,
|
| 1564 |
-
interactive=False,
|
| 1565 |
-
elem_classes=["water-box"]
|
| 1566 |
-
)
|
| 1567 |
-
|
| 1568 |
-
with gr.Column():
|
| 1569 |
-
gr.Markdown("### 🔍 전략 검증 전문가 (오행 상극)")
|
| 1570 |
-
critic_output = gr.Textbox(
|
| 1571 |
-
label="",
|
| 1572 |
-
lines=12,
|
| 1573 |
-
max_lines=18,
|
| 1574 |
-
interactive=False,
|
| 1575 |
-
elem_classes=["critic-box"]
|
| 1576 |
-
)
|
| 1577 |
-
|
| 1578 |
-
# 예제
|
| 1579 |
-
gr.Examples(
|
| 1580 |
-
examples=[
|
| 1581 |
-
"우리 회사의 디지털 전환 전략과 3개년 실행 로드맵을 수립해주세요",
|
| 1582 |
-
"글로벌 시장 진출을 위한 종합적인 사업 전략과 리스크 분석 보고서를 작성해주세요",
|
| 1583 |
-
"AI 기반 신규 비즈니스 모델 개발과 수익화 전략을 제안해주세요",
|
| 1584 |
-
"ESG 경영 체계 구축과 지속가능성 전략 보고서를 작성해주세요",
|
| 1585 |
-
"메타버스 플랫폼 구축을 위한 기술 아키텍처와 사업 계획을 수립해주세요",
|
| 1586 |
-
"공급망 최적화와 스마트 팩토리 전환 전략을 분석해주세요",
|
| 1587 |
-
"데이터 기반 의사결정 체계 구축 방안과 거버넌스 모델을 제시해주세요",
|
| 1588 |
-
"고객 경험 혁신을 위한 옴니채널 전략과 실행 계획을 수립해주세요"
|
| 1589 |
-
],
|
| 1590 |
-
inputs=user_input,
|
| 1591 |
-
label="💡 전문 보고서 예제"
|
| 1592 |
-
)
|
| 1593 |
-
|
| 1594 |
-
# 이벤트 핸들러
|
| 1595 |
-
submit_btn.click(
|
| 1596 |
-
fn=process_wuxing_query,
|
| 1597 |
-
inputs=[user_input, llm_mode],
|
| 1598 |
-
outputs=[wood_output, fire_output, earth_output, metal_output, water_output, critic_output, final_report, status_text]
|
| 1599 |
-
).then(
|
| 1600 |
-
fn=lambda: "",
|
| 1601 |
-
outputs=[user_input]
|
| 1602 |
-
)
|
| 1603 |
-
|
| 1604 |
-
user_input.submit(
|
| 1605 |
-
fn=process_wuxing_query,
|
| 1606 |
-
inputs=[user_input, llm_mode],
|
| 1607 |
-
outputs=[wood_output, fire_output, earth_output, metal_output, water_output, critic_output, final_report, status_text]
|
| 1608 |
-
).then(
|
| 1609 |
-
fn=lambda: "",
|
| 1610 |
-
outputs=[user_input]
|
| 1611 |
-
)
|
| 1612 |
-
|
| 1613 |
-
clear_btn.click(
|
| 1614 |
-
fn=clear_wuxing,
|
| 1615 |
-
outputs=[wood_output, fire_output, earth_output, metal_output, water_output, critic_output, final_report, status_text]
|
| 1616 |
-
)
|
| 1617 |
|
| 1618 |
if __name__ == "__main__":
|
| 1619 |
-
|
| 1620 |
-
app.launch(
|
| 1621 |
-
server_name="0.0.0.0",
|
| 1622 |
-
server_port=7860,
|
| 1623 |
-
share=True,
|
| 1624 |
-
show_error=True
|
| 1625 |
-
)
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from tempfile import NamedTemporaryFile
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def main():
|
| 7 |
+
try:
|
| 8 |
+
# Get the code from secrets
|
| 9 |
+
code = os.environ.get("MAIN_CODE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
| 13 |
return
|
| 14 |
|
| 15 |
+
# Create a temporary Python file
|
| 16 |
+
with NamedTemporaryFile(suffix='.py', delete=False, mode='w') as tmp:
|
| 17 |
+
tmp.write(code)
|
| 18 |
+
tmp_path = tmp.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Execute the code
|
| 21 |
+
exec(compile(code, tmp_path, 'exec'), globals())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Clean up the temporary file
|
| 24 |
try:
|
| 25 |
+
os.unlink(tmp_path)
|
| 26 |
+
except:
|
| 27 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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