Open doggy8088 opened 4 months ago
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?
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.
The interface IGenerativeAI
has been added in release 0.9.1
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 .. 😅
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.
Here is my test code:
LINQPad Query: https://share.linqpad.net/ol86v9he.linq