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
55 stars 11 forks source link

400 ERROR when used on Azure. Localhost is fine #28

Closed lunar-safari closed 4 months ago

lunar-safari commented 4 months ago

I've built an app that uses the Gemini AI api, and it works great locally on my machine on localhost.

When I publish the app to Azure I keep getting 400 errors when my code hits the AI

System.AggregateException: One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()at Mscc.GenerativeAI.GenerativeModel.GenerateContent(GenerateContentRequest request)at Mscc.GenerativeAI.GenerativeModel.GenerateContent(String prompt, GenerationConfig generationConfig, List1 safetySettings, List1 tools, ToolConfig toolConfig)

My code is real simple. It fails on the simple example

     string apiKey = "blah blah";
     var prompt = "Write a story about a magic backpack.";
     var googleAI = new GoogleAI(apiKey: apiKey);
     var model = googleAI.GenerativeModel(model: Model.Gemini15Flash);
     var response = model.GenerateContent(prompt).Result;
     Console.WriteLine(response.Text);

In Azure, I've set the key to 'unrestricted' and it still fails.

image

Is there a setting I need to change on Azure? Or the Google API settings?

I have billing enabled for the API.

Thanks

jochenkirstaetter commented 3 months ago

Hello @lunar-safari

How did you solve this issue? Apologies for not responding to it earlier.

Regards, JoKi