feat: AI 서비스 및 AI 어시스턴트 전용 페이지 추가
- ai-service: Ollama 기반 AI 서비스 (분류, 시맨틱 검색, RAG Q&A, 패턴 분석) - AI 어시스턴트 페이지: 채팅형 Q&A, 시맨틱 검색, 패턴 분석, 분류 테스트 - 권한 시스템에 ai_assistant 페이지 등록 (기본 비활성) - 기존 페이지에 AI 기능 통합 (대시보드, 수신함, 관리함) - docker-compose, gateway, nginx 설정 업데이트 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
0
ai-service/routers/__init__.py
Normal file
0
ai-service/routers/__init__.py
Normal file
47
ai-service/routers/classification.py
Normal file
47
ai-service/routers/classification.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
from services.classification_service import (
|
||||
classify_issue,
|
||||
summarize_issue,
|
||||
classify_and_summarize,
|
||||
)
|
||||
|
||||
router = APIRouter(tags=["classification"])
|
||||
|
||||
|
||||
class ClassifyRequest(BaseModel):
|
||||
description: str
|
||||
detail_notes: str = ""
|
||||
|
||||
|
||||
class SummarizeRequest(BaseModel):
|
||||
description: str
|
||||
detail_notes: str = ""
|
||||
solution: str = ""
|
||||
|
||||
|
||||
@router.post("/classify")
|
||||
async def classify(req: ClassifyRequest):
|
||||
try:
|
||||
result = await classify_issue(req.description, req.detail_notes)
|
||||
return {"available": True, **result}
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
|
||||
|
||||
@router.post("/summarize")
|
||||
async def summarize(req: SummarizeRequest):
|
||||
try:
|
||||
result = await summarize_issue(req.description, req.detail_notes, req.solution)
|
||||
return {"available": True, **result}
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
|
||||
|
||||
@router.post("/classify-and-summarize")
|
||||
async def classify_and_summarize_endpoint(req: ClassifyRequest):
|
||||
try:
|
||||
result = await classify_and_summarize(req.description, req.detail_notes)
|
||||
return {"available": True, **result}
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
33
ai-service/routers/daily_report.py
Normal file
33
ai-service/routers/daily_report.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from fastapi import APIRouter, Request
|
||||
from pydantic import BaseModel
|
||||
from services.report_service import generate_daily_report
|
||||
from datetime import date
|
||||
|
||||
router = APIRouter(tags=["daily_report"])
|
||||
|
||||
|
||||
class DailyReportRequest(BaseModel):
|
||||
date: str | None = None
|
||||
project_id: int | None = None
|
||||
|
||||
|
||||
@router.post("/report/daily")
|
||||
async def daily_report(req: DailyReportRequest, request: Request):
|
||||
report_date = req.date or date.today().isoformat()
|
||||
token = request.headers.get("authorization", "").replace("Bearer ", "")
|
||||
try:
|
||||
result = await generate_daily_report(report_date, req.project_id, token)
|
||||
return {"available": True, **result}
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
|
||||
|
||||
@router.post("/report/preview")
|
||||
async def report_preview(req: DailyReportRequest, request: Request):
|
||||
report_date = req.date or date.today().isoformat()
|
||||
token = request.headers.get("authorization", "").replace("Bearer ", "")
|
||||
try:
|
||||
result = await generate_daily_report(report_date, req.project_id, token)
|
||||
return {"available": True, "preview": True, **result}
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
77
ai-service/routers/embeddings.py
Normal file
77
ai-service/routers/embeddings.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from fastapi import APIRouter, BackgroundTasks, Query
|
||||
from pydantic import BaseModel
|
||||
from services.embedding_service import (
|
||||
sync_all_issues,
|
||||
sync_single_issue,
|
||||
sync_incremental,
|
||||
search_similar_by_id,
|
||||
search_similar_by_text,
|
||||
)
|
||||
from db.vector_store import vector_store
|
||||
|
||||
router = APIRouter(tags=["embeddings"])
|
||||
|
||||
|
||||
class SyncSingleRequest(BaseModel):
|
||||
issue_id: int
|
||||
|
||||
|
||||
class SearchRequest(BaseModel):
|
||||
query: str
|
||||
n_results: int = 5
|
||||
project_id: int | None = None
|
||||
category: str | None = None
|
||||
|
||||
|
||||
@router.post("/embeddings/sync")
|
||||
async def sync_embeddings(background_tasks: BackgroundTasks):
|
||||
background_tasks.add_task(sync_all_issues)
|
||||
return {"status": "sync_started", "message": "전체 임베딩 동기화가 시작되었습니다"}
|
||||
|
||||
|
||||
@router.post("/embeddings/sync-full")
|
||||
async def sync_embeddings_full():
|
||||
result = await sync_all_issues()
|
||||
return {"status": "completed", **result}
|
||||
|
||||
|
||||
@router.post("/embeddings/sync-single")
|
||||
async def sync_single(req: SyncSingleRequest):
|
||||
result = await sync_single_issue(req.issue_id)
|
||||
return result
|
||||
|
||||
|
||||
@router.post("/embeddings/sync-incremental")
|
||||
async def sync_incr():
|
||||
result = await sync_incremental()
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/similar/{issue_id}")
|
||||
async def get_similar(issue_id: int, n_results: int = Query(default=5, le=20)):
|
||||
try:
|
||||
results = await search_similar_by_id(issue_id, n_results)
|
||||
return {"available": True, "results": results, "query_issue_id": issue_id}
|
||||
except Exception as e:
|
||||
return {"available": False, "results": [], "error": str(e)}
|
||||
|
||||
|
||||
@router.post("/similar/search")
|
||||
async def search_similar(req: SearchRequest):
|
||||
filters = {}
|
||||
if req.project_id is not None:
|
||||
filters["project_id"] = str(req.project_id)
|
||||
if req.category:
|
||||
filters["category"] = req.category
|
||||
try:
|
||||
results = await search_similar_by_text(
|
||||
req.query, req.n_results, filters or None
|
||||
)
|
||||
return {"available": True, "results": results}
|
||||
except Exception as e:
|
||||
return {"available": False, "results": [], "error": str(e)}
|
||||
|
||||
|
||||
@router.get("/embeddings/stats")
|
||||
async def embedding_stats():
|
||||
return vector_store.stats()
|
||||
21
ai-service/routers/health.py
Normal file
21
ai-service/routers/health.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from fastapi import APIRouter
|
||||
from services.ollama_client import ollama_client
|
||||
from db.vector_store import vector_store
|
||||
|
||||
router = APIRouter(tags=["health"])
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def health_check():
|
||||
ollama_status = await ollama_client.check_health()
|
||||
return {
|
||||
"status": "ok",
|
||||
"service": "tk-ai-service",
|
||||
"ollama": ollama_status,
|
||||
"embeddings": vector_store.stats(),
|
||||
}
|
||||
|
||||
|
||||
@router.get("/models")
|
||||
async def list_models():
|
||||
return await ollama_client.check_health()
|
||||
57
ai-service/routers/rag.py
Normal file
57
ai-service/routers/rag.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
from services.rag_service import (
|
||||
rag_suggest_solution,
|
||||
rag_ask,
|
||||
rag_analyze_pattern,
|
||||
rag_classify_with_context,
|
||||
)
|
||||
|
||||
router = APIRouter(tags=["rag"])
|
||||
|
||||
|
||||
class AskRequest(BaseModel):
|
||||
question: str
|
||||
project_id: int | None = None
|
||||
|
||||
|
||||
class PatternRequest(BaseModel):
|
||||
description: str
|
||||
n_results: int = 10
|
||||
|
||||
|
||||
class ClassifyRequest(BaseModel):
|
||||
description: str
|
||||
detail_notes: str = ""
|
||||
|
||||
|
||||
@router.post("/rag/suggest-solution/{issue_id}")
|
||||
async def suggest_solution(issue_id: int):
|
||||
try:
|
||||
return await rag_suggest_solution(issue_id)
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
|
||||
|
||||
@router.post("/rag/ask")
|
||||
async def ask_question(req: AskRequest):
|
||||
try:
|
||||
return await rag_ask(req.question, req.project_id)
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
|
||||
|
||||
@router.post("/rag/pattern")
|
||||
async def analyze_pattern(req: PatternRequest):
|
||||
try:
|
||||
return await rag_analyze_pattern(req.description, req.n_results)
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
|
||||
|
||||
@router.post("/rag/classify")
|
||||
async def classify_with_rag(req: ClassifyRequest):
|
||||
try:
|
||||
return await rag_classify_with_context(req.description, req.detail_notes)
|
||||
except Exception as e:
|
||||
return {"available": False, "error": str(e)}
|
||||
Reference in New Issue
Block a user