Skip to content

Commit 1b4f93c

Browse files
rickstaavictorges
andauthored
feat(sdks): implement SDK-specific API customizations (#191)
* feat(sdks): implement SDK-specific API customizations This commit introduces several SDK-specific OpenAPI configurations to the runner API configuration. These customizations will enhance the SDKs we are planning to release. Co-authored-by: Victor Elias <[email protected]>
1 parent 36d796d commit 1b4f93c

File tree

18 files changed

+418
-1314
lines changed

18 files changed

+418
-1314
lines changed

cmd/examples/image-to-image/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func main() {
6969
imageFile := types.File{}
7070
imageFile.InitFromBytes(imageBytes, imagePath)
7171

72-
req := worker.ImageToImageMultipartRequestBody{
72+
req := worker.GenImageToImageMultipartRequestBody{
7373
Image: imageFile,
7474
ModelId: &modelID,
7575
Prompt: prompt,

cmd/examples/image-to-video/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func main() {
6868
imageFile := types.File{}
6969
imageFile.InitFromBytes(imageBytes, imagePath)
7070

71-
req := worker.ImageToVideoMultipartRequestBody{
71+
req := worker.GenImageToVideoMultipartRequestBody{
7272
Image: imageFile,
7373
ModelId: &modelID,
7474
}

cmd/examples/text-to-image/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func main() {
5959

6060
prompt := args[1]
6161

62-
req := worker.TextToImageJSONRequestBody{
62+
req := worker.GenTextToImageJSONRequestBody{
6363
ModelId: &modelID,
6464
Prompt: prompt,
6565
}

runner/app/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ async def lifespan(app: FastAPI):
2121
app.pipeline = load_pipeline(pipeline, model_id)
2222
app.include_router(load_route(pipeline))
2323

24-
use_route_names_as_operation_ids(app)
25-
2624
logger.info(f"Started up with pipeline {app.pipeline}")
2725
yield
2826
logger.info("Shutting down")

runner/app/routes/audio_to_text.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
logger = logging.getLogger(__name__)
1616

1717
RESPONSES = {
18+
status.HTTP_200_OK: {
19+
"content": {
20+
"application/json": {
21+
"schema": {
22+
"x-speakeasy-name-override": "data",
23+
}
24+
}
25+
},
26+
},
1827
status.HTTP_400_BAD_REQUEST: {"model": HTTPError},
1928
status.HTTP_401_UNAUTHORIZED: {"model": HTTPError},
2029
status.HTTP_413_REQUEST_ENTITY_TOO_LARGE: {"model": HTTPError},
@@ -52,6 +61,10 @@ def handle_pipeline_error(e: Exception) -> JSONResponse:
5261
response_model=TextResponse,
5362
responses=RESPONSES,
5463
description="Transcribe audio files to text.",
64+
operation_id="genAudioToText",
65+
summary="Audio To Text",
66+
tags=["generate"],
67+
openapi_extra={"x-speakeasy-name-override": "audioToText"},
5568
)
5669
@router.post(
5770
"/audio-to-text/",

runner/app/routes/health.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class HealthCheck(BaseModel):
88
status: str = "OK"
99

1010

11-
@router.get("/health", response_model=HealthCheck)
11+
@router.get("/health", operation_id="health", response_model=HealthCheck)
1212
@router.get("/health/", response_model=HealthCheck, include_in_schema=False)
1313
def health() -> HealthCheck:
1414
return HealthCheck(status="OK")

runner/app/routes/image_to_image.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919

2020

2121
RESPONSES = {
22+
status.HTTP_200_OK: {
23+
"content": {
24+
"application/json": {
25+
"schema": {
26+
"x-speakeasy-name-override": "data",
27+
}
28+
}
29+
},
30+
},
2231
status.HTTP_400_BAD_REQUEST: {"model": HTTPError},
2332
status.HTTP_401_UNAUTHORIZED: {"model": HTTPError},
2433
status.HTTP_500_INTERNAL_SERVER_ERROR: {"model": HTTPError},
@@ -32,6 +41,10 @@
3241
response_model=ImageResponse,
3342
responses=RESPONSES,
3443
description="Apply image transformations to a provided image.",
44+
operation_id="genImageToImage",
45+
summary="Image To Image",
46+
tags=["generate"],
47+
openapi_extra={"x-speakeasy-name-override": "imageToImage"},
3548
)
3649
@router.post(
3750
"/image-to-image/",

runner/app/routes/image_to_video.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
logger = logging.getLogger(__name__)
1919

2020
RESPONSES = {
21+
status.HTTP_200_OK: {
22+
"content": {
23+
"application/json": {
24+
"schema": {
25+
"x-speakeasy-name-override": "data",
26+
}
27+
}
28+
},
29+
},
2130
status.HTTP_400_BAD_REQUEST: {"model": HTTPError},
2231
status.HTTP_401_UNAUTHORIZED: {"model": HTTPError},
2332
status.HTTP_500_INTERNAL_SERVER_ERROR: {"model": HTTPError},
@@ -31,6 +40,10 @@
3140
response_model=VideoResponse,
3241
responses=RESPONSES,
3342
description="Generate a video from a provided image.",
43+
operation_id="genImageToVideo",
44+
summary="Image To Video",
45+
tags=["generate"],
46+
openapi_extra={"x-speakeasy-name-override": "imageToVideo"},
3447
)
3548
@router.post(
3649
"/image-to-video/",

runner/app/routes/segment_anything_2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
logger = logging.getLogger(__name__)
2525

2626
RESPONSES = {
27+
status.HTTP_200_OK: {
28+
"content": {
29+
"application/json": {
30+
"schema": {
31+
"x-speakeasy-name-override": "data",
32+
}
33+
}
34+
},
35+
},
2736
status.HTTP_400_BAD_REQUEST: {"model": HTTPError},
2837
status.HTTP_401_UNAUTHORIZED: {"model": HTTPError},
2938
status.HTTP_500_INTERNAL_SERVER_ERROR: {"model": HTTPError},
@@ -37,6 +46,10 @@
3746
response_model=MasksResponse,
3847
responses=RESPONSES,
3948
description="Segment objects in an image.",
49+
operation_id="genSegmentAnything2",
50+
summary="Segment Anything 2",
51+
tags=["generate"],
52+
openapi_extra={"x-speakeasy-name-override": "segmentAnything2"},
4053
)
4154
@router.post(
4255
"/segment-anything-2/",

runner/app/routes/text_to_image.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ class TextToImageParams(BaseModel):
9292

9393

9494
RESPONSES = {
95+
status.HTTP_200_OK: {
96+
"content": {
97+
"application/json": {
98+
"schema": {
99+
"x-speakeasy-name-override": "data",
100+
}
101+
}
102+
},
103+
},
95104
status.HTTP_400_BAD_REQUEST: {"model": HTTPError},
96105
status.HTTP_401_UNAUTHORIZED: {"model": HTTPError},
97106
status.HTTP_500_INTERNAL_SERVER_ERROR: {"model": HTTPError},
@@ -103,6 +112,10 @@ class TextToImageParams(BaseModel):
103112
response_model=ImageResponse,
104113
responses=RESPONSES,
105114
description="Generate images from text prompts.",
115+
operation_id="genTextToImage",
116+
summary="Text To Image",
117+
tags=["generate"],
118+
openapi_extra={"x-speakeasy-name-override": "textToImage"},
106119
)
107120
@router.post(
108121
"/text-to-image/",

0 commit comments

Comments
 (0)