-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Support Message API for chatbot and chatinterface #8422
base: main
Are you sure you want to change the base?
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/3c289033bb851b380f0e0cd9b774624aa822e57e/gradio-4.32.2-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@3c289033bb851b380f0e0cd9b774624aa822e57e#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-builds.s3.amazonaws.com/3c289033bb851b380f0e0cd9b774624aa822e57e/gradio-client-0.20.1.tgz |
🦄 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.
|
4aedebd
to
88942ea
Compare
@freddyaboulton this looks great! Just one quibble: I'd suggest not using "openai" as the name of the format. It might be that they modify their message format in a way that we don't want to track. Also Anthropic and others use the same format as well. What about So thinking how we could add support for components into this: we could modify the class Message(GradioModel):
role: str
metadata: Metadata = Field(default_factory=Metadata)
content: str | FileData | Component |
Yes makes sense regarding renaming. What about "messages" (the name used by tgi/transformers and from the looks of it is actually the industry standard name transformers docs anthropic docs ) |
"messages" sounds good, compatibility with transformers/tgi makes more sense 👍 |
This format looks good.
Regrading this, it would have to be another dict
|
imo it would be much nicer DX if the |
Yes that is what I had in mind, we can handle the conversion from component instance to internal payload format in pre/postprocess |
3c28903
to
a6519b8
Compare
Description
Main Changes:
msg_format
parameter toChatbot
andChatInterface
so that messages can be returned as either the current list of tuples or a dictionary that is a superset of the "OAI" format, e.g. {"role": "user", "content": ""}.msg_format
is "messages", then inChatInterface
developers can just yield the next token. They don't have to yield the entire message up to and including that token. I think this makes demos easier to write. And lets developers simply yield from their iterator._testcase.py
in a demo directory corresponding to an e2e test, that demo will also be loaded to the e2e app. And you can usego_to_testcase
to navigate to that testcase.OAI format overview
The message format is a dict with two required keys
role
andcontent
. There is an additionalmetadata
key that is not required but it can be used for tools and additional info about the message. Most messages returned from an "openai compatible" client will be compatible with gradio.The implementation of the message is below:
Examples
Realistic Inference API Streaming
ChatInterface Streaming
ChatInterface Multimodal
Chatbot
Multimodal Chatbot
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh