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

Endpoint issue with Gemini Pro 1.5 and Gemini Flash Support #5437

Closed
5 tasks done
stuntnmore opened this issue May 17, 2024 · 12 comments
Closed
5 tasks done

Endpoint issue with Gemini Pro 1.5 and Gemini Flash Support #5437

stuntnmore opened this issue May 17, 2024 · 12 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@stuntnmore
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

the version should be able to be set from configuration, right now google apis have 2 versions, one called v1, and another called v1beta, the difference is on v1 some of the newest gemini models dont exist on it but on v1beta it does, so being able to set this would allow for more model support of newer generation gemini releases

Error Message and Stack Trace (if applicable)

No response

Description

add the ability to set the google generative api version through config and if not set then default back to v1

System Info

langchain + google community libs

@stuntnmore
Copy link
Author

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label May 17, 2024
@jeasonnow
Copy link
Contributor

this.apiVersion = fields?.apiVersion ?? this.apiVersion;

It seems that if you use fields.apiVersion, it will take effect. Would you like to try? @stuntnmore

@afirstenberg
Copy link
Contributor

If you're using any of the packages that use google-common (ie - @langchain/google-gauth, @langchain/google-webauth, @langchain/google-vertexai, or @langchain/google-vertexai-web) you should be able to include apiVersion as a configuration parameter. So something like this should work:

const model = new ChatGoogle({
  modelName: "gemini-1.5-flash-latest",
  apiVersion: "v1beta",
  platformType: "gai",
});

@yharaskrik
Copy link

Anyone have a working configuration using an API key? I tried what @afirstenberg suggested (although not with gai) but that did not work, I get

 [GoogleGenerativeAI Error]: Error fetching from https://generativeai.googleapis.com/v1/models/gemini-1.5-flash-latest:generateContent: [404 Not Found]

config:

    apiKey: process.env['API_KEY'],
    modelName: 'gemini-1.5-flash-latest',
    apiVersion: 'v1beta',

@afirstenberg
Copy link
Contributor

@yharaskrik - which package are you using?

What I described works for the packages I specified.
If you're using @langchain/google-genai (which it kinda looks like you are), you shouldn't need to set apiVersion, you just need to update to the latest version of the package.

@yharaskrik
Copy link

@yharaskrik - which package are you using?

What I described works for the packages I specified.
If you're using @langchain/google-genai (which it kinda looks like you are), you shouldn't need to set apiVersion, you just need to update to the latest version of the package.

Ya that's the one I'm using. I think I'm on the latest (since I just installed it today). I'll do some more debugging when I get home.

@stuntnmore
Copy link
Author

stuntnmore commented May 20, 2024

Just checked up langchain-google-genai and doesnt seem like theres a api version field there and just uses the constructor default of v1

apiVersion: this.apiVersion,

the fix is probably just adding

fields?.apiVersion?? this.apiVersion

@stuntnmore
Copy link
Author

opened a pr with change but probably needs more testing to see if its all okay
#5480

Just checked up langchain-google-genai and doesnt seem like theres a api version field there and just uses the constructor default of v1

apiVersion: this.apiVersion,

the fix is probably just adding

fields?.apiVersion?? this.apiVersion

@afirstenberg
Copy link
Contributor

This should already be in place:
#5115 - Which used the new library that defaults to v1beta
#5426 - Which added apiVersion

@afirstenberg
Copy link
Contributor

@bracesproul - Did we get a regression somewhere?

@yharaskrik
Copy link

Looks like was a regression it seems and a URL is wrong. This is working for me (obviously its a hack, I will see if I can open a PR with the real fix)

const baseUrl = 'https://generativelanguage.googleapis.com';
const version = 'v1beta';
const genAi = new ChatGoogleGenerativeAI({
    model: 'gemini-1.5-flash-latest',
    apiKey: process.env.GEMINI_KEY,
    apiVersion: version,
    maxRetries: 0,
    baseUrl,
});

(genAi as any).client.requestOptions.apiVersion = version;
(genAi as any).client.requestOptions.baseUrl = baseUrl;
(genAi as any).apiVersion = version;
(genAi as any).baseUrl = baseUrl;

@bracesproul
Copy link
Collaborator

This should be fixed by #5490 (@langchain/google-genai v0.0.15)

Please ping if you're still experiencing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants