Files
youlbot/config.py
T
shinalok 68f741af72 Phase 17: Multimodal image understanding via analyze_image tool
Dual-model approach (C): Qwen3-8B handles conversation, Qwen2.5-VL-7B
analyzes images on demand via analyze_image LangChain tool.

- services/model/mlx_vision_model.py: MlxVisionModel (mlx-vlm wrapper, lazy load)
- services/agent/tools.py: make_vision_tool(vision_model, image_path)
- agent_service.py: stream_response(image_path=None), dynamic tool binding
  via config["image_path"] — thread-safe per-request rebinding
- container.py: vision_model Singleton provider
- config.py: vision_enabled, vision_model_id, vision_max_tokens
- api.py: image_base64 in ChatRequest, decode to temp file, cleanup after stream

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 13:52:10 +09:00

88 lines
4.0 KiB
Python

from pydantic_settings import BaseSettings, SettingsConfigDict
class Config(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
frozen=True,
extra="ignore",
)
# LLM
model_id: str = "mlx-community/Qwen3-14B-4bit"
max_tokens: int = 1024
max_history_turns: int = 10
compact_threshold: int = 20
enable_thinking: bool = True
think_verbose: bool = False
# MySQL
db_host: str = "localhost"
db_port: int = 3306
db_name: str = "youlbot"
db_user: str = ""
db_password: str = ""
# Qdrant
qdrant_url: str = "http://localhost:6333"
qdrant_collection: str = "youlbot_docs"
# Embedding
embedding_model_id: str = "BAAI/bge-m3"
embedding_device: str = "mps"
# RAG
rag_top_k: int = 3
semantic_breakpoint_threshold_type: str = "percentile" # percentile | standard_deviation | interquartile | gradient
semantic_buffer_size: int = 1 # 인접 문장 몇 개를 묶어 임베딩할지 (1=단일 문장, 2=전후 1문장 포함)
# Reranker (RERANKER_ENABLED=true 시 활성화)
reranker_enabled: bool = False
reranker_model_id: str = "cross-encoder/mmarco-mMiniLMv2-L12-H384-v1" # 한국어 지원 다국어 모델
reranker_fetch_k: int = 10 # rerank 전 벡터 검색 후보 수 (rag_top_k보다 커야 함)
# Hybrid Search (Phase 18) — BM25 + Vector
hybrid_search_enabled: bool = False
sparse_model_id: str = "Qdrant/bm25" # fastembed sparse 모델 (언어 무관 BM25)
# Query Rewriting (Phase 19) — 구어체 질문을 검색 최적화 쿼리로 변환
query_rewrite_enabled: bool = False
# REST API (Phase 22) — 빈 문자열이면 인증 스킵 (개발 모드)
api_token: str = ""
rag_verbose: bool = False
rag_show_sources: bool = False
langgraph_verbose: bool = False
# Voice (Phase 14)
whisper_model_size: str = "small"
tts_voice: str = "Yuna" # macOS say 명령어 한국어 음성
# Vision (Phase 17)
vision_enabled: bool = False
vision_model_id: str = "mlx-community/Qwen2.5-VL-7B-Instruct-4bit"
vision_max_tokens: int = 512
system_prompt: str = """모든 사고 과정(thinking)과 답변은 반드시 한국어로만 작성하세요. 영어 사용 절대 금지.
당신의 이름은 '율봇'입니다. 친절하고 따뜻한 한국어 상담 도우미입니다.
육아와 금융 두 분야를 전문으로 합니다.
- 육아: 아이 발달, 이유식, 수면, 훈육, 교육 등 부모가 궁금해하는 모든 것을 도와드립니다.
- 금융: 저축, 투자, 보험, 대출, 세금 등 생활 금융 관련 질문에 답변드립니다.
항상 쉽고 친근한 말투로 설명하고, 전문 용어는 풀어서 설명합니다.
의학적 진단이나 법적 판단이 필요한 경우에는 반드시 전문가 상담을 권유합니다.
## 사용자 정보 기억 규칙
대화 중 사용자가 가족(아이 이름·생년, 배우자, 자녀 수 등), 직업, 거주지, 재정 목표, 건강 상황 등 개인 정보를 언급하면 즉시 remember_user_info로 저장하세요.
- 아이 나이는 생년월일 전체를 저장합니다. (예: key='첫째_이름' value='신도율' / key='첫째_생년월일' value='2020년 6월 19일')
- 사용자 정보 섹션에 나이가 표시되어 있으면 그 값을 그대로 사용하세요. 직접 계산하지 마세요.
- 나이를 직접 계산해야 할 경우에는 반드시 get_current_date 도구를 먼저 호출하여 오늘 날짜를 확인하세요.
- 나이는 항상 한국 나이와 만 나이를 함께 알려주세요. (한국 나이 = 현재 연도 - 출생 연도 + 1 / 만 나이 = 생일이 지났으면 현재 연도 - 출생 연도, 생일이 안 지났으면 -1)
## 문서 검색 규칙
육아·금융 관련 질문이라면 자신의 학습 지식으로 직접 답하지 말고, 반드시 search_documents 도구를 먼저 호출하세요.
검색 결과가 없거나 관련 문서가 등록되어 있지 않은 경우에만 학습 지식을 보조적으로 활용합니다."""