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 GenerateContentRequest as an optional param to CountTokensRequest #148

Merged
merged 5 commits into from
May 31, 2024

Conversation

DellaBitta
Copy link
Collaborator

@DellaBitta DellaBitta commented May 22, 2024

Expand the model's countTokens method to alternatively accept a GenerateContentRequest.

Added integration and unit tests.

packages/main/types/requests.ts Show resolved Hide resolved
packages/main/src/requests/request-helpers.ts Outdated Show resolved Hide resolved
packages/main/src/requests/request-helpers.ts Outdated Show resolved Hide resolved
packages/main/types/requests.ts Show resolved Hide resolved
@DellaBitta DellaBitta requested a review from hsubox76 May 30, 2024 15:03
@DellaBitta DellaBitta marked this pull request as ready for review May 30, 2024 15:03
.changeset/dirty-wolves-sin.md Outdated Show resolved Hide resolved
@@ -157,7 +158,8 @@ export class GenerativeModel {
async countTokens(
request: CountTokensRequest | string | Array<string | Part>,
): Promise<CountTokensResponse> {
const formattedParams = formatGenerateContentInput(request);
const formattedParams = formatCountTokensInput(request, this.model);
// countTokens() appends the model to the CountTokensRequest proto.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this comment should be for the previous line? countTokens doesn't append anything. It uses the model param to build the request url.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It adds it to the request body, but I'll remove the comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

countTokens() doesn't, but formatCountTokensInput() does, right? That's why I think it would be best to attach it to the previous line? countTokens() just calls makeRequest() and returns response.json().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

countTokens() also adds it to the proto request object here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, that seems to have been there since initial commit but I can't remember why it was needed. I don't know if countTokens is special or if I forgot to remove the model there when I removed it from generateContent and the other methods, let me double check. If it's just left over from the beginning we should probably remove it to avoid unexpected behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this blocks this PR though.

@DellaBitta DellaBitta requested a review from hsubox76 May 30, 2024 19:49
@DellaBitta DellaBitta merged commit 83ec4ac into main May 31, 2024
4 checks passed
@DellaBitta DellaBitta deleted the ddb-counttoken-generatecontent branch May 31, 2024 14:00
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