generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

How to use proxy-based proxy clients on google.generativeai

Open Blues-star opened this issue 1 year ago • 2 comments

Description of the feature request:

In OpenAI's Python SDK, you can implement client-side proxying through the following operation https://github.com/openai/openai-python#configuring-the-http-client

import httpx
from openai import OpenAI

client = OpenAI(
    # Or use the `OPENAI_BASE_URL` env var
    base_url="http://my.test.server.example.com:8083",
    http_client=httpx.Client(
        proxies="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

I am very curious about how I should implement the above operation in google.generativeai sdk?

What problem are you trying to solve with this feature?

I want to avoid using the system-wide global proxy as much as possible to achieve the above functionality

Any other information you'd like to share?

No response

Blues-star avatar Jan 31 '24 03:01 Blues-star

It is for llamaindex, but I made it. https://github.com/HawkClaws/proxy_gemini

HawkClaws avatar Apr 30 '24 08:04 HawkClaws

没有找到prox的方法

tianlichunhong avatar Jun 21 '24 13:06 tianlichunhong

There are a couple of ways you can proxy with the SDK.

You can force the SDK to use HTTP traffic (it's gRPC by default) with genai.configure(..., transport="rest"), then the underlying requests will honour the typical environment variables - HTTP_PROXY=... or ALL_PROXY=... (note that they must be upper case).

If you have a fake endpoint or want to send the traffic to a different host directly, you can use genai.configure(client_options={'api_endpoint': 'path.to.my.domain'})

markmcd avatar Sep 10 '24 23:09 markmcd

If you have a fake endpoint or want to send the traffic to a different host directly, you can use genai.configure(client_options={'api_endpoint': 'path.to.my.domain'})

Are you saying that I can now use genai.configure to configure a reverse proxy for the Gemini API?

daiaji avatar Sep 14 '24 01:09 daiaji

Are you saying that I can now use genai.configure to configure a reverse proxy for the Gemini API?

It's not built specifically for reverse proxying, we use it for staging/preprod endpoints internally, but you do you :)

markmcd avatar Sep 16 '24 02:09 markmcd