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

Application Default Credentials (ADC) has been loaded automatically even I use API Key auth. #9

Closed
doggy8088 opened this issue Mar 26, 2024 · 5 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@doggy8088
Copy link
Contributor

doggy8088 commented Mar 26, 2024

When I'm using a API Key authentication on Google AI Gemini API, the library still load my ADC automatically.

This might lead some issues. (Maybe) I'm not sure.

image

Here is my test code:

async Task Main()
{
	var model = new GenerativeModel(apiKey: Util.GetPassword("GEMINI_API_KEY"), model: Model.GeminiPro);

	var prompt = "I love Taipei. Give me a 15 words summary about it.";
	
	model.Uncapsulate().Dump();

	var response = await model.GenerateContent(prompt);

	response.Dump();
}

LINQPad Query: https://share.linqpad.net/ol86v9he.linq

@jochenkirstaetter jochenkirstaetter added bug Something isn't working enhancement New feature or request labels Mar 26, 2024
@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Mar 26, 2024

Yes, the application default credentials (ADC) are currently loaded in the default constructor. However, there is no AccessToken requested when using an API key. In case that you're using the envVar GOOGLE_ACCESS_TOKEN its value gets loaded but not necessarily refreshed or used to make the API call..

It's a bit of a small culprit given that Google AI supports both API key and OAuth/ADC whereas Vertex AI works with OAuth/ADC only.

In general, I thought that the three constructors should handle it sufficiently. Following your suggestion to introduce a GoogleAI type it shall be even more clear. For future releases, the currently public constructor accepting apiKey should be internal and closing access to it. This means that the expected way would be as you suggested.

using Mscc.GenerativeAI;
// Google AI with an API key
var googleAI = new GoogleAI(apiKey: "your API key");
var model = googleAI.GenerativeModel(model: Model.GeminiPro);

// Original approach, still valid. Is going to disappear...
// var model = new GenerativeModel(apiKey: "your API key", model: Model.GeminiPro);

Sorry, although it has been implemented originally the other way I'm getting more and more accustomed to the newer approach of using the GoogleAI type to create the model object instead of public constructor.

What's your thought?

@jochenkirstaetter
Copy link
Contributor

Using this approach would open the doors to introduce an interface IGenerativeAI which is implemented by both VertexAI and GoogleAI classes. This should streamline the use of Gemini across both API endpoints.

@jochenkirstaetter jochenkirstaetter self-assigned this Mar 26, 2024
@jochenkirstaetter
Copy link
Contributor

The interface IGenerativeAI has been added in release 0.9.1

@doggy8088
Copy link
Contributor Author

Sorry, although it has been implemented originally the other way I'm getting more and more accustomed to the newer approach of using the GoogleAI type to create the model object instead of public constructor.

Support for newer approach is absolutely fine for me. There is no need to keep "backward-compatibility". It because there are almost no one using this library. It probably only less than 10 people. ha .. 😅

jochenkirstaetter added a commit that referenced this issue Oct 30, 2024
jochenkirstaetter added a commit that referenced this issue Oct 30, 2024
@jochenkirstaetter
Copy link
Contributor

Hi, this has been improved and (hopefully) resolved in release v1.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants