-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix request serialization for fastapi /docs
#8530
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/c841ac8484eb4d18ef185ee583c75f4a6ff73b1e/gradio-4.36.1-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@c841ac8484eb4d18ef185ee583c75f4a6ff73b1e#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-builds.s3.amazonaws.com/c841ac8484eb4d18ef185ee583c75f4a6ff73b1e/gradio-client-1.1.1.tgz |
gradio/data_classes.py
Outdated
@@ -110,6 +110,24 @@ class PredictBody(BaseModel): | |||
None # dictionary of request headers, query parameters, url, etc. (used to to pass in request for queuing) | |||
) | |||
|
|||
def __get_pydantic_json_schema__(self, source_type: Any, handler): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the docs, this should be a class method!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @freddyaboulton, for pointing that out! I've updated the method to be a class method as per the documentation. Please review the latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - added a unit test
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
This commit addresses a serialization issue in the
PredictBody
model that has been present since version 4.0. Therequest
attribute, being of typeRequest
, could not be serialized automatically, affecting FastAPI's auto-generated documentation (/openapi.json).By adding a custom
__get_pydantic_json_schema__
method, the serialization schema is manually defined, ensuring correct documentation generation.This is also one of the reasons why applications like "stable-diffusion-webui," which require /docs pages, have not updated to newer versions of Gradio.
Closes: #7287