UiPath Documentation
test-cloud
latest
false
Test Cloud 管理员指南
重要 :
新发布内容的本地化可能需要 1-2 周的时间才能完成。

操作指南:通过 AI Trust Layer 连接 Mistral

使用自定义 Integration Service 连接器,通过 AI Trust Layer 将 Azure AI Foundry 中的 Mistrl 模型连接到 UiPath Agents。

备注:

此功能目前已针对 Enterprise 客户正式发布,可应请求提供。

本指南说明了如何通过 AI Trust Layer LLM 配置功能将 Microsoft Azure AI Foundry 中部署的 Mistral 模型连接到 UiPath 智能体。您可以基于 Azure OpenAI 模板创建一个自定义 Integration Service 连接器,并根据 Mistral 的 API 要求调整其请求挂钩。

先决条件​

  • 为您的组织启用了 AI Trust Layer 的自定义连接器(目前可根据 Enterprise 客户请求提供)。
  • 在 Azure AI Foundry 中部署的 Mistral 模型(例如mistral-small-2503 )
  • 资源的 Azure AI Foundry 端点 URL
  • Azure AI Foundry 资源的 API 密钥
  • Test Cloud 中的 Organization Administrator 访问权限
  • 访问 Integration Service 和连接器生成器

创建自定义连接器​

  1. 导航到“管理员” > “AI Trust Layer” > “LLM 配置” ,然后选择“添加配置” 。
  2. 设置“租户” 、 “产品”和“功能”的值。
  3. 在“模型配置”下,在“LLM 名称”字段中输入自定义别名,并将“API 类型”设置为“OpenAI” 。
  4. 在“连接器”字段中,选择“创建自定义连接器” 。
  5. 选择“Azure OpenAI”模板,然后选择“创建连接器” 。系统将打开连接器生成器,其中已预先填充 Azure OpenAI 模板。

编辑连接器以实现 Mistral 兼容性​

Azure AI Foundry 上的 Mistral 模型使用严格的架构验证,并且不接受 Azure OpenAI 模板默认发送的所有字段。在每个请求到达 Mistral 端点之前,连接器的preRequest挂钩必须解决这些差异。

Azure OpenAI 模板发送Azure AI Foundry 上的 Mistral挂钩应用的分辨率
tool_choice: "required" 或对象形式"none"、 "auto"或"any"如果存在工具,则转换为"any"
parallel_tool_calls 字段不支持的字段 ( extra_forbidden )已从请求正文中删除
max_completion_tokensmax_tokens字段已重命名
  1. 在连接器生成器中,打开“挂钩”部分,然后选择“preRequest”挂钩。

  2. 将整个挂钩主体替换为以下脚本:

    // Normalize query params and payload for Mistral on Azure AI Foundry.
    // Removes unsupported fields and adapts tool semantics for Mistral's strict schema.
    const _reqPath = (typeof request_path !== 'undefined') ? request_path : '';
    const _reqParams = (typeof request_parameters !== 'undefined') ? request_parameters : undefined;
    const _cfg = (typeof configuration !== 'undefined') ? configuration : undefined;
    
    if (['/query', '/v1/responses'].includes(_reqPath)) {
        return done();
    }
    
    let apiVersion = (_cfg && _cfg['api-version']) ? _cfg['api-version'] : "2023-05-15";
    if (_reqParams && _reqParams["api-version"]) {
        apiVersion = _reqParams["api-version"];
    }
    if (['/listAllModels', '/auth_validation'].includes(_reqPath)) {
        apiVersion = (_cfg && _cfg['api-version']) ? _cfg['api-version'] : "2023-10-01-preview";
    }
    
    // Resolve body across different runtime variable names
    let body = (typeof request_body !== 'undefined' && request_body) ? request_body :
               ((typeof request_vendor_body !== 'undefined' && request_vendor_body) ? request_vendor_body :
                ((typeof request !== 'undefined' && request && request.body) ? request.body : undefined));
    
    if (body && typeof body === 'string') {
        try { body = JSON.parse(body); } catch (e) { /* leave as-is */ }
    }
    
    if (body && typeof body === 'object') {
        // Remove field rejected by Mistral's strict schema
        if (Object.prototype.hasOwnProperty.call(body, 'parallel_tool_calls')) {
            delete body.parallel_tool_calls;
        }
    
        // Normalize tool_choice: Mistral accepts only 'none', 'auto', or 'any'
        const _allowedToolChoice = new Set(['none', 'auto', 'any']);
        const _hasTools = Object.prototype.hasOwnProperty.call(body, 'tools')
            && Array.isArray(body.tools) && body.tools.length > 0;
    
        if (Object.prototype.hasOwnProperty.call(body, 'tool_choice')) {
            if (body.tool_choice === 'required') {
                body.tool_choice = 'any';
            } else if (body.tool_choice && typeof body.tool_choice === 'object') {
                body.tool_choice = 'any';
            } else if (typeof body.tool_choice === 'string' && !_allowedToolChoice.has(body.tool_choice)) {
                body.tool_choice = _hasTools ? 'any' : 'auto';
            }
        } else if (_hasTools) {
            // Force tool usage: agent runtime expects tool calls when tools are configured
            body.tool_choice = 'any';
        }
    
        // Rename max_completion_tokens to max_tokens
        if (Object.prototype.hasOwnProperty.call(body, 'max_completion_tokens')) {
            if (!Object.prototype.hasOwnProperty.call(body, 'max_tokens')) {
                body.max_tokens = body.max_completion_tokens;
            }
            delete body.max_completion_tokens;
        }
    }
    
    const out = {
        request_vendor_parameters: { "api-version": apiVersion }
    };
    
    if (typeof request_body !== 'undefined') out.request_body = body;
    if (typeof request_vendor_body !== 'undefined') out.request_vendor_body = body;
    
    return done(out);
    // Normalize query params and payload for Mistral on Azure AI Foundry.
    // Removes unsupported fields and adapts tool semantics for Mistral's strict schema.
    const _reqPath = (typeof request_path !== 'undefined') ? request_path : '';
    const _reqParams = (typeof request_parameters !== 'undefined') ? request_parameters : undefined;
    const _cfg = (typeof configuration !== 'undefined') ? configuration : undefined;
    
    if (['/query', '/v1/responses'].includes(_reqPath)) {
        return done();
    }
    
    let apiVersion = (_cfg && _cfg['api-version']) ? _cfg['api-version'] : "2023-05-15";
    if (_reqParams && _reqParams["api-version"]) {
        apiVersion = _reqParams["api-version"];
    }
    if (['/listAllModels', '/auth_validation'].includes(_reqPath)) {
        apiVersion = (_cfg && _cfg['api-version']) ? _cfg['api-version'] : "2023-10-01-preview";
    }
    
    // Resolve body across different runtime variable names
    let body = (typeof request_body !== 'undefined' && request_body) ? request_body :
               ((typeof request_vendor_body !== 'undefined' && request_vendor_body) ? request_vendor_body :
                ((typeof request !== 'undefined' && request && request.body) ? request.body : undefined));
    
    if (body && typeof body === 'string') {
        try { body = JSON.parse(body); } catch (e) { /* leave as-is */ }
    }
    
    if (body && typeof body === 'object') {
        // Remove field rejected by Mistral's strict schema
        if (Object.prototype.hasOwnProperty.call(body, 'parallel_tool_calls')) {
            delete body.parallel_tool_calls;
        }
    
        // Normalize tool_choice: Mistral accepts only 'none', 'auto', or 'any'
        const _allowedToolChoice = new Set(['none', 'auto', 'any']);
        const _hasTools = Object.prototype.hasOwnProperty.call(body, 'tools')
            && Array.isArray(body.tools) && body.tools.length > 0;
    
        if (Object.prototype.hasOwnProperty.call(body, 'tool_choice')) {
            if (body.tool_choice === 'required') {
                body.tool_choice = 'any';
            } else if (body.tool_choice && typeof body.tool_choice === 'object') {
                body.tool_choice = 'any';
            } else if (typeof body.tool_choice === 'string' && !_allowedToolChoice.has(body.tool_choice)) {
                body.tool_choice = _hasTools ? 'any' : 'auto';
            }
        } else if (_hasTools) {
            // Force tool usage: agent runtime expects tool calls when tools are configured
            body.tool_choice = 'any';
        }
    
        // Rename max_completion_tokens to max_tokens
        if (Object.prototype.hasOwnProperty.call(body, 'max_completion_tokens')) {
            if (!Object.prototype.hasOwnProperty.call(body, 'max_tokens')) {
                body.max_tokens = body.max_completion_tokens;
            }
            delete body.max_completion_tokens;
        }
    }
    
    const out = {
        request_vendor_parameters: { "api-version": apiVersion }
    };
    
    if (typeof request_body !== 'undefined') out.request_body = body;
    if (typeof request_vendor_body !== 'undefined') out.request_vendor_body = body;
    
    return done(out);
    
  3. 在连接器设置中,将“基本 URL”设置为您的 Azure AI Foundry 端点: https://{your-resource-name}.openai.azure.com/openai 。

  4. 设置“身份验证类型”以匹配您的设置。本示例使用API 密钥( customApiKey ),但您可以使用任何受支持的身份验证类型,包括OAuth — 请相应地更新连接器设置。

  5. 选择“保存”。

在 Integration Service 中创建连接​

  1. 在 Integration Service 中,导航到“连接” ,然后选择“添加连接” 。
  2. 选择您发布的自定义连接器。
  3. 在“API 密钥”字段中,输入您的 Azure AI Foundry API 密钥。
  4. 在“Azure OpenAI 资源”字段中,输入您的资源名称,即端点 URL 的子域部分,不带https://或.openai.azure.com 。
  5. 选择“连接”以配置连接。

完成 LLM 配置​

  1. 返回到“管理员” > “AI Trust Layer” > “LLM 配置” ,然后打开您启动的配置。
  2. 在“模型配置”下,将“连接器”设置为您已发布的连接器,将“连接” 设置为您创建的连接。
  3. 在“LLM 标识符”字段中,输入与 Azure AI Foundry 中显示的完全相同的部署名称。
    备注:

    LLM 标识符字段中的尾随空格会导致DeploymentNotFound错误。保存前,请验证没有前导或尾随空格。

  4. 选择测试配置,以运行 AI Trust Layer 探测器。
  5. 如果探测器通过,请选择“保存” 。

结果​

配置将保存,并且 Mistral 模型可用于您指定的产品和功能的 UiPath 智能体。调用通过 AI Trust Layer 路由,并显示在审核日志中的“来源:自定义连接”下。

备注:

如果您在创建自定义连接器时遇到问题,请联系 UiPath 支持团队获取帮助。

  • 先决条件​
  • 创建自定义连接器​
  • 编辑连接器以实现 Mistral 兼容性​
  • 在 Integration Service 中创建连接​
  • 完成 LLM 配置​
  • 结果​

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新