Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How should the header be configured in the generative AI custom LLM Transformer?

Perry4
Tera Contributor

I configured a generic large language model (LLM) connector, but for the Authorization part in the header, I have to either set it as a fixed value or use a script to query. I believe that after the authentication has been configured, there should no longer be a need to query the apikey in the AI custom LLM Transformer. Could you please tell me exactly how to configure it so that I don't need to use a script to obtain the API key?

my generative AI custom LLM Transformer request transformer :

(function(inputs) {
    /* write code here to construct the request body and any custom headers needed using the inputs object.
    inputs structure: {
        prompt_data: object,
        request_data: object
    } */
    var requestData = inputs.request_data;
    var promptData = inputs.prompt_data;
    var prompt = promptData.prompt;
    var model = promptData.model;

    // construct body using the inputs    
    var body = {
        "model": model,
        "messages": [{
            "role": "user",
            "content": prompt
        }],
        "stream": false
    };
    var apikey = "Bearer ";
    var provider = new sn_cc.ConnectionInfoProvider();
    // Replace 'MyExternalServiceAPI' with the actual ID of your Connection & Credential Alias
    var connectionInfo = provider.getConnectionInfo('XXXXXX');
 
    if (connectionInfo) {
        // Access the API key securely
        apiKey = apikey + connectionInfo.getCredentialAttribute('api_key');
        var headers = {
            "Authorization": apiKey,
            "Content-Type": "application/json"
        };
       
        return {
            body: body,
            headers: headers
        };
    } else {
        gs.error('Connection & Credential Alias not found or invalid.');
    }

 

})(inputs);
0 REPLIES 0