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

Add support for additional_outputs in gr.ChatInterface #7933

Open
chengyjonathan opened this issue Apr 4, 2024 · 5 comments
Open

Add support for additional_outputs in gr.ChatInterface #7933

chengyjonathan opened this issue Apr 4, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@chengyjonathan
Copy link

  • [yes] I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
I'm trying to setup a ChatInterface() Where I can get the output documents that were retrieved along with the response. Ie. if my input query fn outputs both a list of strings for the retrieved docs and a response str, I want to be able to send that list of retrieved docs to a different compoenent.

Describe the solution you'd like
Idk if this is easier than I think it is, but I'd appreciate a way to implement this (if this doesn't exist already). Where I can supply a fn that returns both a response and a list of documents

@abidlabs abidlabs changed the title RAGChatInterface() Add support for additional_outputs in ChatInterface Apr 4, 2024
@abidlabs abidlabs changed the title Add support for additional_outputs in ChatInterface Add support for additional_outputs in gr.ChatInterface Apr 4, 2024
@abidlabs
Copy link
Member

abidlabs commented Apr 4, 2024

Hi @chengyjonathan yes I think we could add support for additional_outputs in gr.ChatInterface similar to how we have additional_inputs. cc @dawoodkhan82

@abidlabs abidlabs added the enhancement New feature or request label Apr 4, 2024
@abidlabs
Copy link
Member

abidlabs commented Apr 5, 2024

Or alternatively we could support the gr.File component in gr.Chatbot cc @dawoodkhan82

@dawoodkhan82 dawoodkhan82 self-assigned this Apr 7, 2024
@justinzyw
Copy link

+1 currently I have to embed the additional outputs in the response itself.

@Balint-Batki
Copy link

This works for me (until a better option in gradio):

RAG_component = gr.Textbox()
# chatbot is a gr.Chatbot() component
chatbot.change(fn=update_RAG_component, inputs=[], outputs=[RAG_component])

The chatbot changes many times, but after the last change, the RAG_component shows the retrieved docs.
I have tried other EventListeners, but none of them worked for me.

A nicer solution requires some modifications in the source code, for example:

  1. A new member variable in the ChatInterface class:
self.state_id = Textbox("0", visible=False)
  1. Another submit_event, appended at the end:
...
.then(self._update_state, [self.state_id ], [self.state_id ])
  1. The update function:
def _update_state(self, state:Textbox):
        return Textbox(str(int(state)+1))

Then, an event listener can be set up, which only acts once after the response is generated:
chatinterface.state_id.change(fn=update_RAG_component, inputs=[], outputs=[RAG_component])

@taoari
Copy link

taoari commented Aug 29, 2024

+1 for this. It could be useful for a stateful chatbot.

E.g.

def bot_fn(message, history, session_state, <additional_inputs>):
    return bot_message, session_state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants