open-webui icon indicating copy to clipboard operation
open-webui copied to clipboard

Add the enable_thinking parameter to Qwen3

Open lingyezhixing opened this issue 11 months ago • 16 comments

Check Existing Issues

  • [x] I have searched the existing issues and discussions.

Problem Description

The latest Qwen3 cannot switch response mode in the current open webui version

Desired Solution you'd like

Add the enable_thinking parameter to Qwen3

Alternatives Considered

Add the enable_thinking parameter to Qwen3

Additional Context

No response

lingyezhixing avatar Apr 29 '25 04:04 lingyezhixing

If it is really impossible to add options to a single model, providing extra_body option is also fine. At least we have a way to solve some minor adaptation problems by ourselves.
(;´д`)ゞ

1790374044 avatar Apr 29 '25 07:04 1790374044

+1

ZV-Liu avatar Apr 29 '25 07:04 ZV-Liu

To disable the thinking process, what is required of you is to add /no_think to your prompt (for the current round) or the system message (for the entire dialogue) without making any other settings.

Wannabeasmartguy avatar Apr 29 '25 07:04 Wannabeasmartguy

If it is really impossible to add options to a single model, providing extra_body option is also fine. At least we have a way to solve some minor adaptation problems by ourselves. (;´д`)ゞ

Although as stated in https://github.com/open-webui/open-webui/issues/1484 , Function can cover this usage scenario, but using Function is too much like using a sledgehammer to crack a nut.
...( _ _)ノ|

1790374044 avatar Apr 29 '25 07:04 1790374044

To disable the thinking process, what is required of you is to add no_think to your prompt (for the current round) or the system message (for the entire dialogue) without making any other settings.

In some cases (like qwen-plus provided by aliyun) , enable_thinking is turned off by default, which leads to the inability to enable the thinking process.

1790374044 avatar Apr 29 '25 08:04 1790374044

If it is really impossible to add options to a single model, providing extra_body option is also fine. At least we have a way to solve some minor adaptation problems by ourselves. (;´д`)ゞ

Although as stated in #1484 , Function can cover this usage scenario, but using Function is too much like using a sledgehammer to crack a nut. ...( _ _)ノ|

As mentioned above, Function can be used for this.
Yesterday I found Gemini Safety Settings off .
So...

from pydantic import BaseModel, Field
from typing import Optional


class Filter:
    class Valves(BaseModel):
        enable_thinking: bool = Field(
            default=True, description="whether reasoning or not"
        )
        thinking_budget: int = Field(default=38912, description="max reasoning length")
        pass

    def __init__(self):
        # Indicates custom file handling logic. This flag helps disengage default routines in favor of custom
        # implementations, informing the WebUI to defer file-related operations to designated methods within this class.
        # Alternatively, you can remove the files directly from the body in from the inlet hook
        # self.file_handler = True

        # Initialize 'valves' with specific configurations. Using 'Valves' instance helps encapsulate settings,
        # which ensures settings are managed cohesively and not confused with operational flags like 'file_handler'.
        self.valves = self.Valves()
        pass

    def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
        # Modify the request body or validate it before processing by the chat completion API.
        # This function is the pre-processor for the API where various checks on the input can be performed.
        # It can also modify the request before sending it to the API.
        body["enable_thinking"] = self.valves.enable_thinking
        if self.valves.enable_thinking and self.valves.thinking_budget > 0:
            body["thinking_budget"] = self.valves.thinking_budget

        return body
  1. place it in http://your-webui-url/admin/functions as a Filter Function
  2. go to http://your-webui-url/workspace/models, create a new model based on qwen3 (in my case, based on qwen-plus-latest) and use filter you created in the previous step
  3. use this new model

I'm a novice, so I don't know why it works. But, it is not as complicated as Pipe Function, and, it just works.

1790374044 avatar Apr 30 '25 02:04 1790374044

A switch to turn on thinking could be added at the bottom of the dialog so that you can choose whether to start thinking or not

zhongli0226 avatar Apr 30 '25 02:04 zhongli0226

This one works. But does not allow user to toggle in chat config.

from pydantic import BaseModel, Field
from typing import Optional


class Filter:
    class Valves(BaseModel):
        enable_thinking: bool = Field(
            default=True, description="whether reasoning or not"
        )

    def __init__(self):
        self.valves = self.Valves()

    def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
        body["chat_template_kwargs"] = {"enable_thinking": self.valves.enable_thinking}

        return body


cpwan avatar Apr 30 '25 06:04 cpwan

Very important, in title generation we don't need to be able to force the non thinking version to generate instead of the thinking version for Qwen3

TheNexter avatar Apr 30 '25 09:04 TheNexter

If it is really impossible to add options to a single model, providing extra_body option is also fine. At least we have a way to solve some minor adaptation problems by ourselves. (;´д`)ゞ

Although as stated in #1484 , Function can cover this usage scenario, but using Function is too much like using a sledgehammer to crack a nut. ...( _ _)ノ|

We need custom model parameter settings in OpenWebUI. Adding some simple parameters through Functions complicates model management process.

Xi-Gong avatar Apr 30 '25 10:04 Xi-Gong

Image Image

The "Think" or "Reason" toggles are becoming fairly standard on AI chat interfaces and apps alike. I think a toggle such as that (or potentially enhanced with a dropdown, on the toggle, to fine-tune the thinking effort/level on models that support it) would address a lot of the before mentioned desires, in a user friendly way, that is standard with what users are coming to expect with AI chat interfaces

TheDropZone avatar Apr 30 '25 12:04 TheDropZone

Image Image

The "Think" or "Reason" toggles are becoming fairly standard on AI chat interfaces and apps alike. I think a toggle such as that (or potentially enhanced with a dropdown, on the toggle, to fine-tune the thinking effort/level on models that support it) would address a lot of the before mentioned desires, in a user friendly way, that is standard with what users are coming to expect with AI chat interfaces

In fact, they can be different models under the button. For instance, deepseek v3 and deepseek r1 are different models even it is rendered as a button toggle.

cpwan avatar Apr 30 '25 12:04 cpwan

Now different models have different ways to enable reasoning.
How to make a toggle work with different models may be a complicated challenge.
(;′⌒`)

1790374044 avatar Apr 30 '25 12:04 1790374044

Ideally, it would be actioned by the standard openai "reasoning" field, with the effort object. But, openai reasoning.effort doesn't support disabling currently, just low/medium/high. So yah, being flexible for various models will be the hard part.

But I do think the think/reason toggle, from a ui perspective, is the way to go in terms of user experience

TheDropZone avatar Apr 30 '25 15:04 TheDropZone

I think could let an administrator to configure the thinking option for the model, can turn it on/off, or turn it on to use another thinking model.

The think option is not displayed by default.

At87668 avatar May 01 '25 10:05 At87668

Now different models have different ways to enable reasoning. How to make a toggle work with different models may be a complicated challenge. (;′⌒`)

@1790374044 that's true

There are several publicly available hybrid thinking models, but a standard has not been established yet.

https://huggingface.co/nvidia/Llama-3_3-Nemotron-Super-49B-v1 https://huggingface.co/NousResearch/DeepHermes-3-Llama-3-8B-Preview

I don’t think this feature will follow an official API standard, but I believe Qwen’s approach could be adopted as the de facto standard.

dongs0104 avatar May 01 '25 23:05 dongs0104

Perhaps we can use a function to add custom buttons (similar to enabling a filter when pressed, and if they are checked in the model settings interface, they will be displayed Because they function like filters, we can fully customize their behavior after pressing the button, such as adding a sentence to enable or disable inference when prompted by the system

Image

EntropyYue avatar May 11 '25 07:05 EntropyYue

How would you handle the fact that in thinking and non-thinking mode, different sampling parameters are recommended?

ssakar avatar May 11 '25 07:05 ssakar

This one works. But does not allow user to toggle in chat config.这个可以运行,但不允许用户在聊天配置中切换。

from pydantic import BaseModel, Field from typing import Optional

class Filter: class Valves(BaseModel): enable_thinking: bool = Field( default=True, description="whether reasoning or not" )

def __init__(self):
    self.valves = self.Valves()

def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
    body["chat_template_kwargs"] = {"enable_thinking": self.valves.enable_thinking}

    return body

It looks like this must be done by removing the parameter --enable-reasoning --reasoning-parser deepseek_r1 on the vllm side, or else it will cause the output to be mistakenly thought of as thinking

kenvix avatar May 11 '25 18:05 kenvix

To disable the thinking process, what is required of you is to add /no_think to your prompt (for the current round) or the system message (for the entire dialogue) without making any other settings.

Specifically, you can add /think and /no_think to user prompts or system messages to switch the model’s thinking mode from turn to turn.

Image openwebui是否可以加个按钮,实现自动给用户prompt尾部添加/no_think或/think

fifiand1 avatar May 13 '25 08:05 fifiand1

How about this one? Add a swtich checkbox on model edit page to enable switching think/non-think mode Image

Then add a think button on message input Image

Image

For other models that do not support switching between thinking/non-thinking modes, there does not exist the Thinking button.

Image

If anyone were interested in this solution, I could submit the code.

dongfangzan avatar May 15 '25 10:05 dongfangzan

For prompting, I would want the switch on the chat window or model selector, not buried deep in the model details. Perhaps the model details page could have configuration on how to apply the switch (/think and /no_think for qwen3).

Of more interest to me though would be Open Web UI turning off thinking for certain operations automatically, like for summary generation.

MicahZoltu avatar May 15 '25 10:05 MicahZoltu

@dongfangzan I'm interested in this, can you upload to github?

EntropyYue avatar May 15 '25 11:05 EntropyYue

I just tested to verify, title and tag generation at the least don't work without putting /no_think in the prompts that are used. I'm guessing because the output ends up not being formatted like the prompt declares because of the extra <thinking></thinking>. Also, thinking is much slower and unnecessary (waste of resources) for title and tag generation. Being able to teach OpenWebUI how to enable/disable thinking for each model on a per-query basis would allow OpenWebUI to fix this problem automatically.

MicahZoltu avatar May 15 '25 11:05 MicahZoltu

For image and code generation, I would like the model to think deeply, but I believe things will break if the output includes the <thinking></thinking> tags. This is another situation where it feels like OpenWebUI should be aware of how models think and filter that out of the final response.

MicahZoltu avatar May 15 '25 11:05 MicahZoltu

How about this one? Add a swtich checkbox on model edit page to enable switching think/non-think mode Image

Then add a think button on message input Image Image

For other models that do not support switching between thinking/non-thinking modes, there does not exist the Thinking button. Image

If anyone were interested in this solution, I could submit the code.

I'm sorry if I offended you.

If I understand correctly, is this solution only effective for qwen3?
If it is a solution limited to qwen3, might open-webui not accept such a pr?
>︿<

1790374044 avatar May 15 '25 11:05 1790374044

How about this one? Add a swtich checkbox on model edit page to enable switching think/non-think mode Image Then add a think button on message input Image Image For other models that do not support switching between thinking/non-thinking modes, there does not exist the Thinking button. Image If anyone were interested in this solution, I could submit the code.

I'm sorry if I offended you.

If I understand correctly, is this solution only effective for qwen3? If it is a solution limited to qwen3, might open-webui not accept such a pr? >︿<

No, any model can be effective with this solution if they used the same parameter enable_thinking: true. However, for now there is only one model which support switching thinking/non-thinking modes.

You can have a look at the qwen3 Offical document below.

Image

Nevermind whether open-webui could accept this pr, I've used it in my production.

dongfangzan avatar May 15 '25 12:05 dongfangzan

How about this one? Add a swtich checkbox on model edit page to enable switching think/non-think mode Image Then add a think button on message input Image Image For other models that do not support switching between thinking/non-thinking modes, there does not exist the Thinking button. Image If anyone were interested in this solution, I could submit the code.

I'm sorry if I offended you. If I understand correctly, is this solution only effective for qwen3? If it is a solution limited to qwen3, might open-webui not accept such a pr? >︿<

No, any model can be effective with this solution if they used the same parameter enable_thinking: true. However, for now there is only one model which support switching thinking/non-thinking modes.

You can have a look at the qwen3 Offical document below. Image

Nevermind whether open-webui could accept this pr, I've used it in my production.

However, for now there is only one model which support switching thinking/non-thinking modes.

In fact, there are some other models. For example,Claude 3.7 Sonnet, Llama-3_3-Nemotron-Super-49B-v1
...( _ _)ノ|

1790374044 avatar May 15 '25 12:05 1790374044

How about this one? Add a swtich checkbox on model edit page to enable switching think/non-think mode Image Then add a think button on message input Image Image For other models that do not support switching between thinking/non-thinking modes, there does not exist the Thinking button. Image If anyone were interested in this solution, I could submit the code.

I'm sorry if I offended you. If I understand correctly, is this solution only effective for qwen3? If it is a solution limited to qwen3, might open-webui not accept such a pr? >︿<

No, any model can be effective with this solution if they used the same parameter enable_thinking: true. However, for now there is only one model which support switching thinking/non-thinking modes. You can have a look at the qwen3 Offical document below. Image Nevermind whether open-webui could accept this pr, I've used it in my production.

However, for now there is only one model which support switching thinking/non-thinking modes.

In fact, there are some other models. For example,Claude 3.7 Sonnet, Llama-3_3-Nemotron-Super-49B-v1 ...( _ _)ノ|

Alright, I really didn't notice that. Most of my works are related to Qwen. This is indeed a difficult problem to solve if there is not a standard API.

dongfangzan avatar May 15 '25 12:05 dongfangzan

Actually, I've been curious for a long time...

Why not place some dynamically generated buttons next to the "Web Search" button based on the Filter used?
Clicking the button would open a pop-up window containing a toggle switch and configuration options for the Filter.

Does this sound like it could serve as a fallback solution for adapting models?

¯\_(ツ)_/¯

1790374044 avatar May 15 '25 12:05 1790374044