-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
JSON type fix in Client and and typing fix for /chat
endpoint in gr.ChatInterface
#10193
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/c654ade0861f827272e7672c7ff241f7af0f188a/gradio-5.8.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@c654ade0861f827272e7672c7ff241f7af0f188a#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/c654ade0861f827272e7672c7ff241f7af0f188a/gradio-client-1.8.0.tgz Use Lite from this PR <script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/c654ade0861f827272e7672c7ff241f7af0f188a/dist/lite.js""></script> |
🦄 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.
|
/chat
endpoint in gr.ChatInterface
(For more context, once we the API set up and typed correctly, I'll start working on the guides on how to deploy a Discord bot, Slack bot, etc. directly from a ChatInterface). |
client/python/gradio_client/utils.py
Outdated
@@ -926,7 +926,7 @@ def _json_schema_to_python_type(schema: Any, defs) -> str: | |||
type_ = get_type(schema) | |||
if type_ == {}: | |||
if "json" in schema.get("description", {}): | |||
return "Dict[Any, Any]" | |||
return "str | list | dict" |
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.
I guess we could collapse both cases into str | bool | int | float | list | dict
since that covers the spectrum of possible json payloads
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.
updated
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.
Nice!
Thanks @freddyaboulton! |
Cool! |
While working on the API for
gr.ChatInterface
, I noticed that the typing for thegr.JSON
component was incorrect. I'm not sure why make a special case for thegr.JSON
component in the first place (@freddyaboulton do you remember?) but at least we should fix the typing here.Also replaces the
gr.Textbox
ingr.ChatInterface
withgr.JSON
so that it correctly states that dictionaries can be returned.For example, the following chat interface is now correctly typed: