-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
91 lines (77 loc) · 2.75 KB
/
main.py
File metadata and controls
91 lines (77 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# main.py
import asyncio
import json
from config. settings import Settings
from utils.url_parser import parse_github_url
from graph.spoon_graph import create_analysis_graph
from services.chatbot_service import SummaryChatBot
async def main():
try:
Settings.validate()
except ValueError as e:
print(f"❌ {e}")
return
print("="*60)
print("🚀 SpoonAI - Graph-based Repository Analyzer")
print("="*60)
# 사용자 입력
repo_url = input("\n🔗 GitHub URL: ").strip()
owner, repo = parse_github_url(repo_url)
if not owner or not repo:
print("❌ Invalid GitHub URL")
return
# Graph 생성
print("\n📊 Building analysis graph...")
graph = create_analysis_graph()
# 초기 상태
initial_state = {
"owner": owner,
"repo": repo,
"readme": "",
"file_tree": [],
"code_samples": [],
"languages": {},
"llm_summary": None,
"security_report": None,
"final_report": None,
"current_step": "initialized",
"errors": []
}
# Graph 실행
print(f"\n🔄 Running analysis pipeline for {owner}/{repo}\n")
try:
final_state = await graph.invoke(initial_state)
# ✅ 최종 리포트 가져오기
report = final_state.get("final_report", {})
llm_summary = final_state.get("llm_summary") or report.get("analysis", {}).get("llm_summary") or {}
# ✅ JSON 형식으로 예쁘게 출력
print("\n" + "="*60)
print("✅ Analysis Complete!")
print("="*60)
print("\n📄 Result:\n")
print(json.dumps(report, ensure_ascii=False, indent=2))
# 💬 추가 질의 기반 요약 보강 챗봇
chatbot = SummaryChatBot(llm_summary)
print("\n💬 추가 질의로 요약을 보강할 수 있습니다. (그냥 Enter 입력 시 종료)")
while True:
follow_up = input("\n질문을 입력하세요: ").strip()
if not follow_up:
break
try:
refined = await chatbot.enhance(follow_up)
print("\n📦 업데이트된 요약(JSON):\n")
print(json.dumps(refined, ensure_ascii=False, indent=2))
except Exception as e:
print(f"❌ 보강 중 오류: {e}")
# 에러 출력 (있는 경우)
errors = final_state.get("errors", [])
if errors:
print(f"\n⚠️ Warnings/Errors:")
for error in errors:
print(f" - {error}")
except Exception as e:
print(f"\n❌ Error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
asyncio.run(main())