Skip to content

adds "Branch here" functionality as footer-button #6967

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

Merged
merged 11 commits into from
May 20, 2025

Conversation

Madrawn
Copy link
Contributor

@Madrawn Madrawn commented May 10, 2025

This simply allows, in addition, branching at a specific assistant response by adding a new icon under each response.

branch

  • UI & HTML:
    • Grouped message action buttons (copy, regenerate, etc.) into a new .message-actions div for better organization and styling.
    • Added a "Branch here" button with a new SVG icon to each assistant/bot message.
    • Assistant/bot messages now include a data-index attribute.
  • JavaScript:
    • Implemented branchHere(element) function that, when a "Branch here" button is clicked:
      • Retrieves the data-index of the message.
      • Populates a hidden branch_index Gradio input field with this index.
      • Programmatically clicks the main "Branch" button.
  • Backend (Python):
    • The handle_branch_chat_click function in modules/chat.py now:
      • Accepts a branch_index from the state.
      • If branch_index is provided (not -1), it truncates the current chat history up to (and including) that index before creating the new branched chat.
      • Resets branch_index to -1 after branching.
    • Added branch_index to the Gradio interface state and input elements.

Checklist:

oobabooga and others added 8 commits February 14, 2025 23:25
-   **UI & HTML:**
    -   Grouped message action buttons (copy, regenerate, etc.) into a new `.message-actions` div for better organization and styling.
    -   Added a "Branch here" button with a new SVG icon to each assistant/bot message.
    -   Assistant/bot messages now include a `data-index` attribute.
-   **JavaScript:**
    -   Implemented `branchHere(element)` function that, when a "Branch here" button is clicked:
        -   Retrieves the `data-index` of the message.
        -   Populates a hidden `branch_index` Gradio input field with this index.
        -   Programmatically clicks the main "Branch" button.
-   **Backend (Python):**
    -   The `handle_branch_chat_click` function in `modules/chat.py` now:
        -   Accepts a `branch_index` from the state.
        -   If `branch_index` is provided (not -1), it truncates the current chat history up to (and including) that index before creating the new branched chat.
        -   Resets `branch_index` to -1 after branching.
    -   Added `branch_index` to the Gradio interface state and input elements.
@oobabooga
Copy link
Owner

This change is excellent -- I haven't had time to review it properly yet but I'll merge it as soon as I confirm it works without issues. I see that you have made some nice code quality improvements as well.

On a side note, I think that a similar logic (plus some CSS styling) could be used to edit past messages and replies, similar to how the ChatGPT UI works. If you are interested in adding this in a future PR, that would be helpful.

@oobabooga oobabooga merged commit c25a381 into oobabooga:dev May 20, 2025
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