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

Better handling of max tokens error #9

Open
bryanjtc opened this issue Jul 6, 2023 · 1 comment
Open

Better handling of max tokens error #9

bryanjtc opened this issue Jul 6, 2023 · 1 comment

Comments

@bryanjtc
Copy link

bryanjtc commented Jul 6, 2023

My pull request was a little bit too big for the request. I propose handling this error by adding the InvalidRequestError as a comment to the pull request. Although the error happened, the model generated a lot of bullet points. This points should be included in the pr in the case the max tokens error happens. Another suggested change is to send the text in chunks to avoid hitting the limit.

│ /home/runner/.local/lib/python3.10/site-packages/openai/api_requestor.py:687 │
│ in _interpret_response_line                                                  │
│                                                                              │
│   684 │   │   # to better handle the "error while streaming" case.           │
│   685 │   │   stream_error = stream and "error" in resp.data                 │
│   686 │   │   if stream_error or not 200 <= rcode < 300:                     │
│ ❱ 687 │   │   │   raise self.handle_error_response(                          │
│   688 │   │   │   │   rbody, rcode, resp.data, rheaders, stream_error=stream │
│   689 │   │   │   )                                                          │
│   690 │   │   return resp                                                    │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │         data = {                                                         │ │
│ │                │   'error': {                                            │ │
│ │                │   │   'message': "This model's maximum context length   │ │
│ │                is 4097 tokens, however you requested 6505 t"+102,        │ │
│ │                │   │   'type': 'invalid_request_error',                  │ │
│ │                │   │   'param': None,                                    │ │
│ │                │   │   'code': None                                      │ │
│ │                │   }                                                     │ │
│ │                }                                                         │ │
│ │        rbody = '{\n  "error": {\n    "message": "This model\'s maximum   │ │
│ │                context length is 4097 token'+215                         │ │
│ │        rcode = 400                                                       │ │
│ │         resp = <openai.openai_response.OpenAIResponse object at          │ │
│ │                0x7f1ce43086d0>                                           │ │
│ │     rheaders = {'Date': 'Thu, 06 Jul 2023 06:33:38 GMT', 'Content-Type': │ │
│ │                'application/json', 'Content-Length': '295',              │ │
│ │                'Connection': 'keep-alive',                               │ │
│ │                'access-control-allow-origin': '*', 'openai-model':       │ │
│ │                'text-davinci-003', 'openai-organization':                │ │
│ │                'micros-0zhpga', 'openai-processing-ms': '227',           │ │
│ │                'openai-version': '2020-10-01',                           │ │
│ │                'strict-transport-security': 'max-age=15724800;           │ │
│ │                includeSubDomains', 'x-ratelimit-limit-requests': '3000', │ │
│ │                'x-ratelimit-limit-tokens': '250000',                     │ │
│ │                'x-ratelimit-remaining-requests': '2999',                 │ │
│ │                'x-ratelimit-remaining-tokens': '248[975](https://github.com/paymesoft/PayMeSoftWeb/actions/runs/5472276542/jobs/9964282465?pr=143#step:3:980)',                 │ │
│ │                'x-ratelimit-reset-requests': '20ms',                     │ │
│ │                'x-ratelimit-reset-tokens': '245ms', 'x-request-id':      │ │
│ │                'aeca0586a2d4ff8604a152b2554c5d07', 'CF-Cache-Status':    │ │
│ │                'DYNAMIC', 'Server': 'cloudflare', 'CF-RAY':              │ │
│ │                '7e25d13f2dd4065a-IAD', 'alt-svc': 'h3=":443"; ma=86400'} │ │
│ │         self = <openai.api_requestor.APIRequestor object at              │ │
│ │                0x7f1ce430a020>                                           │ │
│ │       stream = False                                                     │ │
│ │ stream_error = False                                                     │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────╯
InvalidRequestError: This model's maximum context length is 4097 tokens, however
you requested 6505 tokens (5481 in your prompt; 1024 for the completion). Please
reduce your prompt; or completion length.
@cosydney
Copy link

+1, I submitted a 90,000 line PR and maxed out on my GPT limits to 30$

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