Skip to content

DashScopeChatOptions missing toolCallbacks #781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
qsLI opened this issue May 6, 2025 · 1 comment
Open

DashScopeChatOptions missing toolCallbacks #781

qsLI opened this issue May 6, 2025 · 1 comment

Comments

@qsLI
Copy link

qsLI commented May 6, 2025

我们鼓励使用英文,如果不能直接使用,可以使用翻译软件,您仍旧可以保留中文原文。另外请按照如下要求提交相关信息节省社区维护同学的理解成本,否则该讨论极有可能直接被忽视或关闭。
We recommend using English. If you are non-native English speaker, you can use the translation software. We recommend using English. If you are non-native English speaker, you can use the translation software. In addition, please submit relevant information according to the following requirements to save the understanding cost of community maintenances, otherwise the discussion is very likely to be ignored or closed directly.

Which Component
DashScopeChatOptions

Describe the bug
LLM didn't recieve tool call descriptions with dashscope, same code is ok with open ai.
The root cause is DashScopeChatOptions bean missed a field toolCallbacks
DashScope just copyToTarget use ChatOptions

// com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel#createRequest
        DashScopeChatOptions options = DashScopeChatOptions.builder().build();
        if (prompt.getOptions() != null) {
            DashScopeChatOptions updatedRuntimeOptions = (DashScopeChatOptions)ModelOptionsUtils.copyToTarget(prompt.getOptions(), ChatOptions.class, DashScopeChatOptions.class);
            enabledToolsToUse.addAll(this.runtimeFunctionCallbackConfigurations(updatedRuntimeOptions));
            options = (DashScopeChatOptions)ModelOptionsUtils.merge(updatedRuntimeOptions, options, DashScopeChatOptions.class);
        }

OpenAiChatOptions has toolCallbacks

	/**
	 * Collection of {@link ToolCallback}s to be used for tool calling in the chat completion requests.
	 */
	@JsonIgnore
	private List<FunctionCallback> toolCallbacks = new ArrayList<>();

open ai use ToolCallingChatOptions as source class and works fine.

// org.springframework.ai.openai.OpenAiChatModel#buildRequestPrompt
	Prompt buildRequestPrompt(Prompt prompt) {
		// Process runtime options
		OpenAiChatOptions runtimeOptions = null;
		if (prompt.getOptions() != null) {
			if (prompt.getOptions() instanceof ToolCallingChatOptions toolCallingChatOptions) {
				runtimeOptions = ModelOptionsUtils.copyToTarget(toolCallingChatOptions, ToolCallingChatOptions.class,
						OpenAiChatOptions.class);
			}
			else if (prompt.getOptions() instanceof FunctionCallingOptions functionCallingOptions) {
				runtimeOptions = ModelOptionsUtils.copyToTarget(functionCallingOptions, FunctionCallingOptions.class,
						OpenAiChatOptions.class);
			}
			else {
				runtimeOptions = ModelOptionsUtils.copyToTarget(prompt.getOptions(), ChatOptions.class,
						OpenAiChatOptions.class);
			}
		}

Simplest demo

        final JfrTools jfrTools = new JfrTools();
        ChatClient chatClient = ChatClient.builder(chatModel)
                .defaultTools(jfrTools)
                .defaultOptions(DefaultToolCallingChatOptions.builder()
                        .internalToolExecutionEnabled(false).build())
                .build();

To Reproduce

  1. use above code
  2. run with dashscope

Expected behavior
pass tool info correctly

Screenshots

  • dashscope copy
Image
  • open ai copy
Image
  • no tool info in qwen
Image
  • tool info in open ai
Image
@songxiaosheng
Copy link

has solve it ,pls help check it
3fb3cb7

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

No branches or pull requests

3 participants
@qsLI @songxiaosheng and others