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

Assigning a API_KEY using model.ApiKey is not working #20

Closed
doggy8088 opened this issue Mar 28, 2024 · 3 comments
Closed

Assigning a API_KEY using model.ApiKey is not working #20

doggy8088 opened this issue Mar 28, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@doggy8088
Copy link
Contributor

doggy8088 commented Mar 28, 2024

Here is my code. It's not working. It should be a bug.

void Main()
{
    var googleAI = new GoogleAI(apiKey: "WRONG_API_KEY");
    var model = googleAI.GenerativeModel(model: Model.Gemini10Pro001);
    model.ApiKey = Util.GetPassword("GEMINI_API_KEY");
    model.GenerateContent("Tell me 4 things about Taipei. Be short.").Dump();
}

image

I think bug is here:

image

You should able to replace a new key there.

@jochenkirstaetter
Copy link
Contributor

jochenkirstaetter commented Mar 29, 2024

Hi @doggy8088

Hm, that is a problematic area due to the DefaultRequestHeaders member. It can only be modified prior to the first request issued by the HttpClient. Then it is immutable and throws an exception. See field HttpClient._operationStarted.

void Main()
{
    var googleAI = new GoogleAI(apiKey: "WRONG_API_KEY");
    var model = googleAI.GenerativeModel(model: Model.Gemini10Pro001);
    model.GenerateContent("Tell me 4 things about Taipei. Be short.").Dump();

    // throws an exception!
    model.ApiKey = Util.GetPassword("GEMINI_API_KEY");
    model.GenerateContent("Tell me 4 things about Taipei. Be short.").Dump();
}

This member should rather be internal than public.
Same probably applies for member ProjectId.

@jochenkirstaetter jochenkirstaetter added the enhancement New feature or request label Mar 29, 2024
@jochenkirstaetter
Copy link
Contributor

Interesting...
Last time I ran into an exception, now not.

Fixed in next release.

@doggy8088
Copy link
Contributor Author

@jochenkirstaetter Awesome, pal! It works now. 👍

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

No branches or pull requests

2 participants