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

Add too many tokens errors and token-counting APIs #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

domenic
Copy link
Collaborator

@domenic domenic commented Jan 22, 2025

Closes #5.


Preview | Diff

domenic added a commit to webmachinelearning/prompt-api that referenced this pull request Jan 23, 2025
This is mostly to align with webmachinelearning/writing-assistance-apis#31:

* Use TooManyTokensError when appropriate, instead of a "QuotaExceededError" DOMException.
* Rename tokensLeft/tokensSoFar to tokensAvailable/tokenCount.
* Rename countPromptTokens() to countTokens().
* Remove maxTokens.
* Rename "contextoverflow" to "overflow", since the vocabulary "context" is not used elsewhere in the API and there's only one relevant type of overflow for the session.

It's possible that the inputs given for summarizing and rewriting might be too large for the underlying machine learning model to handle. The same can even be the case for strings that are usually smaller, such as the writing task for the writer API, or the context given to all APIs.

Whenever any API call fails due to too-large input, it is rejected with a `TooManyTokensError`. This is a new type of exception, which subclasses `DOMException`, and has the following additional properties:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to generalize the terminology here for other situations where input size could exceed a limit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's probably a good idea. That might change my take on the naming for tokensAvailable to follow that new model, hmm. Like if we choose quota for the property of the exception, then maybe it should be tokenQuota.

I posted whatwg/webidl#1463.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed better idea at whatwg/webidl#1465 . This PR is on hold until we have agreement on that front.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ways of telling by how much a too-large input is too large
2 participants