@umituz/react-native-ai-gemini-provider 1.3.0 → 1.5.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-gemini-provider",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Google Gemini AI provider for React Native applications",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -21,6 +21,8 @@ export interface GeminiGenerationConfig {
21
21
  topP?: number;
22
22
  maxOutputTokens?: number;
23
23
  stopSequences?: string[];
24
+ /** Response modalities for multimodal output (TEXT, IMAGE) */
25
+ responseModalities?: Array<"TEXT" | "IMAGE">;
24
26
  }
25
27
 
26
28
  export interface GeminiSafetySettings {
@@ -4,3 +4,4 @@
4
4
 
5
5
  export * from "./gemini.types";
6
6
  export * from "./error.types";
7
+ export * from "./models";
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Gemini Model Constants
3
+ * Centralized model configuration for all AI operations
4
+ */
5
+
6
+ /**
7
+ * Available Gemini models
8
+ */
9
+ export const GEMINI_MODELS = {
10
+ // Text generation models
11
+ TEXT: {
12
+ FLASH: "gemini-2.0-flash",
13
+ FLASH_LITE: "gemini-2.0-flash-lite",
14
+ PRO: "gemini-1.5-pro",
15
+ },
16
+
17
+ // Image generation models
18
+ IMAGE: {
19
+ FLASH: "gemini-2.5-flash-preview-image-generation",
20
+ FLASH_STABLE: "gemini-2.0-flash-preview-image-generation",
21
+ },
22
+
23
+ // Video understanding models
24
+ VIDEO: {
25
+ FLASH: "gemini-2.0-flash",
26
+ },
27
+ } as const;
28
+
29
+ /**
30
+ * Default models for each operation type
31
+ */
32
+ export const DEFAULT_MODELS = {
33
+ TEXT: GEMINI_MODELS.TEXT.FLASH,
34
+ IMAGE: GEMINI_MODELS.IMAGE.FLASH,
35
+ VIDEO: GEMINI_MODELS.VIDEO.FLASH,
36
+ } as const;
37
+
38
+ /**
39
+ * Response modalities for different generation types
40
+ */
41
+ export const RESPONSE_MODALITIES = {
42
+ TEXT_ONLY: ["TEXT"] as const,
43
+ IMAGE_ONLY: ["IMAGE"] as const,
44
+ TEXT_AND_IMAGE: ["TEXT", "IMAGE"] as const,
45
+ } as const;
46
+
47
+ export type ResponseModality = "TEXT" | "IMAGE";
package/src/index.ts CHANGED
@@ -42,6 +42,15 @@ export type {
42
42
  GeminiApiError,
43
43
  } from "./domain/entities";
44
44
 
45
+ // Model Constants
46
+ export {
47
+ GEMINI_MODELS,
48
+ DEFAULT_MODELS,
49
+ RESPONSE_MODALITIES,
50
+ } from "./domain/entities";
51
+
52
+ export type { ResponseModality } from "./domain/entities";
53
+
45
54
  // =============================================================================
46
55
  // INFRASTRUCTURE LAYER - Services
47
56
  // =============================================================================
@@ -4,6 +4,10 @@
4
4
  */
5
5
 
6
6
  import { GoogleGenerativeAI, type GenerativeModel } from "@google/generative-ai";
7
+ import {
8
+ DEFAULT_MODELS,
9
+ RESPONSE_MODALITIES,
10
+ } from "../../domain/entities";
7
11
  import type {
8
12
  GeminiConfig,
9
13
  GeminiContent,
@@ -21,8 +25,8 @@ const DEFAULT_CONFIG: Partial<GeminiConfig> = {
21
25
  baseDelay: 1000,
22
26
  maxDelay: 10000,
23
27
  defaultTimeoutMs: 60000,
24
- defaultModel: "gemini-2.0-flash",
25
- imageModel: "gemini-2.0-flash",
28
+ defaultModel: DEFAULT_MODELS.TEXT,
29
+ imageModel: DEFAULT_MODELS.IMAGE,
26
30
  };
27
31
 
28
32
  const RETRYABLE_ERROR_PATTERNS = [
@@ -226,14 +230,14 @@ class GeminiClientService {
226
230
 
227
231
  /**
228
232
  * Generate image from prompt and/or input images
229
- * Uses Gemini 2.0 Flash with image generation capability
233
+ * Uses centralized model config with responseModalities for image output
230
234
  */
231
235
  async generateImage(
232
236
  prompt: string,
233
237
  images?: Array<{ base64: string; mimeType: string }>,
234
238
  config?: GeminiGenerationConfig,
235
239
  ): Promise<GeminiImageGenerationResult> {
236
- const imageModel = this.config?.imageModel || "gemini-2.0-flash-exp";
240
+ const imageModel = this.config?.imageModel || DEFAULT_MODELS.IMAGE;
237
241
 
238
242
  if (typeof __DEV__ !== "undefined" && __DEV__) {
239
243
  // eslint-disable-next-line no-console
@@ -259,7 +263,14 @@ class GeminiClientService {
259
263
  }
260
264
 
261
265
  const contents: GeminiContent[] = [{ parts, role: "user" }];
262
- const response = await this.generateContent(imageModel, contents, config);
266
+
267
+ // Image generation requires responseModalities to include IMAGE
268
+ const imageConfig: GeminiGenerationConfig = {
269
+ ...config,
270
+ responseModalities: [...RESPONSE_MODALITIES.TEXT_AND_IMAGE],
271
+ };
272
+
273
+ const response = await this.generateContent(imageModel, contents, imageConfig);
263
274
 
264
275
  // Extract generated image from response
265
276
  const result: GeminiImageGenerationResult = {