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

Allow users to choose API endpoint version #56

Merged
merged 3 commits into from
Mar 5, 2024
Merged

Allow users to choose API endpoint version #56

merged 3 commits into from
Mar 5, 2024

Conversation

hsubox76
Copy link
Collaborator

@hsubox76 hsubox76 commented Mar 4, 2024

Add an option to RequestOptions so that users can choose API version. Right now the options are "v1" (default) and "v1beta".

  • Added option
  • Updated docs
  • Fixed some integration tests

See design doc (Google internal link only) https://docs.google.com/document/d/17EccPH51QeayXPWdDx6Snz5NOLJXm4La41eEFyTXDz8/edit?tab=t.0#heading=h.ymlc40jj6ff0

Copy link

changeset-bot bot commented Mar 4, 2024

🦋 Changeset detected

Latest commit: e6af0be

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@google/generative-ai Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lahirumaramba lahirumaramba self-assigned this Mar 5, 2024
Copy link
Collaborator

@lahirumaramba lahirumaramba left a comment

Choose a reason for hiding this comment

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

Added two comments. LGTM thanks!

const chat = model.startChat({
generationConfig: {
maxOutputTokens: 100,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious, is there a reason to remove the max tokens limit here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, so this is a live backend test so it doesn't always come back with the same results so it's very loose in what it considers a success (any non-empty string). Lately, it will come back with nothing (empty string) if I set the token limit to 100, and I'm not sure any number guarantees something will come back, so I just removed it.

) {}
toString(): string {
let url = `${BASE_URL}/${API_VERSION}/${this.model}:${this.task}`;
const apiVersion = this.requestOptions?.apiVersion || DEFAULT_API_VERSION;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we validate this.requestOptions?.apiVersion to check if it is either v1 or v1beta?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I want to future-proof it so any version is allowed, so we don't have to update the SDK every time a new version becomes available on the backend.

@hsubox76 hsubox76 merged commit 932e1be into main Mar 5, 2024
3 checks passed
@hsubox76 hsubox76 deleted the ch-apiversion branch March 5, 2024 18:00
@lahirumaramba lahirumaramba linked an issue Mar 12, 2024 that may be closed by this pull request
@hsubox76 hsubox76 mentioned this pull request Mar 12, 2024
@@ -28,7 +28,7 @@ export async function countTokens(
params: CountTokensRequest,
requestOptions?: RequestOptions,
): Promise<CountTokensResponse> {
const url = new RequestUrl(model, Task.COUNT_TOKENS, apiKey, false);
const url = new RequestUrl(model, Task.COUNT_TOKENS, apiKey, false, {});

Choose a reason for hiding this comment

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

Shouldn't this be the requestOptions? Otherwise the version won't get put in the url correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're correct, opened an issue to fix this: #71

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.

Allow API_VERSION in the Configuration
3 participants