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

Negative max_tokens value #11

Open
chew-z opened this issue Aug 12, 2024 · 1 comment
Open

Negative max_tokens value #11

chew-z opened this issue Aug 12, 2024 · 1 comment

Comments

@chew-z
Copy link

chew-z commented Aug 12, 2024

I am getting negative max tokens in AI call.. Some small bug probably...

2024-08-12 09:54:03,183 - ERROR - An error occurred while processing a chunk: Error code: 400 - {'error': {'message': "Invalid 'max_tokens': integer below minimum value. Expected a value >= 1, but got -1971 instead.", 'type': 'invalid_request_error', 'param': 'max_tokens', 'code': 'integer_below_min_value'}}
2024-08-12 09:54:03,420 - ERROR - An error occurred while processing a chunk: Error code: 400 - {'error': {'message': "Invalid 'max_tokens': integer below minimum value. Expected a value >= 1, but got -1971 instead.", 'type': 'invalid_request_error', 'param': 'max_tokens', 'code': 'integer_below_min_value'}}
@GuoMonth
Copy link

I encountered the same error.

I found that problems would occur when I went to this code branch.

if adjusted_max_tokens <= 0:

I think the error is caused by the logic of this code.

async def generate_completion_from_openai(
    prompt: str, max_tokens: int = 5000
) -> Optional[str]:
...
adjusted_max_tokens = min(
        max_tokens, 4096 - prompt_tokens - TOKEN_BUFFER
    )
...

response = await openai_client.chat.completions.create(
                    model=OPENAI_COMPLETION_MODEL,
                    messages=[{"role": "user", "content": chunk}],
                    max_tokens=adjusted_max_tokens, # there error
                    temperature=0.7,
                )
...

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