feat(animal-chat): 로깅 시스템 구축
- SQLite DB: animal_chat_logs.db - 로거 모듈: utils/animal_chat_logger.py - 단계별 로깅: - MSSQL (보유 동물약): 개수, 소요시간 - PostgreSQL (RAG): 개수, 소요시간 - LanceDB (벡터 검색): 상위 N개, 유사도, 소스, 소요시간 - OpenAI: 모델, 토큰(입력/출력), 비용, 소요시간 - Admin 페이지: /admin/animal-chat-logs - API: /api/animal-chat-logs - 통계: 총 대화, 평균 응답시간, 총 토큰, 총 비용
This commit is contained in:
47
backend/db/animal_chat_logs_schema.sql
Normal file
47
backend/db/animal_chat_logs_schema.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
-- 동물약 챗봇 로그 스키마
|
||||
-- 생성일: 2026-03-08
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chat_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
session_id TEXT,
|
||||
|
||||
-- 입력
|
||||
user_message TEXT,
|
||||
history_length INTEGER,
|
||||
|
||||
-- MSSQL (보유 동물약)
|
||||
mssql_drug_count INTEGER,
|
||||
mssql_duration_ms INTEGER,
|
||||
|
||||
-- PostgreSQL (RAG)
|
||||
pgsql_rag_count INTEGER,
|
||||
pgsql_duration_ms INTEGER,
|
||||
|
||||
-- LanceDB (벡터 검색)
|
||||
vector_results_count INTEGER,
|
||||
vector_top_scores TEXT, -- JSON: [0.92, 0.85, 0.78]
|
||||
vector_sources TEXT, -- JSON: ["file1.md#section", ...]
|
||||
vector_duration_ms INTEGER,
|
||||
|
||||
-- OpenAI
|
||||
openai_model TEXT,
|
||||
openai_prompt_tokens INTEGER,
|
||||
openai_completion_tokens INTEGER,
|
||||
openai_total_tokens INTEGER,
|
||||
openai_cost_usd REAL,
|
||||
openai_duration_ms INTEGER,
|
||||
|
||||
-- 출력
|
||||
assistant_response TEXT,
|
||||
products_mentioned TEXT, -- JSON array
|
||||
|
||||
-- 메타
|
||||
total_duration_ms INTEGER,
|
||||
error TEXT,
|
||||
created_at TEXT DEFAULT (datetime('now', 'localtime'))
|
||||
);
|
||||
|
||||
-- 인덱스
|
||||
CREATE INDEX IF NOT EXISTS idx_chat_created ON chat_logs(created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_chat_session ON chat_logs(session_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chat_error ON chat_logs(error);
|
||||
Reference in New Issue
Block a user