qwen有些模型如果是非流式输出必须要关闭深度思考,但是设置 enable_thinking=False并没生效。#88
Open
liuxymm wants to merge 1 commit into
Open
Conversation
原因: HelloAgentsLLM.__init__(..., **kwargs) 里虽然接收了 enable_thinking=False ,但 原实现没有把这些 kwargs 带到每次请求里 ,所以请求照样按服务端默认(可能是 thinking=true)发出 同时修改: OpenAI 适配器里把 enable_thinking 自动映射到 extra_body ,并在非流式时默认强制为 false
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
执行hello-agents教程中例子到 llm = HelloAgentsLLM()这一行时报错
报错:Traceback (most recent call last):
File "d:\project\HelloAgents\hello_agents\core\llm_adapters.py", line 121, in invoke
response = self._client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\openai_utils_utils.py", line 286, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\openai\resources\chat\completions\completions.py", line 1147, in create
return self._post(
^^^^^^^^^^^
or'}, 'id': 'chatcmpl-ebd7a975-de9b-9d01-969c-7102e144a219', 'request_id': 'ebd7a975-de9b-9d01-969c-7102e144a219'}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\project\HelloAgents\test.py", line 22, in
response = agent.run("你好!请介绍一下自己")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\project\HelloAgents\hello_agents\agents\simple_agent.py", line 102, in run
llm_response = self.llm.invoke(messages, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\project\HelloAgents\hello_agents\core\llm.py", line 146, in invoke
return self._adapter.invoke(messages, **call_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\project\HelloAgents\hello_agents\core\llm_adapters.py", line 161, in invoke
raise HelloAgentsException(f"OpenAI API调用失败: {str(e)}")
hello_agents.core.exceptions.HelloAgentsException: OpenAI API调用失败: Error code: 400 - {'error': {'message': 'parameter.enable_thinking must be set to false for non-streaming calls', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_parameter_error'}, 'id': 'chatcmpl-ebd7a975-de9b-9d01-969c-7102e144a219', 'request_id': 'ebd7a975-de9b-9d01-969c-7102e144a219'}
因为使用的qwen模型再非流式时必须关闭深度思考,但是llm = HelloAgentsLLM(enable_thinking=False)仍然报错:
Traceback (most recent call last):
File "d:\project\HelloAgents\hello_agents\core\llm_adapters.py", line 121, in invoke
response = self._client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\openai_utils_utils.py", line 286, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: Completions.create() got an unexpected keyword argument 'enable_thinking'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\project\HelloAgents\test.py", line 22, in
response = agent.run("你好!请介绍一下自己")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\project\HelloAgents\hello_agents\agents\simple_agent.py", line 102, in run
llm_response = self.llm.invoke(messages, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\project\HelloAgents\hello_agents\core\llm.py", line 148, in invoke
return self._adapter.invoke(messages, **call_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\project\HelloAgents\hello_agents\core\llm_adapters.py", line 161, in invoke
raise HelloAgentsException(f"OpenAI API调用失败: {str(e)}")
hello_agents.core.exceptions.HelloAgentsException: OpenAI API调用失败: Completions.create() got an unexpected keyword argument 'enable_thinking'
原因:
HelloAgentsLLM.init(..., **kwargs) 里虽然接收了 enable_thinking=False ,但 原实现没有把这些 kwargs 带到每次请求里 ,所以请求照样按服务端默认(可能是 thinking=true)发出
同时修改:
OpenAI 适配器里把 enable_thinking 自动映射到 extra_body ,并在非流式时默认强制为 false
修复: