GPTRouter 0.5.2__tar.gz → 0.5.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: GPTRouter
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: GPTRouter
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -10,6 +10,7 @@ from gpt_router.models import (
10
10
  GPTRouterMetadata,
11
11
  ImageGenerationRequest,
12
12
  ImageGenerationResponse,
13
+ ImageEditRequest,
13
14
  ModelGenerationRequest,
14
15
  GenerationResponse,
15
16
  ChunkedGenerationResponse,
@@ -67,6 +68,8 @@ class GPTRouterClient:
67
68
  additional_metadata: Optional[GPTRouterMetadata] = None,
68
69
  ):
69
70
  self.base_url = base_url
71
+ if api_key is None:
72
+ raise ValueError("API key cannot be None. Please provide a valid API key.")
70
73
  self.api_key = api_key
71
74
  self.request_timeout = request_timeout
72
75
  self.additional_metadata = additional_metadata
@@ -463,6 +466,55 @@ class GPTRouterClient:
463
466
  for generated_img in generated_images
464
467
  ]
465
468
 
469
+ def edit_image(self, *, image_edit_request: ImageEditRequest) -> List[ImageGenerationResponse]:
470
+ """
471
+ Edit an image based on the provided ImageEditRequest.
472
+ This is a synchronous wrapper around the async method.
473
+
474
+ Args:
475
+ image_edit_request: The request containing the image and editing instructions
476
+
477
+ Returns:
478
+ List of image generation responses
479
+ """
480
+ import asyncio
481
+
482
+ async def _async_call():
483
+ return await self.aedit_image(image_edit_request=image_edit_request)
484
+
485
+ return asyncio.run(_async_call())
486
+
487
+ async def aedit_image(self, *, image_edit_request: ImageEditRequest) -> List[ImageGenerationResponse]:
488
+ """
489
+ Edit an image based on the provided ImageEditRequest.
490
+
491
+ Args:
492
+ image_edit_request: The request containing the image and editing instructions
493
+
494
+ Returns:
495
+ List of image generation responses
496
+ """
497
+ api_path = "/v1/generate/edit-image"
498
+ api_method = "POST"
499
+ api_payload = image_edit_request.dict()
500
+
501
+ api_response = await self._async_api_call(
502
+ path=api_path,
503
+ method=api_method,
504
+ payload=api_payload,
505
+ )
506
+
507
+ generated_images = api_response.get("response", {}).get("data", [])
508
+
509
+ return [
510
+ parse_obj_as(ImageGenerationResponse, {
511
+ "url": img.get("url", None),
512
+ "base64": img.get("b64_json", None),
513
+ "finish_reason": "SUCCESS"
514
+ })
515
+ for img in generated_images
516
+ ]
517
+
466
518
  def _extract_images_from_dict(self, image_dict: dict) -> List[dict]:
467
519
  if artifacts := image_dict.get("artifacts"):
468
520
  return artifacts
@@ -1,8 +1,7 @@
1
1
  from uuid import UUID
2
- from pydantic import BaseModel, Field
2
+ from pydantic import BaseModel, Field, root_validator, validator
3
3
  from enum import Enum
4
-
5
- from typing import List, Optional, Dict, Any, Union
4
+ from typing import Dict, List, Optional, Any, Union
6
5
  from humps import camelize
7
6
 
8
7
 
@@ -142,6 +141,26 @@ class ImageGenerationResponse(BaseModel):
142
141
  finish_reason: Optional[str] = Field(default="SUCCESS", alias="finishReason")
143
142
 
144
143
 
144
+ class ImageEditRequest(BaseModel):
145
+ model_name: str = Field(alias="model", default="gpt-image-1")
146
+ image: Union[str, List[str]] = Field(...)
147
+ prompt: str = Field(...)
148
+ mask: Optional[str] = Field(default=None)
149
+ num_images: Optional[int] = Field(alias="n", default=1)
150
+ quality: Optional[str] = Field(default="high")
151
+ response_format: Optional[str] = Field(alias="responseFormat", default=None)
152
+ size: Optional[str] = Field(default="1024x1024")
153
+ user: Optional[str] = Field(default=None)
154
+
155
+ class Config:
156
+ allow_population_by_field_name = True
157
+ protected_namespaces = ()
158
+
159
+ def dict(self, *args, **kwargs):
160
+ base_dict = super().dict(*args, **kwargs, exclude_none=True, by_alias=True)
161
+ return base_dict
162
+
163
+
145
164
  class ModelRouterGenerationRequest(BaseModel):
146
165
  model_name: str
147
166
  model_provider: str
@@ -3,9 +3,10 @@ from setuptools import setup
3
3
  with open("README.md", "r") as fh:
4
4
  long_description = fh.read()
5
5
 
6
+
6
7
  setup(
7
8
  name="GPTRouter",
8
- version="0.5.2",
9
+ version="0.5.3",
9
10
  description="A Python package for working with GPTRouter APIs",
10
11
  long_description=long_description,
11
12
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes