zylon-ai / private-gpt

Interact with your documents using the power of GPT, 100% privately, no data leaks
https://privategpt.dev
Apache License 2.0
53.64k stars 7.21k forks source link

[BUG] UI keeps track of only the first 20 messages in the chat history #2053

Open rohans30 opened 1 month ago

rohans30 commented 1 month ago

Pre-check

Description

def build_history() -> list[ChatMessage]:`
            history_messages: list[ChatMessage] = []

            for interaction in history:
                history_messages.append(
                    ChatMessage(content=interaction[0], role=MessageRole.USER)
                )
                if len(interaction) > 1 and interaction[1] is not None:
                    history_messages.append(
                        ChatMessage(
                            # Remove from history content the Sources information
                            content=interaction[1].split(SOURCES_SEPARATOR)[0],
                            role=MessageRole.ASSISTANT,
                        )
                    )

            # max 20 messages to try to avoid context overflow
            return history_messages[:20]

This last line where history_message is being spliced with [:20] doesn't make sense because this is grabbing the first 20 messages in the chat history. So if the chat continues longer than 20 messages, then nothing will be added to the chat history. I think this should be changed to [-20:] instead to grab the last 20 messages instead of the first 20.

Steps to Reproduce

Use PrivateGPT UI normally

Expected Behavior

Chat history should comprise of last 20 messages

Actual Behavior

Chat history only tracks first 20 messages

Environment

N/A

Additional Information

No response

Version

No response

Setup Checklist

NVIDIA GPU Setup Checklist

jaluma commented 1 month ago

Yep, totally right. Can you open a PR with this fix?