indoxrouter 0.1.21__py3-none-any.whl → 0.1.23__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
@@ -647,10 +647,11 @@ class Client:
647
647
  # Format the model string
648
648
  formatted_model = self._format_model_string(model)
649
649
 
650
- # Extract provider from model string if present
650
+ # Extract provider and model name from model string if present
651
651
  provider = "openai" # Default provider
652
+ model_name = model
652
653
  if "/" in model:
653
- provider, _ = model.split("/", 1)
654
+ provider, model_name = model.split("/", 1)
654
655
 
655
656
  # Filter out problematic parameters
656
657
  filtered_kwargs = {}
@@ -672,20 +673,29 @@ class Client:
672
673
  if provider.lower() == "google":
673
674
  # For Google, use aspect_ratio instead of size
674
675
  if aspect_ratio is not None:
676
+ # Google's imagen-3 has specific supported aspect ratios
677
+ if model_name == "imagen-3.0-generate-002" and aspect_ratio not in [
678
+ "1:1",
679
+ "3:4",
680
+ "4:3",
681
+ "9:16",
682
+ "16:9",
683
+ ]:
684
+ aspect_ratio = "1:1" # Default to 1:1 if not supported
675
685
  data["aspect_ratio"] = aspect_ratio
676
686
  elif size is not None:
677
687
  # Convert size to aspect_ratio
678
688
  formatted_size = self._format_image_size_for_provider(
679
- size, provider, model
689
+ size, provider, model_name
680
690
  )
681
691
  data["aspect_ratio"] = formatted_size
682
692
  else:
683
693
  # Default aspect_ratio for Google
684
694
  data["aspect_ratio"] = "1:1"
685
695
  elif provider.lower() == "xai":
686
- # xAI doesn't support size parameter
696
+ # xAI doesn't support size parameter - do not include it
687
697
  pass
688
- elif size is not None:
698
+ elif size is not None and provider.lower() != "xai":
689
699
  # For other providers (like OpenAI), use size as is
690
700
  data["size"] = size
691
701
 
@@ -696,7 +706,9 @@ class Client:
696
706
 
697
707
  # Add standard parameters if provided
698
708
  if response_format is not None:
709
+ # Only add response_format if explicitly provided by the user
699
710
  data["response_format"] = response_format
711
+
700
712
  if user is not None:
701
713
  data["user"] = user
702
714
 
@@ -738,8 +750,85 @@ class Client:
738
750
  if filtered_kwargs:
739
751
  data["additional_params"] = filtered_kwargs
740
752
 
753
+ # Special case handling for specific models and providers
754
+ # Only include parameters supported by each model based on their JSON definitions
755
+ if provider.lower() == "openai" and "gpt-image" in model_name.lower():
756
+ # For OpenAI's gpt-image models, don't automatically add response_format
757
+ if "response_format" in data and response_format is None:
758
+ del data["response_format"]
759
+
760
+ if provider.lower() == "xai" and "grok-2-image" in model_name.lower():
761
+ # For xAI's grok-2-image models, ensure size is not included
762
+ if "size" in data:
763
+ del data["size"]
764
+
765
+ # Clean up any parameters that shouldn't be sent to specific providers
766
+ # This ensures we only send parameters that each provider supports
767
+ supported_params = self._get_supported_parameters_for_model(
768
+ provider, model_name
769
+ )
770
+ if supported_params:
771
+ for param in list(data.keys()):
772
+ if param not in ["prompt", "model"] and param not in supported_params:
773
+ del data[param]
774
+
741
775
  return self._request("POST", IMAGE_ENDPOINT, data)
742
776
 
777
+ def _get_supported_parameters_for_model(
778
+ self, provider: str, model_name: str
779
+ ) -> List[str]:
780
+ """
781
+ Get the list of supported parameters for a specific model.
782
+ This helps avoid sending unsupported parameters to providers.
783
+
784
+ Args:
785
+ provider: The provider name (e.g., 'openai', 'google', 'xai')
786
+ model_name: The model name (e.g., 'gpt-image-1', 'imagen-3.0-generate-002')
787
+
788
+ Returns:
789
+ List of parameter names supported by the model
790
+ """
791
+ # Define supported parameters for specific models
792
+ if provider.lower() == "openai" and "gpt-image" in model_name.lower():
793
+ return [
794
+ "prompt",
795
+ "size",
796
+ "quality",
797
+ "n",
798
+ "user",
799
+ "background",
800
+ "moderation",
801
+ "output_compression",
802
+ "output_format",
803
+ "style",
804
+ ]
805
+
806
+ elif provider.lower() == "google" and "imagen" in model_name.lower():
807
+ return [
808
+ "prompt",
809
+ "n",
810
+ "negative_prompt",
811
+ "aspect_ratio",
812
+ "guidance_scale",
813
+ "seed",
814
+ "safety_filter_level",
815
+ "person_generation",
816
+ "include_safety_attributes",
817
+ "include_rai_reason",
818
+ "language",
819
+ "output_mime_type",
820
+ "output_compression_quality",
821
+ "add_watermark",
822
+ "enhance_prompt",
823
+ "response_format",
824
+ ]
825
+
826
+ elif provider.lower() == "xai" and "grok-2-image" in model_name.lower():
827
+ return ["prompt", "n", "response_format"]
828
+
829
+ # Default case - allow all parameters
830
+ return []
831
+
743
832
  def models(self, provider: Optional[str] = None) -> Dict[str, Any]:
744
833
  """
745
834
  Get available models.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: indoxrouter
3
- Version: 0.1.21
3
+ Version: 0.1.23
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=GwdZJiUARBGcD-A_VI1vFXWtvhQTF-3dDCBz-1qtrhk,41632
3
+ indoxrouter/constants.py,sha256=GezZ9nuwK3A37xpWlcfXCrMsIIlCdP7xnvEkPBMyn5g,1383
4
+ indoxrouter/exceptions.py,sha256=qs7f9AnJ7SkOyf9N5qRaZIKpECE8uBq1Pvcg19Jif-U,1718
5
+ indoxrouter-0.1.23.dist-info/METADATA,sha256=xUem08HFj7X3WWvcbqg70fOW4W4f04-Yb7BSw13zBb0,6639
6
+ indoxrouter-0.1.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ indoxrouter-0.1.23.dist-info/top_level.txt,sha256=v6FGWkw0QAnXhyYtnXLI1cxzna0iveNvZUotVzCWabM,12
8
+ indoxrouter-0.1.23.dist-info/RECORD,,
@@ -1,8 +0,0 @@
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,,