Skip to content

Commit

Permalink
fix(api): fix incorrect I2I OpenAPI gateway spec (#105)
Browse files Browse the repository at this point in the history
This commit ensures that the right format is set in the OpenAPI spec for
when the I2I response is coming from the gateway. This is a little bit
hacky since we don't yet generate the OpenAPI spec where it is
implemented (i.e. in go-livepeer).
  • Loading branch information
rickstaa authored Jun 13, 2024
1 parent 8c8c69d commit 0a26654
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 6 additions & 2 deletions runner/app/routes/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def image_to_video(
motion_bucket_id=motion_bucket_id,
noise_aug_strength=noise_aug_strength,
safety_check=safety_check,
seed=seed
seed=seed,
)
except Exception as e:
logger.error(f"ImageToVideoPipeline error: {e}")
Expand All @@ -95,7 +95,11 @@ async def image_to_video(
for frames in batch_frames:
output_frames.append(
[
{"url": image_to_data_url(frame), "seed": seed, "nsfw": has_nsfw_concept[0]}
{
"url": image_to_data_url(frame),
"seed": seed,
"nsfw": has_nsfw_concept[0],
}
for frame in frames
]
)
Expand Down
17 changes: 14 additions & 3 deletions runner/gen_openapi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import json
import os
import copy

import yaml
from app.main import app, use_route_names_as_operation_ids
Expand All @@ -21,9 +22,11 @@ def translate_to_gateway(openapi):
entrypoint created by the https://github.com/livepeer/go-livepeer package.
.. note::
Differences between 'runner' and 'gateway' entrypoints:
- 'health' endpoint is removed.
- 'model_id' is enforced in all endpoints.
Differences between 'runner' and 'gateway' entrypoints:
- 'health' endpoint is removed.
- 'model_id' is enforced in all endpoints.
- 'VideoResponse' schema is updated to match the Gateway's transcoded mp4
response.
Args:
openapi (dict): The OpenAPI schema to be translated.
Expand All @@ -49,6 +52,14 @@ def translate_to_gateway(openapi):
if "model_id" in schema["properties"]:
schema["required"].append("model_id")

# Update the 'VideoResponse' schema to match the Gateway's response.
# NOTE: This is necessary because the Gateway transcodes the runner's response and
# returns an mp4 file.
openapi["components"]["schemas"]["VideoResponse"] = copy.deepcopy(
openapi["components"]["schemas"]["ImageResponse"]
)
openapi["components"]["schemas"]["VideoResponse"]["title"] = "VideoResponse"

return openapi


Expand Down

0 comments on commit 0a26654

Please sign in to comment.