Skip to content

[chatgpt] Add configurable request timeout#20408

Open
abrenk wants to merge 1 commit intoopenhab:mainfrom
abrenk:chatgpt-timeout
Open

[chatgpt] Add configurable request timeout#20408
abrenk wants to merge 1 commit intoopenhab:mainfrom
abrenk:chatgpt-timeout

Conversation

@abrenk
Copy link
Member

@abrenk abrenk commented Mar 20, 2026

The previously hardcoded 10 second timeout is now configurable as a thing-level parameter (requestTimeout) with an optional per-channel override. A channel timeout of 0 falls back to the thing default. This allows longer timeouts for local LLMs (e.g. ollama) or reasoning models that require more processing time.

An example would be a rule that generates a weather report based on sensor data.

Fixes #20203 (although already closed, but without any changes).

A cherry-pick to the 5.1.x branch would be nice.

@abrenk abrenk added the enhancement An enhancement or new feature for an existing add-on label Mar 20, 2026
@abrenk abrenk requested a review from kaikreuzer as a code owner March 20, 2026 12:15
Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing this patch.
Besides these comments, could youalso add the parameter to the readme.md ?


public int maxTokens = 500;

public int requestTimeout = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would not expect this on the channelconfiguration as the PR describes this is on a per thing base.

Copy link
Member Author

@abrenk abrenk Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the PR description:

with an optional per-channel override.

The thing specifies the default value for all channels, but a channel can have its own.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes i see now. I would opt to make this a @Nullable and not default to 0

scheduler.execute(() -> {
try {
Request request = httpClient.newRequest(modelUrl).timeout(REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS)
Request request = httpClient.newRequest(modelUrl).timeout(DEFAULT_REQUEST_TIMEOUT_S, TimeUnit.SECONDS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not respect the timeout set to the thing configuration, but uses the hard coded default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one-time request for /v1/models which should complete in milliseconds. If you want, I can of course change this, but the thing-level timeout is primarily for the HLI completions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i understand, With the provided value it is fine, but it mixes the default for a user configuration parameter and a setting that can be seen as more infrastructural related. Anyway, choose what you want, i have no strong opinion on this, just want to make sure you know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file needs to be regenerated after other comments have been addressed.

Request request = httpClient.newRequest(apiUrl).method(HttpMethod.POST)
.timeout(REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS).header("Content-Type", "application/json")
.header("Authorization", "Bearer " + apiKey).content(new StringContentProvider(queryJson));
return sendPrompt(queryJson, config != null ? config.requestTimeout : DEFAULT_REQUEST_TIMEOUT_S);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case requesttimeout is 0, this will gives issues

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thing-types.xml specifies min="1".

Copy link
Contributor

@lsiepel lsiepel Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that does not enforce the value to be min="1" as we have file based / unmanaged configurations that can have any value, so a sanity check is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the pattern then? Throw an exception or use the default value and log a warning?

Copy link
Contributor

@lsiepel lsiepel Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually a binding verifies in the initialize method if all configuration parameters are valid. If not, the thing state is set accordingly.

<label>Request Timeout</label>
<description>Timeout in seconds for this channel. Overrides the thing-level timeout. Set to 0 to use the thing
default.</description>
<default>0</default>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<default>0</default>
<default>10</default>

It should match the default set in the configuration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The channel default is "0", i.e. to use the thing-level timeout value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here i would remove the default tag to not set any value and leave it null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

<default>1</default>
<advanced>true</advanced>
</parameter>
<parameter name="requestTimeout" type="integer" min="0">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A zero time-out makes no sense, or in many cases it is used as a signal to not set any timeout.

Suggested change
<parameter name="requestTimeout" type="integer" min="0">
<parameter name="requestTimeout" type="integer" min="1">

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly the case, as detailed in the <description>:

Set to 0 to use the thing default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not setting a timeout leaves it to the library, here it is set to the default time out. This is not a common pattern in openHAB and i would opt to reconsider this behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a consequence of using "0" as the value to mean "use config from thing", the http library is always called with an explicit timeout. But as discussed above I will change this to be nullable and then the minimum value can be 1.

The previously hardcoded 10 second timeout is now
configurable as a thing-level parameter (requestTimeout)
with an optional per-channel override. A channel timeout
of 0 falls back to the thing default. This allows longer
timeouts for local LLMs (e.g. ollama) or reasoning models
that require more processing time.

Signed-off-by: Andreas Brenk <mail@andreasbrenk.com>
@abrenk
Copy link
Member Author

abrenk commented Mar 20, 2026

I've removed the translations and added the requestTimeout to README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature for an existing add-on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ChatGPT] Time-out when using local LLM

2 participants