gunpal5 / Google_GenerativeAI

Unofficial C# Google Generative AI SDK (Google Gemini) with function calls support
MIT License
34 stars 4 forks source link

Proxy support for supported region #4

Closed aadi1295 closed 6 months ago

aadi1295 commented 6 months ago

Hello, Thank you for this SDK. It's working fine locally as Gemini API support my local region. However on server deployment it is giving me this error. My server is in Netherlands and according to this https://ai.google.dev/available_regions#available_regions Netherlands is not supported. Can you please add functionality to use proxy so that it can use supported region. Thank you again.

{
  "error": {
    "code": 400,
    "message": "User location is not supported for the API use.",
    "status": "FAILED_PRECONDITION"
  }
}
gunpal5 commented 6 months ago

I would suggest to move server to any supported region: https://ai.google.dev/available_regions

Proxy would not be a reliable solution.

If you still want to use proxy, then just initialize a HttpClient instance with Proxy and pass it to the model:

var handler = new HttpClientHandler()
{
    Proxy = new WebProxy("IP:PORT")
    {
        Credentials = new NetworkCredential("UserName","Password")
    }    
};
var httpClient = new HttpClient(handler);

var model = new GenerativeModel(apiKey,client:httpClient);
//var model = new GeminiProModel(apiKey, client: httpClient)
//var visionModel = new GeminiProVision(apiKey, client: httpClient);