openai-java icon indicating copy to clipboard operation
openai-java copied to clipboard

Maybe Proxy could be set due to Communication issues

Open dylanZk1 opened this issue 2 years ago • 2 comments

dylanZk1 avatar Mar 17 '23 13:03 dylanZk1

There is a new feature recently that does support using a proxy. There is an example in the README that works. Please make sure you are on the latest version, give it a try, & please report any issues here.

https://github.com/TheoKanning/openai-java/blob/832307d18742b94d480dedfdb69af6d5fa309d75/README.md

Adding a Proxy

To use a proxy, modify the OkHttp client as shown below:

ObjectMapper mapper = defaultObjectMapper();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
OkHttpClient client = defaultClient(token, timeout)
        .newBuilder()
        .proxy(proxy)
        .build();
Retrofit retrofit = defaultRetrofit(client, mapper);
OpenAiApi api = retrofit.create(OpenAiApi.class);
OpenAiService service = new OpenAiService(api);

cryptoapebot avatar Mar 17 '23 13:03 cryptoapebot

Thank you. I've noticed that just after I sent it. However, I realize that maybe adding one param in default buildApi (openAiService) to choose whether Proxy should be used can be better if users only wanna the default easy function call.

Just my opinion.

dylanZk1 avatar Mar 17 '23 16:03 dylanZk1

Glad you got this working :+1:

I don't know about your exact use case, but most people use a proxy to get around OpenAI's restrictions so I don't feel comfortable making it any easier

TheoKanning avatar Apr 01 '23 19:04 TheoKanning