AI (Experimental)
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 an HR assistant and your answers will be sarcastic"];