Skip to content

[Feature]: Support ui.Chat history #1932

Open
@schloerke

Description

@schloerke

Category

UI Components

Scope

Major Feature

Problem

I'd like to have multiple chat histories similar to chat GPT.

I'd like to be able to restore and overwrite these chat values.

I'd like to be able to view other's (public) history and copy into mine.

Solution

Chat history data structure

  • Essential:
    • Chat ID (random)
    • Owner username (as provided by connect? localhost if locally run)
    • Message history
  • Nice to have
    • Summary title for chat
    • Public/private (for sharing)
    • Which model was most recently used?

ui.Chat enhancements:

  • .ui_history_browser(): Dynamic UI containing a select drop down of chats
  • .get_history(): Returns all chat history information
  • In .enable_history(), accept a class that inherits from ChatDatabase (described below)

Ex Express usage:

chat.enable_history(ChatLocalFiles)

with ui.sidebar():
    chat.ui_history_browser()

chat.ui()
class ChatDatabaseEntry(TypedDict):
    chat_history: Chat
    id: str
    title: str
    username: str


class ChatDatabase(abc):
    get_chats(username: str) -> list[ChatDatabaseEntry]:
        ...
    
    set_chat(username: str, chat: Chat, id: str | None, *, title: str, **kwargs: object) -> str:  # Return id
        ...

Alternatives (Optional)

  • Instead of ChatDataBase class, we could do everything through bookmarking. However, this will quickly blow up in that we'd need to save the whole chat history (100mb+) for every message. If two tabs are working at the same time, the first tab to save would be overwritten. We require a data structure that allows for parallel updates.

  • We could enhance session.bookmark to work with the browser's localstorage / indexDB. localstorage doesn't allow for much storage (~5 mb) while indexDB has a large amount (~80% of free disk space). Both solutions have eviction policies for when storage space runs out.

Example (Optional)

Impact (Optional)

No response

Contribution? (Optional)

Yes, I can implement (or help).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions