Zenera Logo

When working with transforms in Zenera, you can import functions to process input data and shape it into the desired output. Zenera offers two ways to import functions:

  • Using the import statement: you can pull in functions defined in the dialog script. Imported functions can be used to process data or apply specific logic as part of the query transformation.
  • Using EJS (Embedded JavaScript): you can embed a function output directly in the transform instruction using EJS.

Import statement

Assume you want to import a function that returns a list of all cloud services from the database. To do this, you need to:

  1. Define the getServices() function with the JSDOC description in the dialog script:
    async function getData() {
        // Make the GET request to fetch virtual infrastructure data from the database
        // ...
    }
    
    /**
    * @tool: Returns an array containing cloud services
    * @param:
    * @return: An array with a short description of objects with the following fields:
    * [
    *     {
    *         "errorRate": "Percentage representing the error rate",
    *         "id": "Unique identifier for the cloud service",
    *         "lastCheck": "ISO formatted date and time of the last status check",
    *         "name": "Name of the cloud service",
    *         "responseTime": "Average response time in milliseconds",
    *         "status": "Current status of the cloud service (e.g., operational, degraded)",
    *         "uptime": "Percentage representing the service uptime"
    *     },
    *     ...
    * ]
    */
    async function getServices() {
        const data = await getData();
        console.log(data.cloudServices);
        return data.cloudServices;
    }
  2. Import the getServices() function in the general instruction of the query transform.
  3. Provide a description in natural language how to use this function to get the desired output.
  4. Add a dynamic corpus to use the created query transform:
    corpus({
        title: `Infrastructure requests`,
        query: transforms.query,
        priority: 1
    });

EJS

Zenera supports embedding function outputs directly into the transform instruction using EJS. To do this, use the <%- %> tag, which inserts content directly into the output without escaping.

Assume you want the AI-Native Interface to answer questions about common cloud abbreviations. You can:

  1. Add a function to return a list of abbreviations and their definitions:
    function getCloudAbbreviations() {
        return `
            API, or Application Programming Interface, is a set of protocols and tools...
            CDN, or Content Delivery Network, is a distributed network of servers...
            DNS, or Domain Name System, is a service that translates human-readable domain names...
        `
    }
  2. Import the getCloudAbbreviations() function in the general instruction of the query transform using the EJS syntax:
    <%- getCloudAbbreviations() %>
  3. Provide a description in natural language how to use this function to get the desired output.
  4. Add a dynamic corpus to use the created query transform:
    corpus({
        title: `Abbreviation requests`,
        query: transforms.query,
        priority: 1
    });