@umituz/react-native-ai-gemini-provider 1.14.28 → 1.14.29
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.
- package/package.json +1 -1
- package/src/domain/README.md +232 -0
- package/src/domain/constants/README.md +191 -0
- package/src/domain/entities/README.md +238 -0
- package/src/infrastructure/README.md +252 -0
- package/src/infrastructure/cache/CACHE_SYSTEM.md +213 -0
- package/src/infrastructure/cache/README.md +213 -0
- package/src/infrastructure/content/CONTENT_BUILDER.md +175 -0
- package/src/infrastructure/content/README.md +175 -0
- package/src/infrastructure/interceptors/README.md +226 -0
- package/src/infrastructure/interceptors/REQUEST_INTERCEPTORS.md +171 -0
- package/src/infrastructure/job/JOB_MANAGER.md +174 -0
- package/src/infrastructure/job/README.md +194 -0
- package/src/infrastructure/response/README.md +187 -0
- package/src/infrastructure/response/RESPONSE_FORMATTER.md +185 -0
- package/src/infrastructure/services/CORE_CLIENT_SERVICE.md +202 -0
- package/src/infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md +206 -0
- package/src/infrastructure/services/GENERATION_EXECUTOR_SERVICE.md +176 -0
- package/src/infrastructure/services/IMAGE_EDIT_SERVICE.md +169 -0
- package/src/infrastructure/services/IMAGE_GENERATION_SERVICE.md +166 -0
- package/src/infrastructure/services/JOB_PROCESSOR_SERVICE.md +174 -0
- package/src/infrastructure/services/PROVIDER_INITIALIZER_SERVICE.md +176 -0
- package/src/infrastructure/services/README.md +233 -0
- package/src/infrastructure/services/RETRY_SERVICE.md +178 -0
- package/src/infrastructure/services/STREAMING_SERVICE.md +166 -0
- package/src/infrastructure/services/STRUCTURED_TEXT_SERVICE.md +175 -0
- package/src/infrastructure/services/TEXT_GENERATION_SERVICE.md +160 -0
- package/src/infrastructure/services/VEO_HTTP_CLIENT_SERVICE.md +179 -0
- package/src/infrastructure/services/VEO_POLLING_SERVICE.md +173 -0
- package/src/infrastructure/services/VIDEO_DOWNLOADER_SERVICE.md +166 -0
- package/src/infrastructure/services/VIDEO_ERROR_HANDLER_SERVICE.md +185 -0
- package/src/infrastructure/services/VIDEO_GENERATION_SERVICE.md +176 -0
- package/src/infrastructure/services/VIDEO_URL_EXTRACTOR_SERVICE.md +186 -0
- package/src/infrastructure/telemetry/README.md +203 -0
- package/src/infrastructure/telemetry/TELEMETRY_SYSTEM.md +200 -0
- package/src/infrastructure/utils/DATA_TRANSFORMER_UTILS.md +175 -0
- package/src/infrastructure/utils/ERROR_MAPPER.md +170 -0
- package/src/infrastructure/utils/ERROR_UTILITIES.md +208 -0
- package/src/infrastructure/utils/IMAGE_PREPARER_UTILS.md +185 -0
- package/src/infrastructure/utils/INPUT_BUILDERS.md +214 -0
- package/src/infrastructure/utils/MODEL_VALIDATION_UTILS.md +189 -0
- package/src/infrastructure/utils/PERFORMANCE_UTILITIES.md +477 -0
- package/src/infrastructure/utils/PERFORMANCE_UTILS.md +219 -0
- package/src/infrastructure/utils/README.md +289 -0
- package/src/presentation/README.md +187 -0
- package/src/presentation/hooks/README.md +188 -0
- package/src/presentation/hooks/USE_GEMINI_HOOK.md +226 -0
- package/src/providers/README.md +247 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Feature Model Selector Service
|
|
2
|
+
|
|
3
|
+
Selects appropriate Gemini models based on feature type. Supports runtime model overrides for flexibility.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { featureModelSelector } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to select the correct AI model for specific features. Provides default model mappings and supports runtime overrides.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Select models for image/video features
|
|
17
|
+
- Override models for testing or optimization
|
|
18
|
+
- A/B test different models
|
|
19
|
+
- Implement feature-based model selection
|
|
20
|
+
- Configure models based on user preferences
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Different AI features require specialized models. This service:
|
|
25
|
+
- Maps features to appropriate default models
|
|
26
|
+
- Supports runtime model overrides
|
|
27
|
+
- Provides type-safe model selection
|
|
28
|
+
- Maintains feature-to-model relationships
|
|
29
|
+
- Enables flexible model configuration
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use feature-based model selection instead of hardcoding model IDs. This allows easy model updates and testing without code changes.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** use valid feature types (ImageFeatureType | VideoFeatureType)
|
|
37
|
+
- **SHOULD** check for existing overrides before setting new ones
|
|
38
|
+
- **MUST** clear overrides after temporary usage
|
|
39
|
+
- **SHOULD** use type-safe feature names
|
|
40
|
+
- **MUST NOT** use string literals for feature names
|
|
41
|
+
|
|
42
|
+
### Override Rules
|
|
43
|
+
- **SHOULD** use overrides sparingly
|
|
44
|
+
- **MUST** clean up overrides when done
|
|
45
|
+
- **SHOULD** check if override already exists
|
|
46
|
+
- **MUST NOT** set permanent overrides app-wide
|
|
47
|
+
- **SHOULD** restore original state after temporary overrides
|
|
48
|
+
|
|
49
|
+
### Configuration Rules
|
|
50
|
+
- **MUST** use valid model IDs
|
|
51
|
+
- **SHOULD** validate model IDs before use
|
|
52
|
+
- **MUST** handle model errors appropriately
|
|
53
|
+
- **SHOULD** log override operations in development
|
|
54
|
+
- **MUST NOT** override with invalid model IDs
|
|
55
|
+
|
|
56
|
+
## 🤖 AI Agent Guidelines
|
|
57
|
+
|
|
58
|
+
### When Modifying This Service
|
|
59
|
+
1. **READ** the implementation file first
|
|
60
|
+
2. **UNDERSTAND** feature-to-model mapping
|
|
61
|
+
3. **MAINTAIN** backward compatibility
|
|
62
|
+
4. **ADD** tests for new functionality
|
|
63
|
+
5. **UPDATE** type definitions
|
|
64
|
+
|
|
65
|
+
### When Adding New Features
|
|
66
|
+
1. **CHECK** if feature type already exists
|
|
67
|
+
2. **FOLLOW** existing patterns
|
|
68
|
+
3. **UPDATE** feature constants
|
|
69
|
+
4. **DOCUMENT** in type definitions
|
|
70
|
+
5. **ADD** examples to tests (not docs)
|
|
71
|
+
|
|
72
|
+
### When Fixing Bugs
|
|
73
|
+
1. **REPRODUCE** bug locally first
|
|
74
|
+
2. **IDENTIFY** root cause
|
|
75
|
+
3. **FIX** with minimal changes
|
|
76
|
+
4. **ADD** regression test
|
|
77
|
+
5. **VERIFY** all tests pass
|
|
78
|
+
|
|
79
|
+
### Code Style Rules
|
|
80
|
+
- **USE** type-safe feature names
|
|
81
|
+
- **VALIDATE** model IDs
|
|
82
|
+
- **LOG** override operations in development
|
|
83
|
+
- **THROW** typed errors for invalid inputs
|
|
84
|
+
- **COMMENT** complex logic only
|
|
85
|
+
|
|
86
|
+
## 📦 Available Methods
|
|
87
|
+
|
|
88
|
+
### `setModelOverride(feature, model)`
|
|
89
|
+
|
|
90
|
+
Set a custom model override for a specific feature.
|
|
91
|
+
|
|
92
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
93
|
+
|
|
94
|
+
### `clearOverrides()`
|
|
95
|
+
|
|
96
|
+
Clear all model overrides and revert to default models.
|
|
97
|
+
|
|
98
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
99
|
+
|
|
100
|
+
### `getImageFeatureModel(feature)`
|
|
101
|
+
|
|
102
|
+
Get the model ID for an image feature.
|
|
103
|
+
|
|
104
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
105
|
+
|
|
106
|
+
### `getVideoFeatureModel(feature)`
|
|
107
|
+
|
|
108
|
+
Get the model ID for a video feature.
|
|
109
|
+
|
|
110
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
111
|
+
|
|
112
|
+
### `hasOverride(feature)`
|
|
113
|
+
|
|
114
|
+
Check if a feature has a custom override set.
|
|
115
|
+
|
|
116
|
+
**Refer to**: [`feature-model-selector.ts`](./feature-model-selector.ts)
|
|
117
|
+
|
|
118
|
+
## 🔗 Related Modules
|
|
119
|
+
|
|
120
|
+
- **Feature Constants**: [`domain/constants/feature-models.constants.ts`](../domain/constants/feature-models.constants.ts)
|
|
121
|
+
- **Image Generation**: [`IMAGE_GENERATION_SERVICE.md`](./IMAGE_GENERATION_SERVICE.md)
|
|
122
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
123
|
+
|
|
124
|
+
## 📋 Configuration Reference
|
|
125
|
+
|
|
126
|
+
### Supported Image Features
|
|
127
|
+
|
|
128
|
+
- `image-generation` - Text-to-image generation
|
|
129
|
+
- `image-edit` - Image editing and transformation
|
|
130
|
+
- `upscale` - Image upscaling
|
|
131
|
+
- `face-swap` - Face replacement
|
|
132
|
+
- `remove-background` - Background removal
|
|
133
|
+
- `inpainting` - Image inpainting
|
|
134
|
+
- `outpainting` - Image outpainting
|
|
135
|
+
|
|
136
|
+
### Supported Video Features
|
|
137
|
+
|
|
138
|
+
- `video-generation` - Text-to-video generation
|
|
139
|
+
- `video-preview` - Video preview generation
|
|
140
|
+
|
|
141
|
+
### Default Models
|
|
142
|
+
|
|
143
|
+
**Image Features:**
|
|
144
|
+
- `image-generation`: `imagen-3.0-generate-001`
|
|
145
|
+
- `image-edit`: `imagen-3.0-generate-001`
|
|
146
|
+
- `upscale`: `imagen-3.0-capabilities-001`
|
|
147
|
+
- Other features: `imagen-3.0-capabilities-001`
|
|
148
|
+
|
|
149
|
+
**Video Features:**
|
|
150
|
+
- `video-generation`: `veo-3.1-generate-001`
|
|
151
|
+
- `video-preview`: `veo-3.1-fast-generate-preview`
|
|
152
|
+
|
|
153
|
+
## 🎓 Usage Patterns
|
|
154
|
+
|
|
155
|
+
### Basic Model Selection
|
|
156
|
+
1. Import service
|
|
157
|
+
2. Call `getImageFeatureModel()` or `getVideoFeatureModel()` with feature type
|
|
158
|
+
3. Use returned model ID with generation service
|
|
159
|
+
4. Generate content with selected model
|
|
160
|
+
|
|
161
|
+
### Runtime Model Override
|
|
162
|
+
1. Call `setModelOverride()` with feature and custom model
|
|
163
|
+
2. Use feature services normally
|
|
164
|
+
3. All requests now use custom model
|
|
165
|
+
4. Clear override when done
|
|
166
|
+
|
|
167
|
+
### Temporary Override with Cleanup
|
|
168
|
+
1. Save current overrides state
|
|
169
|
+
2. Set temporary override
|
|
170
|
+
3. Execute operation with custom model
|
|
171
|
+
4. Restore original state in finally block
|
|
172
|
+
|
|
173
|
+
### Feature-Based Model Selection
|
|
174
|
+
1. Determine feature type from request
|
|
175
|
+
2. Call appropriate getter method (image vs video)
|
|
176
|
+
3. Receive model ID for feature
|
|
177
|
+
4. Execute generation with selected model
|
|
178
|
+
|
|
179
|
+
### A/B Testing Different Models
|
|
180
|
+
1. Define array of models to test
|
|
181
|
+
2. Loop through models
|
|
182
|
+
3. Set override for each model
|
|
183
|
+
4. Generate content and track results
|
|
184
|
+
5. Clear overrides after testing
|
|
185
|
+
|
|
186
|
+
## 🚨 Common Pitfalls
|
|
187
|
+
|
|
188
|
+
### Don't
|
|
189
|
+
- Set permanent overrides app-wide
|
|
190
|
+
- Forget to clear overrides after use
|
|
191
|
+
- Use string literals for feature names
|
|
192
|
+
- Override without checking existing state
|
|
193
|
+
- Use invalid model IDs
|
|
194
|
+
|
|
195
|
+
### Do
|
|
196
|
+
- Clean up overrides in finally blocks
|
|
197
|
+
- Check for existing overrides before setting
|
|
198
|
+
- Use type-safe feature names
|
|
199
|
+
- Validate model IDs before use
|
|
200
|
+
- Test with different models for optimization
|
|
201
|
+
- Log override operations in development
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
**Last Updated**: 2025-01-08
|
|
206
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Generation Executor Service
|
|
2
|
+
|
|
3
|
+
Service for executing different types of AI generation tasks. Handles text, image, and video generation with a unified interface.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { generationExecutor } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use generation executor to execute AI generation tasks with a unified interface. Automatically detects generation type and routes to appropriate service.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Execute text, image, or video generation
|
|
17
|
+
- Use unified generation interface
|
|
18
|
+
- Handle multiple generation types
|
|
19
|
+
- Simplify service integration
|
|
20
|
+
- Abstract generation complexity
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Unified interface simplifies integration. This service:
|
|
25
|
+
- Detects generation type automatically
|
|
26
|
+
- Routes to appropriate service
|
|
27
|
+
- Provides consistent interface
|
|
28
|
+
- Handles response formatting
|
|
29
|
+
- Simplifies error handling
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Use executor for generic generation needs. Use specific services for direct control.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** specify generation type in input
|
|
37
|
+
- **SHOULD** use executor for generic operations
|
|
38
|
+
- **MUST** handle typed responses correctly
|
|
39
|
+
- **SHOULD** validate input parameters
|
|
40
|
+
- **MUST NOT** mix generation types
|
|
41
|
+
|
|
42
|
+
### Type Detection Rules
|
|
43
|
+
- **MUST** specify input type explicitly
|
|
44
|
+
- **SHOULD** use appropriate input structure
|
|
45
|
+
- **MUST** match type to service
|
|
46
|
+
- **SHOULD** validate type compatibility
|
|
47
|
+
- **MUST NOT** rely on implicit detection
|
|
48
|
+
|
|
49
|
+
### Response Rules
|
|
50
|
+
- **MUST** handle response types correctly
|
|
51
|
+
- **SHOULD** validate response structure
|
|
52
|
+
- **MUST** check for errors
|
|
53
|
+
- **SHOULD** parse responses appropriately
|
|
54
|
+
- **MUST NOT** assume response format
|
|
55
|
+
|
|
56
|
+
### Error Handling Rules
|
|
57
|
+
- **MUST** catch generation errors
|
|
58
|
+
- **SHOULD** provide meaningful error messages
|
|
59
|
+
- **MUST** handle service-specific errors
|
|
60
|
+
- **SHOULD** log errors appropriately
|
|
61
|
+
- **MUST NOT** suppress errors
|
|
62
|
+
|
|
63
|
+
## 🤖 AI Agent Guidelines
|
|
64
|
+
|
|
65
|
+
### When Executing Generations
|
|
66
|
+
1. **DETERMINE** generation type
|
|
67
|
+
2. **PREPARE** input structure
|
|
68
|
+
3. **CALL** executeGeneration()
|
|
69
|
+
4. **HANDLE** typed response
|
|
70
|
+
5. **PROCESS** result appropriately
|
|
71
|
+
|
|
72
|
+
### When Using Typed Generations
|
|
73
|
+
1. **SPECIFY** type parameter
|
|
74
|
+
2. **PROVIDE** correct input
|
|
75
|
+
3. **CAST** response appropriately
|
|
76
|
+
4. **VALIDATE** response type
|
|
77
|
+
5. **USE** result safely
|
|
78
|
+
|
|
79
|
+
### When Handling Errors
|
|
80
|
+
1. **WRAP** execution in try-catch
|
|
81
|
+
2. **CHECK** error type
|
|
82
|
+
3. **HANDLE** service-specific errors
|
|
83
|
+
4. **PROVIDE** fallback behavior
|
|
84
|
+
5. **LOG** error details
|
|
85
|
+
|
|
86
|
+
### Code Style Rules
|
|
87
|
+
- **SPECIFY** generation type explicitly
|
|
88
|
+
- **USE** type parameters correctly
|
|
89
|
+
- **HANDLE** all error cases
|
|
90
|
+
- **VALIDATE** input structure
|
|
91
|
+
- **DOCUMENT** generation usage
|
|
92
|
+
|
|
93
|
+
## 📦 Available Service
|
|
94
|
+
|
|
95
|
+
### generationExecutor
|
|
96
|
+
|
|
97
|
+
**Refer to**: [`generation-executor.ts`](./generation-executor.ts)
|
|
98
|
+
|
|
99
|
+
**Methods:**
|
|
100
|
+
- `executeGeneration<T>(model, input, options?)` - Execute generation task
|
|
101
|
+
- `generateWithImages(model, prompt, images)` - Generate with image context
|
|
102
|
+
|
|
103
|
+
## 🔗 Related Modules
|
|
104
|
+
|
|
105
|
+
- **Text Generation**: [`TEXT_GENERATION_SERVICE.md`](./TEXT_GENERATION_SERVICE.md)
|
|
106
|
+
- **Image Generation**: [`IMAGE_GENERATION_SERVICE.md`](./IMAGE_GENERATION_SERVICE.md)
|
|
107
|
+
- **Video Generation**: [`VIDEO_GENERATION_SERVICE.md`](./VIDEO_GENERATION_SERVICE.md)
|
|
108
|
+
- **Job Processor**: [`JOB_PROCESSOR_SERVICE.md`](./JOB_PROCESSOR_SERVICE.md)
|
|
109
|
+
|
|
110
|
+
## 📋 Generation Types
|
|
111
|
+
|
|
112
|
+
### Text Generation
|
|
113
|
+
- Type: `text`
|
|
114
|
+
- Input: `{ type: 'text', prompt: string }`
|
|
115
|
+
- Returns: `{ text: string; response: unknown }`
|
|
116
|
+
|
|
117
|
+
### Image Generation
|
|
118
|
+
- Type: `image`
|
|
119
|
+
- Input: `{ type: 'image', prompt: string }`
|
|
120
|
+
- Returns: `{ imageUrl: string; response: unknown }`
|
|
121
|
+
|
|
122
|
+
### Video Generation
|
|
123
|
+
- Type: `video`
|
|
124
|
+
- Input: `{ type: 'video', prompt: string }`
|
|
125
|
+
- Returns: `{ videoUrl: string; response: unknown }`
|
|
126
|
+
|
|
127
|
+
## 🎓 Usage Patterns
|
|
128
|
+
|
|
129
|
+
### Basic Generation
|
|
130
|
+
1. Determine generation type
|
|
131
|
+
2. Prepare input structure
|
|
132
|
+
3. Call executeGeneration()
|
|
133
|
+
4. Get typed response
|
|
134
|
+
5. Use result
|
|
135
|
+
|
|
136
|
+
### Typed Generation
|
|
137
|
+
1. Specify type parameter
|
|
138
|
+
2. Provide correct input
|
|
139
|
+
3. Execute generation
|
|
140
|
+
4. Validate response type
|
|
141
|
+
5. Use result safely
|
|
142
|
+
|
|
143
|
+
### Image Context Generation
|
|
144
|
+
1. Call generateWithImages()
|
|
145
|
+
2. Provide prompt and images
|
|
146
|
+
3. Get text response
|
|
147
|
+
4. Handle multimodal result
|
|
148
|
+
5. Process response
|
|
149
|
+
|
|
150
|
+
### Error Handling
|
|
151
|
+
1. Wrap execution in try-catch
|
|
152
|
+
2. Check error type
|
|
153
|
+
3. Handle specific errors
|
|
154
|
+
4. Provide fallback
|
|
155
|
+
5. Log errors
|
|
156
|
+
|
|
157
|
+
## 🚨 Common Pitfalls
|
|
158
|
+
|
|
159
|
+
### Don't
|
|
160
|
+
- Skip type specification
|
|
161
|
+
- Mix generation types
|
|
162
|
+
- Assume response format
|
|
163
|
+
- Suppress errors
|
|
164
|
+
- Use wrong input structure
|
|
165
|
+
|
|
166
|
+
### Do
|
|
167
|
+
- Always specify type
|
|
168
|
+
- Use correct input structure
|
|
169
|
+
- Handle all error cases
|
|
170
|
+
- Validate responses
|
|
171
|
+
- Use type parameters correctly
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
**Last Updated**: 2025-01-08
|
|
176
|
+
**See Also**: [AI_GUIDELINES.md](../../../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Image Edit Service
|
|
2
|
+
|
|
3
|
+
Edits and transforms images using Gemini API. Supports background removal, object removal, face swap, and image enhancements.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { geminiImageEditService } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to edit and transform existing images with AI. Supports background removal, object deletion, style transfer, image enhancement, and various image manipulation operations.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Remove or replace image backgrounds
|
|
17
|
+
- Remove unwanted objects from images
|
|
18
|
+
- Enhance image quality (upscale, denoise, restore)
|
|
19
|
+
- Apply style transformations (anime, artistic styles)
|
|
20
|
+
- Face swapping and image compositing
|
|
21
|
+
|
|
22
|
+
## 📌 Strategy
|
|
23
|
+
|
|
24
|
+
Image editing requires both visual and textual understanding. This service:
|
|
25
|
+
- Uses multimodal models (gemini-2.5-flash-image)
|
|
26
|
+
- Accepts base64-encoded images as input
|
|
27
|
+
- Returns edited images with text descriptions
|
|
28
|
+
- Supports both single and multiple image inputs
|
|
29
|
+
- Handles image-specific response formats
|
|
30
|
+
|
|
31
|
+
**Key Decision**: Image editing uses TEXT + IMAGE response modalities. The service returns both edited image data and explanatory text when applicable.
|
|
32
|
+
|
|
33
|
+
## ⚠️ Rules
|
|
34
|
+
|
|
35
|
+
### Usage Rules
|
|
36
|
+
- **MUST** initialize provider with API key before use
|
|
37
|
+
- **MUST** provide base64-encoded images
|
|
38
|
+
- **SHOULD** use specific, clear prompts
|
|
39
|
+
- **MUST NOT** exceed image size limits
|
|
40
|
+
- **MUST** handle image editing errors appropriately
|
|
41
|
+
|
|
42
|
+
### Prompt Rules
|
|
43
|
+
- **SHOULD** clearly describe desired edit
|
|
44
|
+
- **MUST** specify what to keep vs remove
|
|
45
|
+
- **SHOULD** include fill instructions for removals
|
|
46
|
+
- **MUST NOT** request prohibited content
|
|
47
|
+
|
|
48
|
+
### Configuration Rules
|
|
49
|
+
- **MUST** use valid model IDs (gemini-2.5-flash-image)
|
|
50
|
+
- **SHOULD** optimize image size before sending
|
|
51
|
+
- **MUST** respect content safety guidelines
|
|
52
|
+
- **SHOULD** implement retry logic for failures
|
|
53
|
+
|
|
54
|
+
### Error Handling Rules
|
|
55
|
+
- **MUST** catch and handle `GeminiError`
|
|
56
|
+
- **MUST** provide user-friendly error messages
|
|
57
|
+
- **SHOULD** log errors for debugging
|
|
58
|
+
- **MUST NOT** expose API keys in errors
|
|
59
|
+
|
|
60
|
+
## 🤖 AI Agent Guidelines
|
|
61
|
+
|
|
62
|
+
### When Modifying This Service
|
|
63
|
+
1. **READ** the implementation file first
|
|
64
|
+
2. **UNDERSTAND** multimodal response format
|
|
65
|
+
3. **MAINTAIN** backward compatibility
|
|
66
|
+
4. **ADD** tests for new functionality
|
|
67
|
+
5. **UPDATE** type definitions
|
|
68
|
+
|
|
69
|
+
### When Adding New Features
|
|
70
|
+
1. **CHECK** if similar feature exists in image services
|
|
71
|
+
2. **FOLLOW** existing patterns
|
|
72
|
+
3. **USE** established error handling
|
|
73
|
+
4. **DOCUMENT** in type definitions
|
|
74
|
+
5. **ADD** examples to tests (not docs)
|
|
75
|
+
|
|
76
|
+
### When Fixing Bugs
|
|
77
|
+
1. **REPRODUCE** bug locally first
|
|
78
|
+
2. **IDENTIFY** root cause
|
|
79
|
+
3. **FIX** with minimal changes
|
|
80
|
+
4. **ADD** regression test
|
|
81
|
+
5. **VERIFY** all tests pass
|
|
82
|
+
|
|
83
|
+
### Code Style Rules
|
|
84
|
+
- **USE** async/await (no callbacks)
|
|
85
|
+
- **VALIDATE** inputs at function entry
|
|
86
|
+
- **THROW** typed errors (`GeminiError`)
|
|
87
|
+
- **LOG** important operations
|
|
88
|
+
- **COMMENT** complex logic only
|
|
89
|
+
|
|
90
|
+
## 📦 Available Methods
|
|
91
|
+
|
|
92
|
+
### `editImage(prompt, images)`
|
|
93
|
+
|
|
94
|
+
Edit images with text instructions.
|
|
95
|
+
|
|
96
|
+
**Refer to**: [`gemini-image-edit.service.ts`](./gemini-image-edit.service.ts)
|
|
97
|
+
|
|
98
|
+
## 🔗 Related Modules
|
|
99
|
+
|
|
100
|
+
- **Domain Types**: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
101
|
+
- **Image Generation**: [`IMAGE_GENERATION_SERVICE.md`](./IMAGE_GENERATION_SERVICE.md)
|
|
102
|
+
- **Core Client**: [`CORE_CLIENT_SERVICE.md`](./CORE_CLIENT_SERVICE.md)
|
|
103
|
+
- **Image Preparers**: [`IMAGE_PREPARER_UTILS.md`](../infrastructure/utils/IMAGE_PREPARER_UTILS.md)
|
|
104
|
+
|
|
105
|
+
## 📋 Configuration Reference
|
|
106
|
+
|
|
107
|
+
### Generation Config
|
|
108
|
+
See: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
109
|
+
|
|
110
|
+
### Model Selection
|
|
111
|
+
- Current model: `gemini-2.5-flash-image`
|
|
112
|
+
- Response modalities: TEXT + IMAGE
|
|
113
|
+
- Output format: PNG (typically)
|
|
114
|
+
|
|
115
|
+
### Error Types
|
|
116
|
+
See: [`ERROR_UTILITIES.md`](../infrastructure/utils/ERROR_UTILITIES.md)
|
|
117
|
+
|
|
118
|
+
## 🎓 Usage Patterns
|
|
119
|
+
|
|
120
|
+
### Background Removal
|
|
121
|
+
1. Import service
|
|
122
|
+
2. Prepare base64-encoded image
|
|
123
|
+
3. Call `editImage()` with removal prompt
|
|
124
|
+
4. Handle response (contains `imageUrl`, `imageBase64`)
|
|
125
|
+
5. Display or save edited image
|
|
126
|
+
|
|
127
|
+
### Object Removal
|
|
128
|
+
1. Import service
|
|
129
|
+
2. Prepare base64-encoded image
|
|
130
|
+
3. Create prompt describing object to remove and fill instructions
|
|
131
|
+
4. Call `editImage()` with prompt and image
|
|
132
|
+
5. Handle result showing edited image
|
|
133
|
+
|
|
134
|
+
### Background Replacement
|
|
135
|
+
1. Import service
|
|
136
|
+
2. Prepare base64-encoded image
|
|
137
|
+
3. Create prompt describing new background
|
|
138
|
+
4. Specify to keep main subject
|
|
139
|
+
5. Call `editImage()` with detailed prompt
|
|
140
|
+
6. Handle response
|
|
141
|
+
|
|
142
|
+
### Image Enhancement
|
|
143
|
+
1. Import service
|
|
144
|
+
2. Prepare base64-encoded image
|
|
145
|
+
3. Create enhancement prompt (brightness, contrast, etc.)
|
|
146
|
+
4. Call `editImage()` with prompt and image
|
|
147
|
+
5. Handle enhanced result
|
|
148
|
+
|
|
149
|
+
## 🚨 Common Pitfalls
|
|
150
|
+
|
|
151
|
+
### Don't
|
|
152
|
+
- Use vague prompts ("remove this")
|
|
153
|
+
- Forget to specify fill instructions
|
|
154
|
+
- Send extremely large images
|
|
155
|
+
- Expect perfect results on complex edits
|
|
156
|
+
- Ignore safety filters
|
|
157
|
+
|
|
158
|
+
### Do
|
|
159
|
+
- Be specific about what to edit
|
|
160
|
+
- Describe how to fill removed areas
|
|
161
|
+
- Optimize image size before sending
|
|
162
|
+
- Handle multimodal responses (text + image)
|
|
163
|
+
- Implement retry logic
|
|
164
|
+
- Test with various image types
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
**Last Updated**: 2025-01-08
|
|
169
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Image Generation Service
|
|
2
|
+
|
|
3
|
+
Generates images from text prompts using Google Imagen API.
|
|
4
|
+
|
|
5
|
+
## 📍 Import Path
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { geminiImageGenerationService } from '@umituz/react-native-ai-gemini-provider';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🎯 Purpose
|
|
12
|
+
|
|
13
|
+
Use this service to generate AI-powered images from text descriptions. Supports creating photorealistic images, artistic renderings, and various visual styles using Imagen 4.0 model.
|
|
14
|
+
|
|
15
|
+
**When to use:**
|
|
16
|
+
- Generate images from text descriptions
|
|
17
|
+
- Create visual content for applications
|
|
18
|
+
- Generate artistic or photorealistic imagery
|
|
19
|
+
- Product visualization and concept art
|
|
20
|
+
|
|
21
|
+
## 📌 Strategy
|
|
22
|
+
|
|
23
|
+
Image generation requires specialized handling compared to text generation. This service:
|
|
24
|
+
- Uses Imagen 4.0 model specifically for images
|
|
25
|
+
- Returns base64-encoded image data
|
|
26
|
+
- Handles image-specific response formats
|
|
27
|
+
- Integrates with retry logic for reliability
|
|
28
|
+
- Validates prompt content for safety
|
|
29
|
+
|
|
30
|
+
**Key Decision**: Images are returned as base64 data URLs for React Native compatibility. Use `imageBase64` for raw data or `imageUrl` for React Native Image component.
|
|
31
|
+
|
|
32
|
+
## ⚠️ Rules
|
|
33
|
+
|
|
34
|
+
### Usage Rules
|
|
35
|
+
- **MUST** initialize provider with API key before use
|
|
36
|
+
- **MUST** handle image data appropriately (display or save)
|
|
37
|
+
- **MUST NOT** exceed API rate limits
|
|
38
|
+
- **SHOULD** provide detailed prompts for better results
|
|
39
|
+
- **MUST** handle image generation errors appropriately
|
|
40
|
+
|
|
41
|
+
### Prompt Rules
|
|
42
|
+
- **SHOULD** be descriptive and specific
|
|
43
|
+
- **SHOULD** include style and lighting information
|
|
44
|
+
- **MUST NOT** include prohibited content
|
|
45
|
+
- **SHOULD** follow prompt templates for consistency
|
|
46
|
+
|
|
47
|
+
### Configuration Rules
|
|
48
|
+
- **MUST** use valid model IDs
|
|
49
|
+
- **SHOULD** configure aspect ratio appropriately (currently 1:1 only)
|
|
50
|
+
- **MUST** respect content safety guidelines
|
|
51
|
+
- **SHOULD** implement retry logic for failures
|
|
52
|
+
|
|
53
|
+
### Error Handling Rules
|
|
54
|
+
- **MUST** catch and handle `GeminiError`
|
|
55
|
+
- **MUST** provide user-friendly error messages
|
|
56
|
+
- **SHOULD** log errors for debugging
|
|
57
|
+
- **MUST NOT** expose API keys in errors
|
|
58
|
+
|
|
59
|
+
## 🤖 AI Agent Guidelines
|
|
60
|
+
|
|
61
|
+
### When Modifying This Service
|
|
62
|
+
1. **READ** the implementation file first
|
|
63
|
+
2. **UNDERSTAND** image response format
|
|
64
|
+
3. **MAINTAIN** backward compatibility
|
|
65
|
+
4. **ADD** tests for new functionality
|
|
66
|
+
5. **UPDATE** type definitions
|
|
67
|
+
|
|
68
|
+
### When Adding New Features
|
|
69
|
+
1. **CHECK** if similar feature exists in image services
|
|
70
|
+
2. **FOLLOW** existing patterns
|
|
71
|
+
3. **USE** established error handling
|
|
72
|
+
4. **DOCUMENT** in type definitions
|
|
73
|
+
5. **ADD** examples to tests (not docs)
|
|
74
|
+
|
|
75
|
+
### When Fixing Bugs
|
|
76
|
+
1. **REPRODUCE** bug locally first
|
|
77
|
+
2. **IDENTIFY** root cause
|
|
78
|
+
3. **FIX** with minimal changes
|
|
79
|
+
4. **ADD** regression test
|
|
80
|
+
5. **VERIFY** all tests pass
|
|
81
|
+
|
|
82
|
+
### Code Style Rules
|
|
83
|
+
- **USE** async/await (no callbacks)
|
|
84
|
+
- **VALIDATE** inputs at function entry
|
|
85
|
+
- **THROW** typed errors (`GeminiError`)
|
|
86
|
+
- **LOG** important operations
|
|
87
|
+
- **COMMENT** complex logic only
|
|
88
|
+
|
|
89
|
+
## 📦 Available Methods
|
|
90
|
+
|
|
91
|
+
### `generateImage(prompt, images?, config?)`
|
|
92
|
+
|
|
93
|
+
Generate an image from text prompt.
|
|
94
|
+
|
|
95
|
+
**Refer to**: [`gemini-image-generation.service.ts`](./gemini-image-generation.service.ts)
|
|
96
|
+
|
|
97
|
+
## 🔗 Related Modules
|
|
98
|
+
|
|
99
|
+
- **Domain Types**: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
100
|
+
- **Image Edit Service**: [`IMAGE_EDIT_SERVICE.md`](./IMAGE_EDIT_SERVICE.md)
|
|
101
|
+
- **Core Client**: [`CORE_CLIENT_SERVICE.md`](./CORE_CLIENT_SERVICE.md)
|
|
102
|
+
- **Retry Service**: [`RETRY_SERVICE.md`](./RETRY_SERVICE.md)
|
|
103
|
+
|
|
104
|
+
## 📋 Configuration Reference
|
|
105
|
+
|
|
106
|
+
### Generation Config
|
|
107
|
+
See: [`domain/entities/README.md`](../domain/entities/README.md)
|
|
108
|
+
|
|
109
|
+
### Model Selection
|
|
110
|
+
- Current model: `imagen-4.0-generate-001`
|
|
111
|
+
- Aspect ratio: 1:1 (only supported ratio)
|
|
112
|
+
- Format: `image/png`
|
|
113
|
+
- Encoding: Base64
|
|
114
|
+
|
|
115
|
+
### Error Types
|
|
116
|
+
See: [`ERROR_UTILITIES.md`](../infrastructure/utils/ERROR_UTILITIES.md)
|
|
117
|
+
|
|
118
|
+
## 🎓 Usage Patterns
|
|
119
|
+
|
|
120
|
+
### Basic Image Generation
|
|
121
|
+
1. Import service
|
|
122
|
+
2. Call `generateImage()` with descriptive prompt
|
|
123
|
+
3. Handle response (contains `imageUrl`, `imageBase64`, `mimeType`)
|
|
124
|
+
4. Display image in React Native Image component
|
|
125
|
+
5. Handle errors appropriately
|
|
126
|
+
|
|
127
|
+
### With Retry Logic
|
|
128
|
+
1. Wrap call in retry mechanism
|
|
129
|
+
2. Configure max retries and delays
|
|
130
|
+
3. Handle retryable errors (network, rate limits)
|
|
131
|
+
4. Provide feedback to user during retries
|
|
132
|
+
|
|
133
|
+
### Saving Generated Images
|
|
134
|
+
1. Generate image using service
|
|
135
|
+
2. Extract `imageBase64` from result
|
|
136
|
+
3. Save to filesystem using React Native FS
|
|
137
|
+
4. Handle file system errors
|
|
138
|
+
|
|
139
|
+
### Uploading Generated Images
|
|
140
|
+
1. Generate image using service
|
|
141
|
+
2. Extract base64 data
|
|
142
|
+
3. Convert to appropriate format
|
|
143
|
+
4. Upload to server/storage
|
|
144
|
+
5. Handle upload errors
|
|
145
|
+
|
|
146
|
+
## 🚨 Common Pitfalls
|
|
147
|
+
|
|
148
|
+
### Don't
|
|
149
|
+
- Use vague or generic prompts
|
|
150
|
+
- Ignore error handling
|
|
151
|
+
- Assume immediate results (generation takes time)
|
|
152
|
+
- Exceed rate limits
|
|
153
|
+
- Try to edit images with this service (use IMAGE_EDIT_SERVICE)
|
|
154
|
+
|
|
155
|
+
### Do
|
|
156
|
+
- Provide detailed, specific prompts
|
|
157
|
+
- Include style and lighting information
|
|
158
|
+
- Handle all error types
|
|
159
|
+
- Implement loading states
|
|
160
|
+
- Use image edit service for modifications
|
|
161
|
+
- Cache generated images appropriately
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
**Last Updated**: 2025-01-08
|
|
166
|
+
**See Also**: [AI_GUIDELINES.md](../../AI_GUIDELINES.md)
|