Closed sebastianbk closed 2 weeks ago
I was able to remediate this issue with the following code:
// Get access token
var credential = await GoogleCredential.GetApplicationDefaultAsync();
var token = await credential.UnderlyingCredential.GetAccessTokenForRequestAsync();
Environment.SetEnvironmentVariable("GOOGLE_ACCESS_TOKEN", token);
// Create model
var model = _vertexAi.GenerativeModel(Model.GeminiPro);
model.AccessToken = token;
Though, it's not ideal. Could you use the GoogleCredential
class instead of using the CLI?
I agreed that bundled with Google.Apis.Auth is a better solution.
Here is the current implementation:
Hello @sebastianbk
Thanks for reporting the issue.
Please see the additional package Mscc.GenerativeAI.Google
which uses the Google Client Libraries for .NET under the hood to handle the access token required to authenticate. It's a wrapper package for the main Mscc.GenerativeAI
package and it uses the GoogleCredential
class already.
That should solve the issue already. And I have to improve the README.md to refer to the second package better.
I'm going to look into this to see myself how this could be improved
Cheers, JoKi
PS: Are you using the latest package already? I added some improvements to avoid the exception... Anyways, going to check.
Hi, this has been improved and (hopefully) resolved in release v1.8.1
When deploying an app using this library to Google App Engine, the exception below is thrown.
This happens despite the fact that the application default credentials indeed are available and are being consumed without any issues by Google's own SDKs in .NET.