Skip to content
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

gr.load_chat: Allow loading any openai-compatible server immediately as a ChatInterface #10222

Merged
merged 9 commits into from
Dec 19, 2024

Conversation

aliabid94
Copy link
Collaborator

@aliabid94 aliabid94 commented Dec 17, 2024

gr.load_chat allows loading any openai chatbot immediately as a ChatInterface easily.

gr.load_chat("http://localhost:11434/v1/", "llama3.2").launch()

Can be customized as such:

import gradio as gr
gr.ChatInterface(
  gr.load_chat("http://localhost:11434/v1/", "llama3.2"),
  title="Etc"
).launch()

I think this will be an especially popular pairing with Ollama.

In a follow up PR, will add support for media input and responses.

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 17, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/0a1285dd8d60705f86ffe137f3d0a930f3e6b986/gradio-5.9.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@0a1285dd8d60705f86ffe137f3d0a930f3e6b986#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/0a1285dd8d60705f86ffe137f3d0a930f3e6b986/gradio-client-1.8.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/0a1285dd8d60705f86ffe137f3d0a930f3e6b986/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 17, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

gr.load_chat: Allow loading any openai-compatible server immediately as a ChatInterface

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs
Copy link
Member

abidlabs commented Dec 18, 2024

Very cool @aliabid94! I find this part kind of confusing though:

Can be customized as such:

import gradio as gr
gr.ChatInterface(
  gr.load_chat("http://localhost:11434/v1/", "llama3.2"),
  title="Etc"
).launch()

So gr.load_chat produces a ChatInterface, but now you can pass a ChatInterface as the fn parameter into a new ChatInterface? That's not intuitive and the DX is not optimal since many of the parameters in gr.ChatInterface (e.g. additional_inputs) don't make sense if you are loading an openai server.

What about if we did the following instead?

gr.ChatInterface.load(server_url). To let users customize, we could add title and whichever parameters actually make sense for loading an openai server to this factory method gr.ChatInterface.load() instead.

@aliabid94
Copy link
Collaborator Author

What about if we did the following instead?

gr.ChatInterface.load(server_url). To let users customize, we could add title and whichever parameters actually make sense for loading an openai server to this factory method gr.ChatInterface.load() instead.

Well we can't use load, that's the event listener for when the demo loads. So we could do something like gr.ChatInterface.load_from(server_url), but that feels too long. I also don't really like the idea of copying all the kwargs and docstrings over again from the constructor to this load_from method, that would be like 40 lines of code duplication.

gr.load_chat mirrors gr.load. Using gr.load as a function for a customized Interface is also the current way to customize a gr.Interface, e.g.

demo = gr.Interface(fn=gr.load("model/meta-ai/llama3.2"), title="My App", examples=["a", "b"])

mirrors

demo = gr.ChatInterface(fn=gr.load_chat("http://chat.com/v1"), title="My App", examples=["a", "b"])

So I think the existing API makes the most sense.

@abidlabs
Copy link
Member

I see thanks for explaining 👍

gradio/external.py Outdated Show resolved Hide resolved
gradio/external.py Outdated Show resolved Hide resolved
gradio/external.py Outdated Show resolved Hide resolved
Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm works great @aliabid94! Can we add some documentation around this at the top of https://www.gradio.app/guides/creating-a-chatbot-fast?

@abidlabs abidlabs changed the title gr.load_chat: Allow loading any openai chatbot immediately as a ChatInterface gr.load_chat: Allow loading any openai-compatible server immediately as a ChatInterface Dec 18, 2024
```python
import gradio as gr

gr.load_chat("http://localhost:11434/v1/", "llama3.2").launch()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gr.load_chat("http://localhost:11434/v1/", "llama3.2").launch()
gr.load_chat("http://localhost:11434/v1/", model="llama3.2", token="ollama").launch()

@aliabid94 aliabid94 enabled auto-merge (squash) December 19, 2024 23:30
@aliabid94 aliabid94 merged commit 9c6d83d into main Dec 19, 2024
22 checks passed
@aliabid94 aliabid94 deleted the load_oai_chat branch December 19, 2024 23:41
freddyaboulton pushed a commit that referenced this pull request Dec 23, 2024
…as a ChatInterface (#10222)

* changes

* add changeset

* add changeset

* Update gradio/external.py

Co-authored-by: Abubakar Abid <[email protected]>

* changes

* changes

* Update guides/05_chatbots/01_creating-a-chatbot-fast.md

Co-authored-by: Abubakar Abid <[email protected]>

* changes

---------

Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: gradio-pr-bot <[email protected]>
Co-authored-by: Abubakar Abid <[email protected]>
freddyaboulton added a commit that referenced this pull request Dec 23, 2024
* update code

* modify imports

* fix

* update notebook

* gr.load_chat: Allow loading any openai-compatible server immediately as a ChatInterface (#10222)

* changes

* add changeset

* add changeset

* Update gradio/external.py

Co-authored-by: Abubakar Abid <[email protected]>

* changes

* changes

* Update guides/05_chatbots/01_creating-a-chatbot-fast.md

Co-authored-by: Abubakar Abid <[email protected]>

* changes

---------

Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: gradio-pr-bot <[email protected]>
Co-authored-by: Abubakar Abid <[email protected]>

* Allow editing chatbot messages (#10203)

* changes

* add changeset

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* Update gradio/events.py

Co-authored-by: Abubakar Abid <[email protected]>

* Update gradio/components/chatbot.py

Co-authored-by: Abubakar Abid <[email protected]>

* changes

---------

Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: gradio-pr-bot <[email protected]>
Co-authored-by: Abubakar Abid <[email protected]>

* Update Guides related to deploying Gradio chatbots to Discord, Slack, and website widgets (#10221)

* changes

* changes

* update

* chat history

* add changeset

* changes

* add changeset

* changes

* guide

* changes

* changes

* changes

* guide

* add images

* slack guide

* changes

* format

* add changeset

* finish up slack

* changes

* improve js guide

* update

* changes

* script

* changes

* changes

* add changeset

* Update guides/05_chatbots/01_creating-a-chatbot-fast.md

Co-authored-by: Ali Abdalla <[email protected]>

* Update guides/05_chatbots/01_creating-a-chatbot-fast.md

Co-authored-by: Ali Abdalla <[email protected]>

* Update guides/05_chatbots/06_creating-a-discord-bot-from-a-gradio-app.md

Co-authored-by: Ali Abdalla <[email protected]>

* Update guides/05_chatbots/08_creating-a-website-widget-from-a-gradio-chatbot.md

Co-authored-by: Ali Abdalla <[email protected]>

* Update guides/05_chatbots/08_creating-a-website-widget-from-a-gradio-chatbot.md

Co-authored-by: Ali Abdalla <[email protected]>

* gradio

* cta

---------

Co-authored-by: gradio-pr-bot <[email protected]>
Co-authored-by: Ali Abdalla <[email protected]>

* Allow editable ChatInterface (#10229)

* changes

* add changeset

* changes

* changes

* changes

---------

Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: gradio-pr-bot <[email protected]>

* Fix typing for components in `gr.Interface` and docstring in `image.py` (#10235)

* changes

* add changeset

* changes

* changes

* change

* add changeset

* image.py

* revert msg

---------

Co-authored-by: gradio-pr-bot <[email protected]>

* Lite: Capture stdout and stderr from the main thread (#9984)

* Add stdout and stderr events

* add changeset

* Refactoring

* Format App.tsx

* add changeset

* Add python-error event to capture Python errors occurring in the running event loop after the initial app launch

* Fix <ErrorDisplay />'s close button

* Fix <ErrorDisplay />

* Propagate python-error and initialization-error events to the controller

* Add init-code|file-run-error events

---------

Co-authored-by: gradio-pr-bot <[email protected]>

* use chat interface

---------

Co-authored-by: Abubakar Abid <[email protected]>
Co-authored-by: aliabid94 <[email protected]>
Co-authored-by: Ali Abid <[email protected]>
Co-authored-by: gradio-pr-bot <[email protected]>
Co-authored-by: Ali Abdalla <[email protected]>
Co-authored-by: Yuichiro Tachibana (Tsuchiya) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants