openai-java
openai-java copied to clipboard
Maybe Proxy could be set due to Communication issues
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);
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.
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