Show / Hide Table of Contents

AI

To have AI in your organizational chart, it is enough enableAI to be true

 
 
 let chart = new OrgChart(document.getElementById("tree"), {
    enableAI: true,
    ...
 });
             

You can try the following prompts:

  • Add new employee Ivan under Ruby
  • How many employees?
  • Increase the salary of Amelia with little
  • Highlight sales

Customization

Here is an example that can send a message to a given employee:.


How we achieve this?

In aiChatTools we give an array of functions to the AI with these parameters:

  • functionName - The function's name
  • functionDescription - A comprehensive explanation of the function's purpose and capabilities.
  • functionParameters - JSON schema defining the function's input arguments
 
     
    let chart = new OrgChart(document.getElementById("tree"), {
        enableAI: true,
        aiChatTools: [{
                functionName: 'sendEmail',        
                functionDescription: 'Send an email to a given employee with a subject and message.',        
                functionParameters: {
                    type: "object",
                    properties: {
                        to: {
                            type: "string",
                            description: "The employee email address."
                        },
                        subject: {
                            type: "string",
                            description: "Email subject line."
                        },
                        body: {
                            type: "string",
                            description: "Body of the email message."
                        }
                    },
                    required: [
                        "to",
                        "subject",
                        "body"
                    ]
                },
                strict: true
        }]
        ...
    });
             

Then in onAIToolCalls we parse the responce with all the objects having a

FunctionName and FunctionArguments to our functions:
 
     
    function sendEmail(args){
        window.location.href = 
            `mailto:${args.to}&subject=${encodeURI(args.subject)}&body=${encodeURI(args.body)}`;
        return 'ok';
    }

    chart.onAIToolCalls(function(args){    
        for(var toolCall of args.toolCalls){
            if (toolCall.FunctionName == 'sendEmail'){
                toolCall.FunctionResult = sendEmail(toolCall.FunctionArguments);
            }   
        }    
    });

    chart.load(nodes)
             
For a given prompt "Send an email to Denny asking for a meeting",here is the result:

System instructions

By giving the model system instructions, you provide the model additional context to understand the task and generate more customized responses.

 
     
    OrgChart.AI_SYSTEM_MESSAGES = ["You are acting as Microsoft's HR assistant."];
 

Server JS
  • The data is not used for training the AI model.
  • If you don’t want to send data, install the Server JS locally.

Server JS Installation

1) Install Server JS on your server

  • Install Server JS ( see installation instructions ).
  • Configure appsettings.json:

      {
      "OpenAIEndPoint": "https://api.openai.com/v1",
      "OpenAIApiKey": "YOUR_OPENAI_API_KEY"
    }

2) Point OrgChart JS to your Server JS

Add the serverUrl option in the OrgChart JS configuration:

  
// Example OrgChart JS initialization
let chart = new OrgChart({
  // ...your existing options...
  serverUrl: "https://your-server-js.example.com" // Your Server JS base URL
});

Replace YOUR_OPENAI_API_KEY and https://your-server-js.example.com with your actual values.