indoxrouter 0.1.18__py3-none-any.whl → 0.1.21__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.
indoxrouter/client.py CHANGED
@@ -399,6 +399,48 @@ class Client:
399
399
  # is having issues with JSON formatted model strings
400
400
  return model
401
401
 
402
+ def _format_image_size_for_provider(
403
+ self, size: str, provider: str, model: str
404
+ ) -> str:
405
+ """
406
+ Format the image size parameter based on the provider's requirements.
407
+
408
+ Google requires aspect ratios like "1:1", "4:3", etc. while OpenAI uses pixel dimensions
409
+ like "1024x1024", "512x512", etc.
410
+
411
+ Args:
412
+ size: The size parameter (e.g., "1024x1024")
413
+ provider: The provider name (e.g., "google", "openai")
414
+ model: The model name
415
+
416
+ Returns:
417
+ Formatted size parameter appropriate for the provider
418
+ """
419
+ if provider.lower() == "google":
420
+ # Google uses aspect ratios instead of pixel dimensions
421
+ # Convert common pixel dimensions to aspect ratios
422
+ size_to_aspect_ratio = {
423
+ "1024x1024": "1:1",
424
+ "512x512": "1:1",
425
+ "256x256": "1:1",
426
+ "1024x768": "4:3",
427
+ "768x1024": "3:4",
428
+ "1024x1536": "2:3",
429
+ "1536x1024": "3:2",
430
+ "1792x1024": "16:9",
431
+ "1024x1792": "9:16",
432
+ }
433
+
434
+ # Check if size is already in aspect ratio format (contains a colon)
435
+ if ":" in size:
436
+ return size
437
+
438
+ # Convert to aspect ratio if we have a mapping, otherwise use default 1:1
439
+ return size_to_aspect_ratio.get(size, "1:1")
440
+
441
+ # For other providers, return the original size
442
+ return size
443
+
402
444
  def chat(
403
445
  self,
404
446
  messages: List[Dict[str, str]],
@@ -555,6 +597,8 @@ class Client:
555
597
  output_mime_type: Optional[str] = None,
556
598
  add_watermark: Optional[bool] = None,
557
599
  enhance_prompt: Optional[bool] = None,
600
+ # Google-specific direct parameters
601
+ aspect_ratio: Optional[str] = None,
558
602
  **kwargs,
559
603
  ) -> Dict[str, Any]:
560
604
  """
@@ -566,7 +610,7 @@ class Client:
566
610
 
567
611
  # Provider-specific parameters - will only be included if explicitly provided
568
612
  # Note: Different providers support different parameters
569
- size: Image size - For OpenAI: "1024x1024", "512x512", etc. For Google: "1:1", "4:3", etc.
613
+ size: Image size - For OpenAI: "1024x1024", "512x512", etc. For Google: use aspect_ratio instead
570
614
  n: Number of images to generate
571
615
  quality: Image quality (e.g., "standard", "hd") - supported by some providers
572
616
  style: Image style (e.g., "vivid", "natural") - supported by some providers
@@ -593,6 +637,7 @@ class Client:
593
637
  output_mime_type: MIME type of the generated image
594
638
  add_watermark: Whether to add a watermark to the generated images
595
639
  enhance_prompt: Whether to use prompt rewriting logic
640
+ aspect_ratio: Aspect ratio for Google models (e.g., "1:1", "16:9") - preferred over size
596
641
 
597
642
  **kwargs: Additional parameters to pass to the API
598
643
 
@@ -602,6 +647,11 @@ class Client:
602
647
  # Format the model string
603
648
  formatted_model = self._format_model_string(model)
604
649
 
650
+ # Extract provider from model string if present
651
+ provider = "openai" # Default provider
652
+ if "/" in model:
653
+ provider, _ = model.split("/", 1)
654
+
605
655
  # Filter out problematic parameters
606
656
  filtered_kwargs = {}
607
657
  for key, value in kwargs.items():
@@ -617,8 +667,28 @@ class Client:
617
667
  # Add optional parameters only if they are explicitly provided
618
668
  if n is not None:
619
669
  data["n"] = n
620
- if size is not None:
670
+
671
+ # Handle size/aspect_ratio parameters based on provider
672
+ if provider.lower() == "google":
673
+ # For Google, use aspect_ratio instead of size
674
+ if aspect_ratio is not None:
675
+ data["aspect_ratio"] = aspect_ratio
676
+ elif size is not None:
677
+ # Convert size to aspect_ratio
678
+ formatted_size = self._format_image_size_for_provider(
679
+ size, provider, model
680
+ )
681
+ data["aspect_ratio"] = formatted_size
682
+ else:
683
+ # Default aspect_ratio for Google
684
+ data["aspect_ratio"] = "1:1"
685
+ elif provider.lower() == "xai":
686
+ # xAI doesn't support size parameter
687
+ pass
688
+ elif size is not None:
689
+ # For other providers (like OpenAI), use size as is
621
690
  data["size"] = size
691
+
622
692
  if quality is not None:
623
693
  data["quality"] = quality
624
694
  if style is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: indoxrouter
3
- Version: 0.1.18
3
+ Version: 0.1.21
4
4
  Summary: A unified client for various AI providers
5
5
  Author-email: indoxRouter Team <ashkan.eskandari.dev@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,8 @@
1
+ indoxrouter/__init__.py,sha256=kwGvH8F5oqm2O4kLs-UtPfcY0AYiy5ZDUg-Sh3iYJA4,1627
2
+ indoxrouter/client.py,sha256=5oNwvLMzFV9_jEffCZe0fzQy0m-807rFSS2NmJNv4_s,38023
3
+ indoxrouter/constants.py,sha256=GezZ9nuwK3A37xpWlcfXCrMsIIlCdP7xnvEkPBMyn5g,1383
4
+ indoxrouter/exceptions.py,sha256=qs7f9AnJ7SkOyf9N5qRaZIKpECE8uBq1Pvcg19Jif-U,1718
5
+ indoxrouter-0.1.21.dist-info/METADATA,sha256=znCM17Sp8qaLphTKtJKx4Bmz4Om8Ys91Jo5hF9yyVEI,6639
6
+ indoxrouter-0.1.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ indoxrouter-0.1.21.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
8
+ indoxrouter-0.1.21.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- indoxrouter/__init__.py,sha256=kwGvH8F5oqm2O4kLs-UtPfcY0AYiy5ZDUg-Sh3iYJA4,1627
2
- indoxrouter/client.py,sha256=j1ESSti83R9_fDiYEop0FJqtho0e2FuYes92XY7iImI,35263
3
- indoxrouter/constants.py,sha256=GezZ9nuwK3A37xpWlcfXCrMsIIlCdP7xnvEkPBMyn5g,1383
4
- indoxrouter/exceptions.py,sha256=qs7f9AnJ7SkOyf9N5qRaZIKpECE8uBq1Pvcg19Jif-U,1718
5
- indoxrouter-0.1.18.dist-info/METADATA,sha256=2K3ms5FkCR1L_PkApVOwzF10AHZWh-nn6yi9GvqDlQE,6639
6
- indoxrouter-0.1.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- indoxrouter-0.1.18.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
8
- indoxrouter-0.1.18.dist-info/RECORD,,