You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将CLU(Conversational Language Understanding)集成到Node.js版Bot Framework SDK中

在Node.js Bot Framework应用中集成CLU的方案

是的,有官方支持的工具可以将Azure CLU(Conversational Language Understanding)集成到你的Node.js Bot Framework应用中,替代即将停用的LUIS,具体方案如下:

1. 使用官方CLU客户端库

微软提供了专门的Node.js客户端库@azure/ai-language-conversations,用于和CLU服务交互,这是集成CLU的首选方式。

  • 安装命令:

    npm install @azure/ai-language-conversations
    
  • 基础使用示例:

    const { ConversationAnalysisClient, AzureKeyCredential } = require('@azure/ai-language-conversations');
    
    // 初始化CLU客户端
    const cluEndpoint = '<你的CLU服务端点>';
    const cluApiKey = '<你的CLU API密钥>';
    const projectName = '<你的CLU项目名称>';
    const deploymentName = '<你的CLU部署名称>';
    
    const client = new ConversationAnalysisClient(cluEndpoint, new AzureKeyCredential(cluApiKey));
    
    // 处理用户输入的函数
    async function recognizeUserInput(userInput) {
      const result = await client.analyzeConversation({
        task: {
          kind: 'Conversation',
          analysisInput: {
            conversationItem: {
              text: userInput,
              id: '1',
              participantId: 'user'
            }
          },
          parameters: {
            projectName: projectName,
            deploymentName: deploymentName,
            verbose: true
          }
        }
      });
    
      // 提取意图和实体
      const topIntent = result.result.prediction.topIntent;
      const entities = result.result.prediction.entities;
      
      return { topIntent, entities };
    }
    

2. 在Bot Framework中替换LUIS逻辑

你可以在原有回声机器人的对话处理逻辑中,替换掉原来LUISRecognizer的调用部分,改用上述CLU客户端来处理用户输入:

// 在机器人的turn handler中使用CLU
this.onMessage(async (context, next) => {
  const userInput = context.activity.text;
  const cluResult = await recognizeUserInput(userInput);

  // 根据CLU返回的意图处理对话
  switch(cluResult.topIntent) {
    case 'Greeting':
      await context.sendActivity('你好!有什么我可以帮你的吗?');
      break;
    case 'WeatherQuery':
      // 提取实体并处理天气查询逻辑
      const location = cluResult.entities.find(e => e.category === 'Location')?.text;
      await context.sendActivity(`你想查询${location}的天气吗?`);
      break;
    default:
      // 回退到回声逻辑
      await context.sendActivity(`你说了:${userInput}`);
  }

  await next();
});

3. 关键注意事项

  • 确保你已经在Azure门户中创建了CLU资源,并且完成了模型的训练和发布
  • 初始化客户端时需要的端点、API密钥、项目名称和部署名称,都可以从Azure门户的CLU资源详情页获取
  • 若需要更贴合Bot Framework的使用习惯,也可以自行封装CLU调用逻辑为一个工具类,类似原来的LUISRecognizer

内容的提问来源于stack exchange,提问作者Narandhran Thangavel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 13:43:13