Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

SocketTimeoutException with OpenAiService#createCompletion #5

Closed
Ugleh opened this issue Jul 5, 2021 · 8 comments
Closed

SocketTimeoutException with OpenAiService#createCompletion #5

Ugleh opened this issue Jul 5, 2021 · 8 comments

Comments

@Ugleh
Copy link

Ugleh commented Jul 5, 2021

Randomly, unbeknownst to me, I get a SocketTimeoutExeption during some executions for createCompletion. I don't know how to increase the connection timeout for OpenAiService and was wondering if I could get some advice, thanks.

@TheoKanning
Copy link
Owner

There's no way to modify anything within OpenAiService, so if you want to increase any timeouts, you'll have to make your own OkHttpClient and Retrofit instances. Just copy the OpenAiService constructor code and modify the OkHttpClient as shown here https://www.baeldung.com/okhttp-timeouts#read

@danielsawan
Copy link

I have the same problem. Is it possible to simply have a setTimeout() method somewhere in the api ?

@gbolcer
Copy link

gbolcer commented Jun 28, 2022

@TheoKanning Thank you for this toolkit. This is really useful.
If you can make the OpenAiApi public that would fix it or else just create a getter and setter for OpenAiApi api in OpenAiService?
I'm using the api-0.6.0.jar and cleint-0.6.0.jar so would prefer not to have to have another code copy if i could avoid it.

@gbolcer
Copy link

gbolcer commented Jun 28, 2022

Just more info. After switching to text-davinci-002, it takes more time than the default timeout about 60% of the time.

TheoKanning added a commit that referenced this issue Jun 29, 2022
If certain engines are timing out regularly, then OpenAiService needs a timeout parameter.
I also added a constructor that takes an OpenAiApi, and this will allow users to customize their api settings much more easily.

If we need more parameters later, I might add a builder for OpenAiService.

Based on feedback in #5
TheoKanning added a commit that referenced this issue Jun 29, 2022
If certain engines are timing out regularly, then OpenAiService needs a timeout parameter.
I also added a constructor that takes an OpenAiApi, and this will allow users to customize their api settings much more easily.

If we need more parameters later, I might add a builder for OpenAiService.

Based on feedback in #5
@gbolcer
Copy link

gbolcer commented Jun 29, 2022

I ended up just importing the project as a gradle project into eclipse and set the dependency. I still think it'd be useful to have a parameter or to be able to access the api object directly to set it, but my problem is solved.

Thank you again!

        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(new AuthenticationInterceptor(token))
                .connectionPool(new ConnectionPool(8, 42, TimeUnit.SECONDS))
                .connectTimeout(42, TimeUnit.SECONDS)
                .readTimeout(42, TimeUnit.SECONDS)
                .writeTimeout(42, TimeUnit.SECONDS)
                .build();

@TheoKanning
Copy link
Owner

@gbolcer you beat me to it haha. I just added a timeout option to fix this.

I also added much easier way to provide your own OpenAiApi in case you want to customize something else without copying the entire OpenAiService.

Version 0.7.0 with the changes will be available very soon

@TheoKanning
Copy link
Owner

Thank you all for pointing this out to me! Version 0.7.0 is live with the new timeout parameter, marking as closed 👍

@gbolcer
Copy link

gbolcer commented Jun 29, 2022

Again, kudos for the api. This is extremely useful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants