Debug School

rakesh kumar
rakesh kumar

Posted on

InvalidRequestError at chatgpt '0' is not of type 'integer' - 'max_tokens' in django

Error

InvalidRequestError at /chatgpt/
'0' is not of type 'integer' - 'max_tokens'
Request Method: POST
Request URL:    http://localhost:8000/chatgpt/
Django Version: 4.1.9
Exception Type: InvalidRequestError
Exception Value:    
'0' is not of type 'integer' - 'max_tokens'
Enter fullscreen mode Exit fullscreen mode

Image description

my code is
dynamic_max_tokens = request.POST.get('max_tokens')

dynamic_top_p = request.POST.get('top_p')
dynamic_temperature = request.POST.get('temperature')
dynamic_modal = request.POST.get('modal')
dynamic_frequency_penalty = request.POST.get('frequency_penalty')
dynamic_presence_penalty = request.POST.get('presence_penalty')

        # max_tokens = int(dynamic_max_tokens) if dynamic_max_tokens and dynamic_max_tokens != '0' else 100
        max_tokens = dynamic_max_tokens if dynamic_max_tokens is not None else 0.5
Enter fullscreen mode Exit fullscreen mode

Solution

max_tokens = int(dynamic_max_tokens) if dynamic_max_tokens is not None else 0.5

==================or===================

max_tokens = int(dynamic_max_tokens) if dynamic_max_tokens and dynamic_max_tokens != '0' else 100 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)