千问turbo无法调用Tools问题

已解决

您好,我目前使用的模型是qwen-turbo-2025-04-28。我想实现他调用Tool的功能。
这是我的tools配置


@Slf4j
public class DateTimeTools {

    @Tool(description = "查询当前的系统时间")
    public String getCurrentDateTime() {
        log.info("DateTimeTools:调用了getCurrentDateTime");
        return "2025-05-15";
    }


    @Tool(description = "Get the time of a specified city.")
    public String getCityTimeMethod(@ToolParam(description = "Time zone id, such as Asia/Shanghai") String timeZoneId) {
        log.info("The current time zone is {}", timeZoneId);
        return String.format("The current time zone is %s and the current time is " + "%s", timeZoneId, "111");
    }
}

我为了防止中英文模型的理解能力,我写了一个中文还有一个英文。

这是我注入ChatClient的代码

    @Bean
    public ChatClient chatClient() {
        return ChatClient.builder(dashScopeChatModel)
                .defaultSystem("你是我的企业知识库AI客服助手,请帮我解答我提出的相关问题")
                .defaultTools(new DateTimeTools())
                .defaultAdvisors(
                        new QuestionAnswerAdvisor(vectorStore, SearchRequest.builder().similarityThreshold(0.7).build()),
                        new SimpleLoggerAdvisor()
                ).build();
    }

这是我调用chatClient的代码


    @GetMapping("/chat")
    public RestResult<String> chat(@RequestParam(value = "conversationId") String conversationId,
                                   @RequestParam(value = "message") String message) {
        return RestResult.buildSuccessResult(chatClient.prompt()
                .user(message)
                // .functions("weatherFunction")
                .advisors(new ChatMessageAdvisor(dbChatMemory, conversationId))
                .call()
                .content());
    }

不管我怎么问,就是没办法调用我写的tool。
大神帮忙看一下,谢谢啦

展开
收起
游客szugmtxqze2te 2025-05-28 19:39:17 65 分享 版权
1 条回答
写回答
取消 提交回答
  • 通义灵码是基于通义大模型的 AI 研发辅助工具,提供代码生成、研发问答、任务执行等能力,为开发者带来智能化研发体验,引领 AI 原生研发新范式。通义灵码包含 AI 编码助手和 AI 程序员。 更多信息欢迎加入通义灵码用户交流群(钉钉群号53770000738)
    官方回答

    您好,这里是通义灵码问答区,如果使用通义灵码有问题,欢迎加入我们的钉钉答疑群,第一时间为您服务:钉钉群:53770000738

    2025-05-30 18:45:32
    赞同 181 展开评论

基于通义系列大模型和开源大模型的一站式大模型服务平台,提供「生成式大模型的全流程应用工具」和「企业大模型的全链路训练工具」。为大模型,也为小应用。 阿里云百炼官网网址:https://www.aliyun.com/product/bailian

还有其他疑问?
咨询AI助理