-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9692644
commit 1156140
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from finegrain import EditorAPIContext | ||
from pydantic import BaseModel | ||
from quart import Request, Response, jsonify | ||
from quart import current_app as app | ||
|
||
from chatgpt_bridge.utils import json_error | ||
|
||
|
||
class UndoParams(BaseModel): | ||
stateid: str | ||
|
||
|
||
class UndoOutput(BaseModel): | ||
openaiFileResponse: list[str] # noqa: N815 | ||
stateid_output_img: str | ||
|
||
|
||
async def _undo(ctx: EditorAPIContext, request: Request) -> Response: | ||
# parse input data | ||
input_json = await request.get_json() | ||
app.logger.debug(f"json payload: {input_json}") | ||
input_data = UndoParams(**input_json) | ||
app.logger.debug(f"parsed payload: {input_data}") | ||
|
||
# check the stateid | ||
if not input_data.stateid: | ||
return json_error("stateid is required", 400) | ||
|
||
# queue state/get-public-link | ||
stateid_link = await ctx.get_public_link(input_data.stateid) | ||
app.logger.debug(f"stateid_link: {stateid_link}") | ||
|
||
# get the public link | ||
metadata_link = await ctx.get_meta(stateid_link) | ||
app.logger.debug(f"metadata_link: {metadata_link}") | ||
|
||
# build output response | ||
output_data = UndoOutput( | ||
openaiFileResponse=[metadata_link["public_link"]], | ||
stateid_output_img=input_data.stateid, | ||
) | ||
app.logger.debug(f"output payload: {output_data}") | ||
output_response = jsonify(output_data.model_dump()) | ||
return output_response |