py-aidol 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aidol/api/aidol.py CHANGED
@@ -21,6 +21,7 @@ from aidol.protocols import (
21
21
  ImageStorageProtocol,
22
22
  )
23
23
  from aidol.schemas import AIdol, AIdolCreate, AIdolPublic, AIdolUpdate
24
+ from aidol.settings import GoogleGenAISettings
24
25
 
25
26
 
26
27
  class AIdolCreateResponse(BaseModel):
@@ -41,11 +42,11 @@ class AIdolRouter(
41
42
 
42
43
  def __init__(
43
44
  self,
44
- google_api_key: str | None,
45
+ google_settings: GoogleGenAISettings | None,
45
46
  image_storage: ImageStorageProtocol,
46
47
  **kwargs,
47
48
  ):
48
- self.google_api_key = google_api_key
49
+ self.google_settings = google_settings
49
50
  self.image_storage = image_storage
50
51
  super().__init__(**kwargs)
51
52
 
@@ -55,7 +56,7 @@ class AIdolRouter(
55
56
  register_image_generation_route(
56
57
  router=self.router,
57
58
  resource_name=self.resource_name,
58
- google_api_key=self.google_api_key,
59
+ google_settings=self.google_settings,
59
60
  image_storage=self.image_storage,
60
61
  )
61
62
 
@@ -142,7 +143,7 @@ class AIdolRouter(
142
143
 
143
144
 
144
145
  def create_aidol_router(
145
- google_api_key: str | None,
146
+ google_settings: GoogleGenAISettings | None,
146
147
  db_session_factory: sessionmaker,
147
148
  repository_factory: AIdolRepositoryFactoryProtocol,
148
149
  image_storage: ImageStorageProtocol,
@@ -155,7 +156,7 @@ def create_aidol_router(
155
156
  Create AIdol router with dependency injection.
156
157
 
157
158
  Args:
158
- google_api_key: Google API Key for image generation
159
+ google_settings: Google API settings (uses ADC if api_key is None)
159
160
  db_session_factory: Database session factory
160
161
  repository_factory: Factory implementing AIdolRepositoryFactoryProtocol
161
162
  image_storage: Image storage for permanent URLs
@@ -168,7 +169,7 @@ def create_aidol_router(
168
169
  FastAPI APIRouter instance
169
170
  """
170
171
  router = AIdolRouter(
171
- google_api_key=google_api_key,
172
+ google_settings=google_settings,
172
173
  image_storage=image_storage,
173
174
  model_class=AIdol,
174
175
  create_schema=AIdolCreate,
aidol/api/common.py CHANGED
@@ -14,12 +14,13 @@ from aidol.schemas import (
14
14
  ImageGenerationResponse,
15
15
  )
16
16
  from aidol.services import ImageGenerationService
17
+ from aidol.settings import GoogleGenAISettings
17
18
 
18
19
 
19
20
  def register_image_generation_route(
20
21
  router: APIRouter,
21
22
  resource_name: str,
22
- google_api_key: str | None,
23
+ google_settings: GoogleGenAISettings | None,
23
24
  image_storage: ImageStorageProtocol,
24
25
  ) -> None:
25
26
  """
@@ -28,7 +29,7 @@ def register_image_generation_route(
28
29
  Args:
29
30
  router: FastAPI APIRouter instance
30
31
  resource_name: Resource name for the route path
31
- google_api_key: Google API Key
32
+ google_settings: Google API settings (API Key or Vertex AI with ADC)
32
33
  image_storage: Image Storage instance
33
34
  """
34
35
 
@@ -45,7 +46,7 @@ def register_image_generation_route(
45
46
  async def generate_image(request: ImageGenerationRequest):
46
47
  """Generate image from prompt."""
47
48
  # Generate and download image
48
- service = ImageGenerationService(api_key=google_api_key)
49
+ service = ImageGenerationService(settings=google_settings)
49
50
  image = service.generate_and_download_image(
50
51
  prompt=request.prompt,
51
52
  size="1024x1024",
aidol/api/companion.py CHANGED
@@ -28,6 +28,7 @@ from aidol.schemas import (
28
28
  Gender,
29
29
  )
30
30
  from aidol.services.companion_service import to_companion_public
31
+ from aidol.settings import GoogleGenAISettings
31
32
 
32
33
 
33
34
  class CompanionPaginatedResponse(BaseModel):
@@ -51,11 +52,11 @@ class CompanionRouter(
51
52
 
52
53
  def __init__(
53
54
  self,
54
- google_api_key: str | None,
55
+ google_settings: GoogleGenAISettings | None,
55
56
  image_storage: ImageStorageProtocol,
56
57
  **kwargs,
57
58
  ):
58
- self.google_api_key = google_api_key
59
+ self.google_settings = google_settings
59
60
  self.image_storage = image_storage
60
61
  super().__init__(**kwargs)
61
62
 
@@ -65,7 +66,7 @@ class CompanionRouter(
65
66
  register_image_generation_route(
66
67
  router=self.router,
67
68
  resource_name=self.resource_name,
68
- google_api_key=self.google_api_key,
69
+ google_settings=self.google_settings,
69
70
  image_storage=self.image_storage,
70
71
  )
71
72
 
@@ -244,7 +245,7 @@ class CompanionRouter(
244
245
 
245
246
 
246
247
  def create_companion_router(
247
- google_api_key: str | None,
248
+ google_settings: GoogleGenAISettings | None,
248
249
  db_session_factory: sessionmaker,
249
250
  repository_factory: CompanionRepositoryFactoryProtocol,
250
251
  image_storage: ImageStorageProtocol,
@@ -257,7 +258,7 @@ def create_companion_router(
257
258
  Create Companion router with dependency injection.
258
259
 
259
260
  Args:
260
- google_api_key: Google API Key for image generation
261
+ google_settings: Google API settings (uses ADC if api_key is None)
261
262
  db_session_factory: Database session factory
262
263
  repository_factory: Factory implementing CompanionRepositoryFactoryProtocol
263
264
  image_storage: Image storage for permanent URLs
@@ -270,7 +271,7 @@ def create_companion_router(
270
271
  FastAPI APIRouter instance
271
272
  """
272
273
  router = CompanionRouter(
273
- google_api_key=google_api_key,
274
+ google_settings=google_settings,
274
275
  image_storage=image_storage,
275
276
  model_class=Companion,
276
277
  create_schema=CompanionCreate,
@@ -1,7 +1,7 @@
1
1
  """
2
- Image generation service for AIdol
2
+ Image generation service for AIdol.
3
3
 
4
- Generates images using OpenAI DALL-E 3 for AIdol emblems and Companion profiles.
4
+ Generates images using Google Gemini for AIdol emblems and Companion profiles.
5
5
  """
6
6
 
7
7
  from __future__ import annotations
@@ -15,6 +15,8 @@ import PIL.Image
15
15
  from google import genai
16
16
  from google.genai import errors as genai_errors
17
17
 
18
+ from aidol.settings import GoogleGenAISettings
19
+
18
20
  logger = logging.getLogger(__name__)
19
21
 
20
22
 
@@ -31,23 +33,33 @@ class ImageGenerationService:
31
33
 
32
34
  client: "genai.Client | None" = None
33
35
 
34
- def __init__(self, api_key: str | None = None, settings=None):
36
+ def __init__(self, settings: GoogleGenAISettings | None = None):
35
37
  """
36
38
  Initialize the Image Generation service.
37
39
 
40
+ Supports two authentication methods:
41
+ 1. Google AI API: settings.api_key
42
+ 2. Vertex AI API (ADC): settings.cloud_project (location=global hardcoded)
43
+
38
44
  Args:
39
- api_key: Google API Key.
40
- settings: Unused, kept for compatibility.
45
+ settings: GoogleGenAISettings for configuration.
41
46
  """
42
-
43
- # Use explicitly provided api_key, otherwise fallback to settings or env
44
- if api_key:
45
- self.client = genai.Client(api_key=api_key)
46
- elif settings and hasattr(settings, "api_key") and settings.api_key:
47
+ # Priority 1: Settings with api_key (Google AI API)
48
+ if settings and settings.api_key:
47
49
  self.client = genai.Client(api_key=settings.api_key)
50
+ # Priority 2: Settings with cloud_project (Vertex AI, location=global)
51
+ elif settings and settings.cloud_project:
52
+ self.client = genai.Client(
53
+ vertexai=True,
54
+ project=settings.cloud_project,
55
+ location="global",
56
+ )
48
57
  else:
49
- # Try loading from GOOGLE_API_KEY environment variable (Client handles this)
50
- self.client = genai.Client()
58
+ logger.error(
59
+ "No authentication configured. "
60
+ "Set GOOGLE_API_KEY or GOOGLE_CLOUD_PROJECT"
61
+ )
62
+ self.client = None
51
63
 
52
64
  def generate_and_download_image(
53
65
  self,
aidol/settings.py ADDED
@@ -0,0 +1,37 @@
1
+ """
2
+ Environment settings for aidol module.
3
+
4
+ Provides GoogleGenAISettings for image generation with Google Gemini.
5
+ """
6
+
7
+ from pydantic_settings import BaseSettings
8
+
9
+
10
+ class GoogleGenAISettings(BaseSettings):
11
+ """
12
+ Google Gen AI SDK settings for Gemini image generation.
13
+
14
+ Supports two authentication methods:
15
+ 1. Google AI API: GOOGLE_API_KEY
16
+ 2. Vertex AI API (ADC): GOOGLE_CLOUD_PROJECT
17
+
18
+ For Google AI API:
19
+ export GOOGLE_API_KEY=your-api-key
20
+
21
+ For Vertex AI with ADC:
22
+ export GOOGLE_CLOUD_PROJECT=your-project-id
23
+ gcloud auth application-default login
24
+
25
+ Note: Vertex AI uses location="global" (hardcoded) because
26
+ Gemini image generation models only support the global endpoint.
27
+
28
+ Environment variables:
29
+ GOOGLE_API_KEY: Google API key (optional)
30
+ GOOGLE_CLOUD_PROJECT: GCP project ID for Vertex AI (optional)
31
+ """
32
+
33
+ api_key: str | None = None
34
+ cloud_project: str | None = None
35
+
36
+ class Config:
37
+ env_prefix = "GOOGLE_"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py-aidol
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Create and chat with your own AI idol group
5
5
  License: Apache-2.0
6
6
  Keywords: kpop,idol,aidol,ai-companion,chatbot,image-generation
@@ -34,7 +34,7 @@ AI 아이돌 그룹 생성 및 채팅 Python 패키지
34
34
  ## 주요 기능
35
35
 
36
36
  - AI 아이돌 그룹/멤버 CRUD
37
- - DALL-E 3 이미지 생성 (엠블럼, 프로필)
37
+ - Google Gemini 이미지 생성 (엠블럼, 프로필)
38
38
  - 텍스트 채팅 (페르소나 기반 응답)
39
39
  - Buppy 통합 Adapter 패턴
40
40
 
@@ -62,7 +62,7 @@ from aidol.factories import AIdolRepositoryFactory, CompanionRepositoryFactory
62
62
  # AIdol 라우터
63
63
  aidol_router = AIdolRouter(
64
64
  repository_factory=AIdolRepositoryFactory(),
65
- openai_settings=openai_settings,
65
+ google_settings=google_settings,
66
66
  image_storage=image_storage,
67
67
  )
68
68
 
@@ -87,11 +87,27 @@ make format
87
87
 
88
88
  ## 환경 변수
89
89
 
90
- ### 필수 (이미지 생성 )
90
+ ### 이미지 생성 인증 (선택, ADC 지원)
91
91
 
92
92
  | 변수 | 설명 |
93
93
  |------|------|
94
- | `OPENAI_API_KEY` | OpenAI API 키 |
94
+ | `GOOGLE_API_KEY` | Google API 키 (Google AI API) |
95
+ | `GOOGLE_CLOUD_PROJECT` | GCP 프로젝트 ID (Vertex AI) |
96
+
97
+ **인증 방법:**
98
+
99
+ **Option 1: Google AI API (API Key)**
100
+ ```bash
101
+ export GOOGLE_API_KEY=your-api-key
102
+ ```
103
+
104
+ **Option 2: Vertex AI (ADC)**
105
+ ```bash
106
+ export GOOGLE_CLOUD_PROJECT=your-project-id
107
+ gcloud auth application-default login # 로컬 개발
108
+ ```
109
+
110
+ > **참고**: Vertex AI 사용 시 `location=global`이 하드코딩되어 있습니다 (Gemini 이미지 생성 모델 요구사항).
95
111
 
96
112
  ### 선택
97
113
 
@@ -106,7 +122,8 @@ make format
106
122
 
107
123
  - aioia-core (공통 인프라)
108
124
  - FastAPI, SQLAlchemy, Pydantic
109
- - OpenAI (이미지 생성, 채팅)
125
+ - Google Generative AI (이미지 생성)
126
+ - OpenAI (채팅)
110
127
  - Pillow (이미지 처리)
111
128
 
112
129
  ## 라이선스
@@ -1,8 +1,8 @@
1
1
  aidol/__init__.py,sha256=iMN-aij1k6vElJt0sZQT4QYJjvoD27Q9vtZkQA0TY9c,141
2
2
  aidol/api/__init__.py,sha256=skD_w82nT0v1hdKK9BBOycNERexIr8F1BmSmSono4Jk,276
3
- aidol/api/aidol.py,sha256=8fRkYq6-pEVKpQWbamv45IT2-b9FIgilSoPWg3itiK0,6486
4
- aidol/api/common.py,sha256=R_2RjV_XjAI5TuTSXNbYEjE-wY3wC_hP2Bww0z2g5ZA,2094
5
- aidol/api/companion.py,sha256=XVZum54ueskJgcaAA2Z_Z6xa3Zpy0CGrl3MIQIga-kY,10738
3
+ aidol/api/aidol.py,sha256=AIpDMTTOxht1eEVk4YITvmJzvklpYlDTpQVrIuSjeUw,6588
4
+ aidol/api/common.py,sha256=w8ERo96t9tat4HPs1qw9JhyoJ8cj5crHCe92Hp3Usug,2198
5
+ aidol/api/companion.py,sha256=Nlx4QHqoi0y_CMczEh75n8C4xJTWp8eV1BqHjEzkOFw,10840
6
6
  aidol/api/lead.py,sha256=RSf3GcIUVJu752rU9HG7Wy22UmnrRZnN_NGWkpTRDfE,3921
7
7
  aidol/factories.py,sha256=5VhEbUVQEo-WruOdDauOi9xGgMxrgT339glocC1ua4o,983
8
8
  aidol/models/__init__.py,sha256=AljQMgSE9vHx203NFQZMknKpzHIfyFLLcOMnFpMOLAs,218
@@ -21,7 +21,8 @@ aidol/schemas/aidol_lead.py,sha256=JS8U-ep0Ga6x0PdwXhJfTrcOCKgG0wfFW8pN5X35GUM,1
21
21
  aidol/schemas/companion.py,sha256=I4hi4LT-S9AC7lqt1jyYfd0vSqYmxYNm2k9EsZdyNyM,7584
22
22
  aidol/services/__init__.py,sha256=3vdT_CtUfeDWbsPn7Xnp41sajovcl2nCvpZ8KNFPHYM,144
23
23
  aidol/services/companion_service.py,sha256=tNNWiIFmJQ-I3UBW06baOANXhBx5oTKoT6nkqfnDisA,2490
24
- aidol/services/image_generation_service.py,sha256=fq4ua1sO4xT4BK0b-Db2u_G0lbXElbO63MFZfstOlWY,3456
25
- py_aidol-0.3.0.dist-info/METADATA,sha256=xuQO_y10IvUUZe4Z-VcQkOnQ9ICHjVtSY5iVE5A0oTE,2926
26
- py_aidol-0.3.0.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
27
- py_aidol-0.3.0.dist-info/RECORD,,
24
+ aidol/services/image_generation_service.py,sha256=zDs9HP_JckHFJJZUIo2ADSsHGppat-8V-ttu8DlN-BU,3862
25
+ aidol/settings.py,sha256=7oI3Vn1iGXvLRRahJ1ygD6qIu-BvZmlVvvMQxnsq1kc,1003
26
+ py_aidol-0.4.0.dist-info/METADATA,sha256=FI4-Xdaxi36hwykQQGgmttCOlsFOlSh_NzCluamZIvA,3431
27
+ py_aidol-0.4.0.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
28
+ py_aidol-0.4.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.3.0
2
+ Generator: poetry-core 2.3.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any