Skip to content

Commit 2606993

Browse files
authored
Merge pull request #26 from kookmin-sw/feature/#17-ai-scaffolding
[#17][AI] ai/ 프로젝트 스캐폴딩 + config + exceptions
2 parents a2283a8 + f3cba23 commit 2606993

18 files changed

Lines changed: 236 additions & 0 deletions

ai/.gitkeep

Whitespace-only changes.

ai/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Poco AI Orchestrator — backend 의존성 없이 독립 동작하는 AI 모듈."""

ai/clients/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ai/clients — Bedrock Claude + KB 클라이언트

ai/config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""환경 변수 기반 AI 모듈 설정.
2+
3+
backend 의존성 없이 독립 동작하며, pydantic-settings로 환경 변수를 로드한다.
4+
"""
5+
6+
from pydantic_settings import BaseSettings, SettingsConfigDict
7+
8+
9+
class AISettings(BaseSettings):
10+
"""AI 모듈 환경 설정.
11+
12+
환경 변수 또는 .env 파일에서 값을 로드한다.
13+
모든 필드에 sensible default가 있으므로 최소 설정으로 동작 가능.
14+
"""
15+
16+
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
17+
18+
AWS_REGION: str = "ap-northeast-2"
19+
MODEL_ID: str = "anthropic.claude-3-5-sonnet-20241022-v2:0"
20+
KB_A_ID: str = ""
21+
KB_B_ID: str = ""
22+
MAX_TOKENS: int = 4096
23+
TEMPERATURE: float = 0.7
24+
25+
26+
ai_settings = AISettings()

ai/exceptions.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""AI 모듈 커스텀 예외 및 에러 코드.
2+
3+
backend 의존성(FastAPI 등) 없이 독립 동작한다.
4+
"""
5+
6+
from enum import Enum
7+
8+
9+
class AIErrorCode(str, Enum):
10+
"""AI 모듈 에러 코드."""
11+
12+
AI_GENERATION_FAILED = "AI_GENERATION_FAILED"
13+
SCHEMA_VALIDATION_ERROR = "SCHEMA_VALIDATION_ERROR"
14+
RAG_SEARCH_FAILED = "RAG_SEARCH_FAILED"
15+
PROMPT_TEMPLATE_NOT_FOUND = "PROMPT_TEMPLATE_NOT_FOUND"
16+
BEDROCK_API_ERROR = "BEDROCK_API_ERROR"
17+
18+
19+
class AIError(Exception):
20+
"""AI 모듈 기반 예외 클래스."""
21+
22+
def __init__(self, code: AIErrorCode, message: str, details: dict | None = None):
23+
self.code = code
24+
self.message = message
25+
self.details = details or {}
26+
super().__init__(f"[{code.value}] {message}")
27+
28+
29+
class AIGenerationFailedError(AIError):
30+
"""Claude 호출 실패 또는 재시도 초과."""
31+
32+
def __init__(self, message: str = "AI 생성에 실패했습니다.", details: dict | None = None):
33+
super().__init__(AIErrorCode.AI_GENERATION_FAILED, message, details)
34+
35+
36+
class SchemaValidationError(AIError):
37+
"""출력 스키마 불일치."""
38+
39+
def __init__(self, message: str = "응답 스키마 검증에 실패했습니다.", details: dict | None = None):
40+
super().__init__(AIErrorCode.SCHEMA_VALIDATION_ERROR, message, details)
41+
42+
43+
class RAGSearchFailedError(AIError):
44+
"""KB 검색 실패 (비치명적)."""
45+
46+
def __init__(self, message: str = "RAG 검색에 실패했습니다.", details: dict | None = None):
47+
super().__init__(AIErrorCode.RAG_SEARCH_FAILED, message, details)
48+
49+
50+
class PromptTemplateNotFoundError(AIError):
51+
"""프롬프트 파일 미존재."""
52+
53+
def __init__(self, message: str = "프롬프트 템플릿을 찾을 수 없습니다.", details: dict | None = None):
54+
super().__init__(AIErrorCode.PROMPT_TEMPLATE_NOT_FOUND, message, details)
55+
56+
57+
class BedrockAPIError(AIError):
58+
"""Bedrock API 레벨 에러 (throttling, timeout 등)."""
59+
60+
def __init__(self, message: str = "Bedrock API 호출에 실패했습니다.", details: dict | None = None):
61+
super().__init__(AIErrorCode.BEDROCK_API_ERROR, message, details)

ai/prompts/accept.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{# accept 프롬프트 템플릿 — Phase 3에서 구현 #}

ai/prompts/generate.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{# generate 프롬프트 템플릿 — Phase 3에서 구현 #}

ai/prompts/side_panel.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{# side_panel 프롬프트 템플릿 — Phase 3에서 구현 #}

ai/pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "poco-ai"
3+
version = "0.1.0"
4+
description = "Poco AI Orchestrator — Bedrock Claude 기반 독립 AI 모듈"
5+
requires-python = ">=3.13"
6+
dependencies = [
7+
"boto3>=1.35.0,<2.0.0",
8+
"pydantic>=2.10.0,<3.0.0",
9+
"pydantic-settings>=2.5.0,<3.0.0",
10+
]
11+
12+
[project.optional-dependencies]
13+
dev = [
14+
"pytest>=8.0.0,<9.0.0",
15+
"pytest-asyncio>=0.24.0,<1.0.0",
16+
"hypothesis>=6.100.0,<7.0.0",
17+
]
18+
19+
[build-system]
20+
requires = ["setuptools>=75.0.0"]
21+
build-backend = "setuptools.build_meta"

ai/schemas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ai/schemas — Pydantic 입출력 스키마

0 commit comments

Comments
 (0)