Skip to content

Python: How to reset chat session? #1589

@ShovingLeopard

Description

@ShovingLeopard

Issue you'd like to raise.

I have create a Gradio driven interface to GPT4All but I am having a problem trying to work out if it is possible to reset the chat session when the user hits "clear" - which resets the callback's history List argument to zero length.

I have a continuous history working using the Python with context as per the examples:

with model.chat_session():

  def get_chat_response(message: str, history: list) -> str:
    if (len(history) == 0):
      print("how do i remove the chat history here")
    result = ""
    if (streaming):
      for token in model.generate(prompt=message, 
                              temp=0, 
                              max_tokens=4000, 
                              streaming=True):
        result += token
        yield result
    else:
      return model.generate(prompt=message, 
                            temp=0, 
                            max_tokens=4000)

  if (streaming):
    gr.ChatInterface(get_chat_response, chatbot=gr.Chatbot(height=1000)).queue().launch()
  else:
    gr.ChatInterface(get_chat_response, chatbot=gr.Chatbot(height=1000)).launch()

If I put the 'with model.chat_session()' within the callback it of course resets the chat session every prompt which is not desired.
I have also tried running model.chat_session() without using the context and this just produces #s as output tokens as the result.

Suggestion:

Add a function to reset the chat history within a session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    python-bindingsgpt4all-bindings Python specific issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions