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

chat: output context limit reached -> roles must alternate between \"user\" and \"assistant\", but found multiple \"assistant\" roles in a row"}}", further input doesn't work #11

Open
hashcacher opened this issue Aug 28, 2024 · 11 comments

Comments

@hashcacher
Copy link

A claude chat response seemed to reach the output context limit, so I asked it to continue, and I got:

Claude: Unknown Claude protocol output: "{"type":"error","error":{"type":"invalid_request_error","message":"messages: roles must alternate between \"user\" and \"assistant\", but found multiple \"assistant\" roles in a row"}}"

Now all my message result in this response. cx results in

Error detected while processing function <SNR>20_CancelClaudeResponse:
line    5:
E906: Not an open channel
Claude response cancelled.
Press ENTER or type command to continue

The only solution I can find is to restart vim

@hashcacher
Copy link
Author

Correction: if I delete the Claude Chat buffer and open a new one, it works again.

@hashcacher
Copy link
Author

Thank you for this plugin, by the way!

@pasky
Copy link
Owner

pasky commented Aug 28, 2024

You can also manually update whatever is at the end of the buffer to restore the alternating flow.

If you can share exactly how last few lines of the buffer look like, we can consider how to handle this better.

@hashcacher
Copy link
Author

Just encountered this again. This time I was focused on another buffer while Claude was outputting. It ended up appending You: to the buffer I was browsing instead of the Claude Chat buffer. And then the Chat stopped working. Here's a direct copy paste, starting with the end of the last Claude output:

(this is the end of claude's last output)
    Is there anything else you'd like me to adjust or explain regarding these mobile-friendly changes?
 (this is me trying to send another message)
    The buttons at the bottom are cut off
(I hit c-], claude's response:)
Claude: Unknown Claude protocol output: "{"type":"error","error":{"type":"invalid_request_error","message":"Your API request included an `assistant` message in the final position, which would pre-fill the `assistant` response. When using tools, pre-filling the `assistant` response is not supported."}}"
(I add a You:, trying to restore the  flow)
   You: The buttons at the bottom are cut off
Claude: Unknown Claude protocol output: "{"type":"error","error":{"type":"invalid_request_error","message":"messages: roles must alternate between \"user\" and \"assistant\", but found multiple \"assistant\" roles in a row"}}"

@pasky
Copy link
Owner

pasky commented Aug 28, 2024

Ah, interesting, so somehow "The buttons at the bottom are cut off" line is missing a "You:" prefix.

And I assume you reposted the line with the prefix rather than coming back to the previous line and adding the prefix there? So the dialog ended up with two Claude: lines in a row.

I think in the future it would be nice to do two things:

  1. don't prefix "Unknown protocol output" with "Claude:", less likely to break the alternation.
  2. check the proper alternation before sending and highlight the error in the buffer if detected

@hashcacher
Copy link
Author

hashcacher commented Aug 28, 2024

It seems to always happen when claude cuts itself off due to max output size. Here's another example, beginning with some cut off output from Claude:

                                  {values.map(value => (
                                    <label key={value} className="inline-flex items-center mr-4 mb

You:continue 
Claude: Unknown Claude protocol output: "{"type":"error","error":{"type":"invalid_request_error","message":"messages: final assistant content cannot end with trailing whitespace"}}"
You:continue
Claude: Unknown Claude protocol output: "{"type":"error","error":{"type":"invalid_request_error","message":"messages: roles must alternate between \"user\" and \"assistant\", but found multiple \"assistant\" roles in a row"}}"

@pasky
Copy link
Owner

pasky commented Aug 28, 2024

Wow that never happenned to me, interesting!

(PR would be welcome. Also just to be clear, is the workaround to fix the output in the buffer clear?)

P.S. you may want to increase the 2048 max_tokens limit

@hashcacher
Copy link
Author

Ah, interesting, so somehow "The buttons at the bottom are cut off" line is missing a "You:" prefix.

that's correct, as I had my cursor in another buffer when the output finished, so it dumped the You: there instead of the claude chat

@hashcacher
Copy link
Author

Wow that never happenned to me, interesting!

(PR would be welcome. Also just to be clear, is the workaround to fix the output in the buffer clear?)

P.S. you may want to increase the 2048 max_tokens limit

Thanks for the tip about the max_tokens limit. Yeah once it starts erroring, the only fix I've found is to delete the buffer.

@pasky
Copy link
Owner

pasky commented Aug 28, 2024

You don't need to delete the whole buffer, you can just edit the last lines of it as appropriate to fix the issue manually.

@hashcacher
Copy link
Author

hashcacher commented Aug 28, 2024

When the max token issue happens, I try to close the ` block and write You: continue but it doesn't work

   (the end of the last code claude was outputting)
               Save
                </button>
        ```

You:continue 
    
Claude: Unknown Claude protocol output: "{"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must contain non-whitespace text"}}"

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

No branches or pull requests

2 participants