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

roles must alternate between "user" and "assistant" error and rate limit #19

Closed
kpoxo6op opened this issue Jun 29, 2024 · 2 comments
Closed

Comments

@kpoxo6op
Copy link

Hey I have experienced #18 too and I can reproduce it using the latest anthropic-sdk-python v0.30.0.

I have a suspicion that hitting the rate limit may cause 'found multiple "user" roles' error.

Reproducing the issue involves hitting the rate limit so it can be "resolved" magically. It also make it hard to debug and reproduce as we may hit the limit at arbitrary time.

Here is my closest attempt. I have hit the rate limit already, so the first message is rate_limit_error.

You: Create a new Python project structure for a web application
Error calling Claude API: Error code: 429 - {'type': 'error', 'error': {'type': 'rate_limit_error', 'message': 'Number of request tokens has exceeded your daily rate limit (https://docs.anthropic.com/en/api/rate-limits); see the response headers for current usage. Please reduce the prompt length or the maximum tokens requested, or try again later. You may also contact sales at https://www.anthropic.com/contact-sales to discuss your options for a rate limit increase.'}}
I'm sorry, there was an error communicating with the AI. Please try again.
Continuation iteration 1 completed.
Press Ctrl+C to exit automode.
Error calling Claude API: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row'}}
I'm sorry, there was an error communicating with the AI. Please try again.
Continuation iteration 2 completed.
Press Ctrl+C to exit automode.
Error calling Claude API: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row'}}
I'm sorry, there was an error communicating with the AI. Please try again.
Continuation iteration 3 completed.
Press Ctrl+C to exit automode. 

Replaced Sonnet with Haiku to work around the rate limit and tried again - everything worked fine:

python3 main.py
Welcome to the claude-3-haiku-20240307 Engineer Chat with Image Support!
Type 'exit' to end the conversation.
Type 'image' to include an image in your message.
Type 'automode [number]' to enter Autonomous mode with a specific number of iterations.
While in automode, press Ctrl+C at any time to exit the automode to return to regular chat.

You: automode 3
Entering automode with 3 iterations. Press Ctrl+C to exit automode at any time.
Press Ctrl+C at any time to exit the automode loop.

You: Create a new Python project structure for a web application

Claude: Okay, let's create a new Python project structure for a web application. Here's what I'll do:

<thinking>
To create a new Python project structure for a web application, I will use the create_folder and create_file tools. The required parameters are:
- path (string): The path where the folder/file should be created
The optional parameter is:
- content (string): The initial content of the file (only for create_file)

I have all the required information to complete this request, so I can proceed with the tool calls.
</thinking>

Tool Used: create_folder
Tool Input: {'path': 'my-web-app'}
Tool Result: Folder created: my-web-app

Claude: <thinking>
To create a Python project structure for a web application, I will need to create the following folders and files:

1. Root folder: 'my-web-app'
2. Subfolders:
   - 'app': Contains the main application code
   - 'templates': Contains HTML templates for the web pages
   - 'static': Contains static files like CSS, JavaScript, and images
   - 'tests': Contains unit tests for the application
3. Files:
   - 'app/__init__.py': This makes the 'app' folder a Python module
   - 'app/main.py': The main entry point of the application
   - 'requirements.txt': Lists the required Python packages for the project
   - 'README.md': Provides information about the project
</thinking>
Okay, let's create a new Python project structure for a web application. Here's what I'll do:

<thinking>
To create a new Python project structure for a web application, I will use the create_folder and create_file tools. The required parameters are:
- path (string): The path where the folder/file should be created
The optional parameter is:
- content (string): The initial content of the file (only for create_file)

I have all the required information to complete this request, so I can proceed with the tool calls.
</thinking><thinking>
To create a Python project structure for a web application, I will need to create the following folders and files:

1. Root folder: 'my-web-app'
2. Subfolders:
   - 'app': Contains the main application code
   - 'templates': Contains HTML templates for the web pages
   - 'static': Contains static files like CSS, JavaScript, and images
   - 'tests': Contains unit tests for the application
3. Files:
   - 'app/__init__.py': This makes the 'app' folder a Python module
   - 'app/main.py': The main entry point of the application
   - 'requirements.txt': Lists the required Python packages for the project
   - 'README.md': Provides information about the project
</thinking>
Continuation iteration 1 completed.
Press Ctrl+C to exit automode.

Claude: Okay, let's continue building the Python web application project structure.

Tool Used: create_folder
Tool Input: {'path': 'my-web-app/app'}
Tool Result: Folder created: my-web-app/app
Okay, let's continue building the Python web application project structure.
Continuation iteration 2 completed.
Press Ctrl+C to exit automode.

Tool Used: create_folder
Tool Input: {'path': 'my-web-app/templates'}
Tool Result: Folder created: my-web-app/templates

Claude: I've created the 'templates' folder within the 'my-web-app' root directory.
I've created the 'templates' folder within the 'my-web-app' root directory.
Continuation iteration 3 completed.
Press Ctrl+C to exit automode.
Max iterations reached. Exiting automode.
Exited automode. Returning to regular chat.

switching back to the rate limited Sonnet:

python3 main.py
Welcome to the Claude-3.5-Sonnet Engineer Chat with Image Support!
Type 'exit' to end the conversation.
Type 'image' to include an image in your message.
Type 'automode [number]' to enter Autonomous mode with a specific number of iterations.
While in automode, press Ctrl+C at any time to exit the automode to return to regular chat.

You: automode
Entering automode with 25 iterations. Press Ctrl+C to exit automode at any time.
Press Ctrl+C at any time to exit the automode loop.

You: create python web app for reporting on how many weeks Engineers were on-call this year in PagerDuty
Error calling Claude API: Error code: 429 - {'type': 'error', 'error': {'type': 'rate_limit_error', 'message': 'Number of request tokens has exceeded your daily rate limit (https://docs.anthropic.com/en/api/rate-limits); see the response headers for current usage. Please reduce the prompt length or the maximum tokens requested, or try again later. You may also contact sales at https://www.anthropic.com/contact-sales to discuss your options for a rate limit increase.'}}
I'm sorry, there was an error communicating with the AI. Please try again.
Continuation iteration 1 completed.
Press Ctrl+C to exit automode.
Error calling Claude API: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row'}}
I'm sorry, there was an error communicating with the AI. Please try again.
Continuation iteration 2 completed.
Press Ctrl+C to exit automode.
Error calling Claude API: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row'}}
I'm sorry, there was an error communicating with the AI. Please try again.
@Doriandarko
Copy link
Owner

Update your Anthropic package

@kpoxo6op
Copy link
Author

Looks like I removed pip output accidentally, I am using v0.30.0 https://pypi.org/project/anthropic/

Which version do I need to update to?

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