UiPath Documentation
test-cloud
latest
false
Test Cloud 管理ガイド
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。

How-to guide: Connecting Cohere through AI Trust Layer

Connect a Cohere model to UiPath Agents via AI Trust Layer using a custom Integration Service connector that calls the Cohere OpenAI-compatible API.

注:

この機能は、Enterprise プランのユーザー向けにリクエストに応じて一般提供されています。

This guide explains how to connect a Cohere model to UiPath Agents through the AI Trust Layer LLM Configurations feature. You create a custom Integration Service connector from the Azure OpenAI template, then replace its hooks so that the connector calls the Cohere OpenAI-compatible API with your Cohere API key.

前提条件​

  • Custom connectors for AI Trust Layer enabled for your organization
  • A Cohere API key from the Cohere dashboard
  • The ID of the Cohere model you want to use (for example, command-a-03-2025)
  • Test Cloud での組織管理者のアクセス権
  • Integration Service とコネクタ ビルダーへのアクセス

カスタム コネクタを作成する​

  1. [ 管理 ] > [AI Trust Layer ] > [LLM の設定 ] に移動し、[ 設定を追加] を選択します。
  2. [テナント]、[製品]、および [機能] の値を設定します。
  3. Under Model Configuration, enter a custom alias in the LLM Name field.
  4. Set API Type to OpenAI.
  5. [コネクタ] フィールドで、[カスタム コネクタを作成] を選択します。
  6. Azure OpenAI テンプレートを選択し、[コネクタを作成] を選択します。コネクタ ビルダーが開き、Azure OpenAI テンプレートが事前に入力された状態で開きます。

Edit the connector for Cohere compatibility​

The Azure OpenAI template defines the request format that AI Trust Layer sends to the connector. No traffic goes through Azure. The connector hooks translate each request for the Cohere OpenAI-compatible API, and the Base URL setting sends it to Cohere.

The preRequest hook resolves the following differences between the two formats:

AI Trust Layer sends (template format)Cohere expectsResolution applied by the hook
max_completion_tokensmax_tokensフィールドの名前が変更されます
parallel_tool_calls, store, metadata, logit_bias, top_logprobs, n, modalities, prediction, audio, or service_tierFields not supportedRemoved from the request body
tool_choice set to any, an object, or an unrecognized value, with tools presentnone、auto、または requiredSet to required. none, auto, and required pass through unchanged.
tool_choice with no toolstool_choice not valid without toolsRemoved from the request body
reasoning_effort other than none or highOnly none or highRemoved from the request body
パス /deployments/{modelId}/chat/completionsPath /chat/completions, with the model in the request bodyPath rewritten. The model ID from the path is set as model in the body.
Deployment-style /embeddings and /models paths/embeddings ] と [ /modelsPaths rewritten
API key in the api-key headerAPI key in the Authorization: Bearer <your-api-key> headerAuthorization header added

The postRequest hook normalizes chat completion responses from Cohere to the strict OpenAI schema that AI Trust Layer expects:

  • Converts message.content to a string when Cohere returns it as an array or an object
  • Sets message.role to assistant when the role is missing
  • Keeps only the first choice
  1. コネクタ ビルダーで [ フック ] セクションを開き、 preRequest フックを選択します。

  2. フック本体全体を次のスクリプトに置き換えます。

    // Native Cohere connector pre-request normalization.
    const _cfg = (typeof configuration !== 'undefined' && configuration) ? configuration : {};
    const _reqPath = (typeof request_path !== 'undefined' && request_path) ? request_path : '';
    const _reqVendorPath = (typeof request_vendor_path !== 'undefined' && request_vendor_path) ? request_vendor_path : '';
    const _headers = (typeof request_vendor_headers !== 'undefined' && request_vendor_headers) ? request_vendor_headers : {};
    let _body = (typeof request_vendor_body !== 'undefined' && request_vendor_body !== undefined) ? request_vendor_body : (typeof request_body !== 'undefined' ? request_body : undefined);
    
    const apiKey = _cfg['api-key'] || _cfg['oauth.api.key'] || '';
    if (apiKey) {
        _headers['Authorization'] = apiKey.startsWith('Bearer ') ? apiKey : ('Bearer ' + apiKey);
    }
    _headers['Accept'] = _headers['Accept'] || 'application/json';
    _headers['Content-Type'] = _headers['Content-Type'] || 'application/json';
    
    if (typeof _body === 'string') {
        try { _body = JSON.parse(_body); } catch (e) { /* leave as-is */ }
    }
    
    const isChat = _reqPath.indexOf('/chat/completions') !== -1 || _reqVendorPath.indexOf('/chat/completions') !== -1;
    const isModels = _reqPath.indexOf('/models') !== -1 || _reqVendorPath.indexOf('/models') !== -1;
    const isEmbeddings = _reqPath.indexOf('/embeddings') !== -1 || _reqVendorPath.indexOf('/embeddings') !== -1;
    
    function extractModelId(path) {
        if (!path || typeof path !== 'string') return '';
        var m = path.match(/\/deployments\/([^\/]+)\//i);
        return (m && m[1]) ? decodeURIComponent(m[1]) : '';
    }
    
    if (_body && typeof _body === 'object') {
        const unsupported = ['parallel_tool_calls','store','metadata','logit_bias','top_logprobs','n','modalities','prediction','audio','service_tier'];
        unsupported.forEach(function (key) {
            if (Object.prototype.hasOwnProperty.call(_body, key)) delete _body[key];
        });
    
        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;
        }
    
        if (Object.prototype.hasOwnProperty.call(_body, 'reasoning_effort')) {
            const r = String(_body.reasoning_effort || '').toLowerCase();
            if (r !== 'none' && r !== 'high') delete _body.reasoning_effort;
        }
    
        const modelId = _body.model || _cfg.model || _cfg['model'] || extractModelId(_reqVendorPath) || extractModelId(_reqPath);
        if ((isChat || isEmbeddings) && modelId && !Object.prototype.hasOwnProperty.call(_body, 'model')) {
            _body.model = modelId;
        }
    
        const hasTools = Array.isArray(_body.tools) && _body.tools.length > 0;
        if (hasTools) {
            if (typeof _body.tool_choice === 'string') {
                const tc = _body.tool_choice.toLowerCase();
                if (tc === 'none') _body.tool_choice = 'none';
                else if (tc === 'required' || tc === 'any') _body.tool_choice = 'required';
                else if (tc === 'auto') _body.tool_choice = 'auto';
                else _body.tool_choice = 'required';
            } else if (Object.prototype.hasOwnProperty.call(_body, 'tool_choice')) {
                _body.tool_choice = 'required';
            }
        } else if (Object.prototype.hasOwnProperty.call(_body, 'tool_choice')) {
            delete _body.tool_choice;
        }
    }
    
    const out = { request_vendor_headers: _headers };
    if (isChat) out.request_vendor_path = '/chat/completions';
    if (isModels) out.request_vendor_path = '/models';
    if (isEmbeddings) out.request_vendor_path = '/embeddings';
    if (_body !== undefined) out.request_vendor_body = _body;
    
    done(out);
    // Native Cohere connector pre-request normalization.
    const _cfg = (typeof configuration !== 'undefined' && configuration) ? configuration : {};
    const _reqPath = (typeof request_path !== 'undefined' && request_path) ? request_path : '';
    const _reqVendorPath = (typeof request_vendor_path !== 'undefined' && request_vendor_path) ? request_vendor_path : '';
    const _headers = (typeof request_vendor_headers !== 'undefined' && request_vendor_headers) ? request_vendor_headers : {};
    let _body = (typeof request_vendor_body !== 'undefined' && request_vendor_body !== undefined) ? request_vendor_body : (typeof request_body !== 'undefined' ? request_body : undefined);
    
    const apiKey = _cfg['api-key'] || _cfg['oauth.api.key'] || '';
    if (apiKey) {
        _headers['Authorization'] = apiKey.startsWith('Bearer ') ? apiKey : ('Bearer ' + apiKey);
    }
    _headers['Accept'] = _headers['Accept'] || 'application/json';
    _headers['Content-Type'] = _headers['Content-Type'] || 'application/json';
    
    if (typeof _body === 'string') {
        try { _body = JSON.parse(_body); } catch (e) { /* leave as-is */ }
    }
    
    const isChat = _reqPath.indexOf('/chat/completions') !== -1 || _reqVendorPath.indexOf('/chat/completions') !== -1;
    const isModels = _reqPath.indexOf('/models') !== -1 || _reqVendorPath.indexOf('/models') !== -1;
    const isEmbeddings = _reqPath.indexOf('/embeddings') !== -1 || _reqVendorPath.indexOf('/embeddings') !== -1;
    
    function extractModelId(path) {
        if (!path || typeof path !== 'string') return '';
        var m = path.match(/\/deployments\/([^\/]+)\//i);
        return (m && m[1]) ? decodeURIComponent(m[1]) : '';
    }
    
    if (_body && typeof _body === 'object') {
        const unsupported = ['parallel_tool_calls','store','metadata','logit_bias','top_logprobs','n','modalities','prediction','audio','service_tier'];
        unsupported.forEach(function (key) {
            if (Object.prototype.hasOwnProperty.call(_body, key)) delete _body[key];
        });
    
        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;
        }
    
        if (Object.prototype.hasOwnProperty.call(_body, 'reasoning_effort')) {
            const r = String(_body.reasoning_effort || '').toLowerCase();
            if (r !== 'none' && r !== 'high') delete _body.reasoning_effort;
        }
    
        const modelId = _body.model || _cfg.model || _cfg['model'] || extractModelId(_reqVendorPath) || extractModelId(_reqPath);
        if ((isChat || isEmbeddings) && modelId && !Object.prototype.hasOwnProperty.call(_body, 'model')) {
            _body.model = modelId;
        }
    
        const hasTools = Array.isArray(_body.tools) && _body.tools.length > 0;
        if (hasTools) {
            if (typeof _body.tool_choice === 'string') {
                const tc = _body.tool_choice.toLowerCase();
                if (tc === 'none') _body.tool_choice = 'none';
                else if (tc === 'required' || tc === 'any') _body.tool_choice = 'required';
                else if (tc === 'auto') _body.tool_choice = 'auto';
                else _body.tool_choice = 'required';
            } else if (Object.prototype.hasOwnProperty.call(_body, 'tool_choice')) {
                _body.tool_choice = 'required';
            }
        } else if (Object.prototype.hasOwnProperty.call(_body, 'tool_choice')) {
            delete _body.tool_choice;
        }
    }
    
    const out = { request_vendor_headers: _headers };
    if (isChat) out.request_vendor_path = '/chat/completions';
    if (isModels) out.request_vendor_path = '/models';
    if (isEmbeddings) out.request_vendor_path = '/embeddings';
    if (_body !== undefined) out.request_vendor_body = _body;
    
    done(out);
    
  3. Select the postRequest hook for chat completions.

  4. フック本体全体を次のスクリプトに置き換えます。

    // Native Cohere connector post-request normalization.
    if (response_iserror) { done(); return; }
    
    let body = response_body;
    if (typeof body === 'string') {
        try { body = JSON.parse(body); } catch (e) { done(); return; }
    }
    
    function contentToString(content) {
        if (content == null) return '';
        if (typeof content === 'string') return content;
        if (Array.isArray(content)) {
            return content.map(function (part) {
                if (typeof part === 'string') return part;
                if (part && typeof part === 'object') {
                    if (typeof part.text === 'string') return part.text;
                    if (typeof part.content === 'string') return part.content;
                }
                return '';
            }).join('');
        }
        if (typeof content === 'object') {
            if (typeof content.text === 'string') return content.text;
            if (typeof content.content === 'string') return content.content;
        }
        return String(content);
    }
    
    if (body && Array.isArray(body.choices) && body.choices.length > 0) {
        const first = body.choices[0] || {};
        first.index = 0;
        first.message = first.message || {};
        if (!first.message.role) first.message.role = 'assistant';
        first.message.content = contentToString(first.message.content);
        body.choices = [first];
    }
    
    done({ response_body: body });
    // Native Cohere connector post-request normalization.
    if (response_iserror) { done(); return; }
    
    let body = response_body;
    if (typeof body === 'string') {
        try { body = JSON.parse(body); } catch (e) { done(); return; }
    }
    
    function contentToString(content) {
        if (content == null) return '';
        if (typeof content === 'string') return content;
        if (Array.isArray(content)) {
            return content.map(function (part) {
                if (typeof part === 'string') return part;
                if (part && typeof part === 'object') {
                    if (typeof part.text === 'string') return part.text;
                    if (typeof part.content === 'string') return part.content;
                }
                return '';
            }).join('');
        }
        if (typeof content === 'object') {
            if (typeof content.text === 'string') return content.text;
            if (typeof content.content === 'string') return content.content;
        }
        return String(content);
    }
    
    if (body && Array.isArray(body.choices) && body.choices.length > 0) {
        const first = body.choices[0] || {};
        first.index = 0;
        first.message = first.message || {};
        if (!first.message.role) first.message.role = 'assistant';
        first.message.content = contentToString(first.message.content);
        body.choices = [first];
    }
    
    done({ response_body: body });
    
  5. In the connector settings, set Base URL to https://api.cohere.ai/compatibility/v1.

  6. Set Authentication Type to API Key (customApiKey).

  7. [保存] を選択します。

Integration Service でコネクションを作成する​

  1. Integration Service で [ コネクション ] に移動し、[ コネクションを追加] を選択します。
  2. パブリッシュしたカスタム コネクタを選択します。
  3. Enter your Cohere API key.
  4. [ 接続 ] を選択して、コネクションをプロビジョニングします。

Integration Service validates the connection by calling the Cohere /models endpoint.

LLM の設定を完了します​

  1. [管理] > [AI Trust Layer] > [LLM の設定] に戻り、開始した設定を開きます。

  2. Under Model Configuration, set Connector to your published connector.

  3. Set Connection to the connection you created.

  4. In the LLM identifier field, enter the Cohere model ID exactly as Cohere lists it, for example command-a-03-2025.

    注:

    Leading or trailing spaces in the LLM identifier field cause a model-not-found error.

  5. [ 設定をテスト ] を選択して、AI Trust Layer プローブを実行します。

  6. プローブが成功した場合は、 [ 保存] を選択します。

Result: The configuration is saved and the Cohere model is available to UiPath Agents for the product and feature you selected. Calls route through the AI Trust Layer and appear in the audit log under Source: Custom connection.

注:

カスタム コネクタの作成中に問題が発生した場合は、UiPath サポートにお問い合わせください。

このページは役に立ちましたか?

接続

ヘルプ リソース サポート(opens in new window)

学習する UiPath アカデミー(opens in new window)

質問する UiPath フォーラム(opens in new window)

最新情報を取得