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

Error "Could not determine chat role" when sending too many messages to a single chat #633

Open
igrmk opened this issue Oct 12, 2024 · 6 comments · May be fixed by #634
Open

Error "Could not determine chat role" when sending too many messages to a single chat #633

igrmk opened this issue Oct 12, 2024 · 6 comments · May be fixed by #634

Comments

@igrmk
Copy link

igrmk commented Oct 12, 2024

I have an alias set up to use the predefined role using the --chat option.
For example, --chat improve is automatically added to every "Improve writing" query.

ShellGPT truncates the chat using the CHAT_CACHE_LENGTH option
each time it saves the conversation.

As a result, the first message eventually gets removed,
causing the tool to display "Could not determine chat role",
since the role is defined in that initial message.

To prevent this issue, the first message should likely never be truncated.

igrmk added a commit to igrmk/shell_gpt that referenced this issue Oct 12, 2024
igrmk added a commit to igrmk/shell_gpt that referenced this issue Oct 12, 2024
@DanijelDomazet
Copy link

I've also aliased the --chat option, and I have the same issue.

Could not determine chat role of "dd"

@tinmarino
Copy link

Hello @igrmk, thank you for raising the issue, I experiment the same behavior.
For me, it seems to happen when I interrupt the chat with Ctrl-C and try to start it again.

Screenshot from 2024-10-25 13-05-27

@matthewblott
Copy link

Ah, I see I have the same problem :-)

@EmVee381
Copy link

EmVee381 commented Feb 14, 2025

I'm not a Python developer, but purely through deductive reasoning, I think the problem is on this line.

json.dump(messages[-self.length :], file_path.open("w"))

And it is caused by how the cache is set up, as when the number of items from the end is taken, the first entry in the cache, which defines the initial role (e.g., system), is also deleted. Since the slice is taken from the end according to the number of items defined by the chat cache size, the role gets deleted. A possible solution could be either defining the role as "user" or fixing the code to something like:

        message_role_item = messages.pop(0)
        json.dump([message_role_item] + messages[-self.length :], file_path.open("w"))

@EmVee381
Copy link

#634 (comment)

@matthewblott
Copy link

matthewblott commented Feb 14, 2025

Thanks @EmVee381 👍

It doesn't look good that the previous PR to fix this submitted in October is still waiting approval 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants