mscraftsman / generative-ai

Gemini AI SDK for .NET and ASP.NET Core enables developers to use Google's state-of-the-art generative AI models to build AI-powered features and applications.
https://mscraftsman.github.io/generative-ai/
Apache License 2.0
47 stars 8 forks source link

Discussion: Keep API interface consistent #3

Closed doggy8088 closed 5 months ago

doggy8088 commented 5 months ago

There are two types of Google Cloud Generative AI:

  1. Google AI Gemini API

    // Google AI with an API key
    var model = new GenerativeModel(apiKey: "your API key", model: Model.GeminiPro);
  2. Vertex AI Gemini API

    // Vertex AI with OAuth. Use `gcloud auth application-default print-access-token` to get the access token.
    var vertex = new VertexAI(projectId: projectId, region: region);
    var model = vertex.GenerativeModel(model: Model.Gemini10Pro);

What if we keep these two APIs consistent?

For example,

  1. Google AI Gemini API

    // Google AI with an API key
    var googleai = new GoogleAI(apiKey: "your API key");
    var model = googleai.GenerativeModel(model: Model.Gemini10Pro);
  2. Vertex AI Gemini API

    // Vertex AI with OAuth. Use `gcloud auth application-default print-access-token` to get the access token.
    var vertexai = new VertexAI(projectId: projectId, region: region);
    var model = vertexai.GenerativeModel(model: Model.Gemini10Pro);
jochenkirstaetter commented 5 months ago

Hi @doggy8088 ,

Thanks for the suggestion. That would be similar to the genai object available in the other SDKs. I didn't consider the abstraction of the Google AI. However, it can make sense to add this extra layer.

One of the issues I'm facing at the moment, is that "administrative" methods like ListModels, GetModel are at the wrong location. This might also be relevant for CreateTunedModel.

Also, take into consideration that GenerativeModel can work autonomously to detect the targetted API based on environmental constraints, like using .env and envVars.

using Mscc.GenerativeAI;
var model = new GenerativeModel();

As described in the README: Using Environment variables

Again, thanks for the suggestion. This is helpful to clear my own thoughts.

jochenkirstaetter commented 5 months ago

Hi @doggy8088

I added this request to version 0.8.4. See commit: https://github.com/mscraftsman/generative-ai/commit/16403cec663f2ba7507c8c2177a05f3b073324b4

I hope that it's more consistent now. Eventually, I have to make further changes regarding Google AI using OAuth / ADC authentication. Currently, there is a null check of ApiKey in the method.

doggy8088 commented 5 months ago

Just a reminder that the README.md should be updated as well.