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

feat: added helpers for various exceptions including a prompt truncation error #151

Merged
merged 9 commits into from
Aug 13, 2024

Conversation

adubovik
Copy link
Collaborator

@adubovik adubovik commented Aug 9, 2024

Introduced error helpers for the prompt truncation procedure which is triggered by request.max_prompt_tokens parameter.

A corresponding code is introduced for such an error called truncate_prompt_error:

def _truncate_prompt_error(message: str, **kwargs) -> HTTPException:
    return invalid_request_error(
        code="truncate_prompt_error",
        param="max_prompt_tokens",
        message=message,
        **kwargs,
    )

Compare it with the error message thrown by OpenAI itself when context length is exceeded:

    {
        "message": "This model's maximum context length is 128000 tokens. However, your messages resulted in 458759 tokens. Please reduce the length of the messages.",
        "type": "invalid_request_error",
        "param": "messages",
        "code": "context_length_exceeded"
    }

@adubovik adubovik self-assigned this Aug 9, 2024
@adubovik adubovik changed the title feat: added helpers for typical errors feat: added helpers for various exceptions including a prompt truncation error Aug 9, 2024
@adubovik adubovik merged commit d6b32ad into development Aug 13, 2024
14 checks passed
@adubovik adubovik deleted the feat/added-helpers-for-errors branch August 13, 2024 09:57
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

Successfully merging this pull request may close these issues.

2 participants