GPTRouter 0.5.2__tar.gz → 0.5.4__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.
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/GPTRouter.egg-info/PKG-INFO +1 -1
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/PKG-INFO +1 -1
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/gpt_router/client.py +52 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/gpt_router/models.py +27 -3
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/setup.py +1 -1
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/GPTRouter.egg-info/SOURCES.txt +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/GPTRouter.egg-info/dependency_links.txt +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/GPTRouter.egg-info/requires.txt +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/GPTRouter.egg-info/top_level.txt +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/LICENSE +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/README.md +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/gpt_router/__init__.py +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/gpt_router/constants.py +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/gpt_router/enums.py +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/gpt_router/exceptions.py +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/pyproject.toml +0 -0
- {GPTRouter-0.5.2 → GPTRouter-0.5.4}/setup.cfg +0 -0
|
@@ -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, Literal, Optional, Any, Union
|
|
6
5
|
from humps import camelize
|
|
7
6
|
|
|
8
7
|
|
|
@@ -63,6 +62,7 @@ class GenerationParams(BaseModel):
|
|
|
63
62
|
colasce_into_thinking_tag: Optional[bool] = None
|
|
64
63
|
use_response_api: Optional[bool] = None
|
|
65
64
|
web_search_options: Optional[WebSearchOptions] = None
|
|
65
|
+
reasoning_effort: Optional[Literal["low", "medium", "high"]] = None
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
class ModelGenerationRequest(BaseModel):
|
|
@@ -120,6 +120,10 @@ class ImageGenerationRequest(BaseModel):
|
|
|
120
120
|
width: Optional[int] = Field(None, alias="width")
|
|
121
121
|
height: Optional[int] = Field(None, alias="height")
|
|
122
122
|
num_inference_steps: Optional[int] = Field(None, alias="numInferenceSteps")
|
|
123
|
+
app_id: Optional[str] = Field(None, alias="appId")
|
|
124
|
+
user_id: Optional[str] = Field(None, alias="createdByUserId")
|
|
125
|
+
history_id: Optional[str] = Field(None, alias="historyId")
|
|
126
|
+
feature: Optional[str] = Field(None, alias="feature")
|
|
123
127
|
|
|
124
128
|
class Config:
|
|
125
129
|
allow_population_by_field_name = True
|
|
@@ -142,6 +146,26 @@ class ImageGenerationResponse(BaseModel):
|
|
|
142
146
|
finish_reason: Optional[str] = Field(default="SUCCESS", alias="finishReason")
|
|
143
147
|
|
|
144
148
|
|
|
149
|
+
class ImageEditRequest(BaseModel):
|
|
150
|
+
model_name: str = Field(alias="model", default="gpt-image-1")
|
|
151
|
+
image: Union[str, List[str]] = Field(...)
|
|
152
|
+
prompt: str = Field(...)
|
|
153
|
+
mask: Optional[str] = Field(default=None)
|
|
154
|
+
num_images: Optional[int] = Field(alias="n", default=1)
|
|
155
|
+
quality: Optional[str] = Field(default="high")
|
|
156
|
+
response_format: Optional[str] = Field(alias="responseFormat", default=None)
|
|
157
|
+
size: Optional[str] = Field(default="1024x1024")
|
|
158
|
+
user: Optional[str] = Field(default=None)
|
|
159
|
+
|
|
160
|
+
class Config:
|
|
161
|
+
allow_population_by_field_name = True
|
|
162
|
+
protected_namespaces = ()
|
|
163
|
+
|
|
164
|
+
def dict(self, *args, **kwargs):
|
|
165
|
+
base_dict = super().dict(*args, **kwargs, exclude_none=True, by_alias=True)
|
|
166
|
+
return base_dict
|
|
167
|
+
|
|
168
|
+
|
|
145
169
|
class ModelRouterGenerationRequest(BaseModel):
|
|
146
170
|
model_name: str
|
|
147
171
|
model_provider: str
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|