UNPKG

json-object-editor

Version:

JOE the Json Object Editor | Platform Edition

125 lines (116 loc) 4.88 kB
// Joe AI Tool Schema // This schema defines reusable tools for OpenAI Assistants and Chat Completions. // Each tool includes a JSON schema for function calling and an executable code block. var schema = { title: "Ai Tool | ${name}", display: "Ai Tool", info: "Reusable Ai tool function for OpenAI tool calling and local execution.", summary:{ description:'Definition of a reusable AI tool (function) that can be called by OpenAI assistants or prompts.', purpose:'Use ai_tool to describe function-calling tools (name, parameters) and optional server-side execution code that JOE can invoke when OpenAI calls the tool.', labelField:'name', defaultSort:{ field:'name', dir:'asc' }, searchableFields:['name','info','description','tool_id','datasets','tags'], allowedSorts:['name','joeUpdated','created'], relationships:{ outbound:[ { field:'datasets', targetSchema:'<schemaName>', cardinality:'many' }, { field:'tags', targetSchema:'tag', cardinality:'many' } ], inbound:{ graphRef:'server/relationships.graph.json' } }, joeManagedFields:['created','joeUpdated'], fields:[ { name:'_id', type:'string', required:true }, { name:'itemtype', type:'string', required:true, const:'ai_tool' }, { name:'name', type:'string', required:true }, { name:'info', type:'string' }, { name:'description', type:'string' }, { name:'tool_id', type:'string' }, { name:'tool_properties', type:'string' }, { name:'server_code', type:'string' }, { name:'tags', type:'string', isArray:true, isReference:true, targetSchema:'tag' }, { name:'datasets', type:'string', isArray:true }, { name:'joeUpdated', type:'string', format:'date-time' }, { name:'created', type:'string', format:'date-time' } ] }, //menuicon: `<svg viewBox="0 0 24 24"><path d="M3 6h18M3 12h18M3 18h18"/></svg>`, listView: { title: '<joe-title>${name}</joe-title><joe-subtitle>${info}</joe-subtitle>', listWindowTitle: 'Ai Tools' }, methods:{ updateToolProperties:function(propObj){ //get the current tool properties as json // set the tool_properties.name to the passed current objects tool_id let rawProps = _jco(true).tool_properties ||"{}"; var toolProperties = eval('('+rawProps+')')||{}; toolProperties.type = 'function'; toolProperties.function = Object.assign({ description:'', parameters:{ type:'object', properties:{} } },toolProperties.function,{name:propObj.name}); //toolProperties.function.name = propObj.name; _joe.Fields.set('tool_properties',JSON.stringify(toolProperties,'\n','\t')); } }, fields: function() { return [ "name", "info", // Unique identifier "description", // Short tool description {name:'tool_id', type:'text', display:'Tool ID', comment:'Unique identifier for the tool. Used in OpenAI function calling.',onblur:"_joe.schemas.ai_tool.methods.updateToolProperties({name:this.value});"}, { section_start: "schema", display: "OpenAI Tool Schema" }, { name: "tool_properties", type: "code", display: "Tool Properties (OpenAI format)", height: "300px", language: "json", comment: `<div>Define the tool funcitonal properties as used in OpenAI tool calling.</div> <a href="https://platform.openai.com/docs/guides/gpt/function-calling?api-mode=chat" target="_blank">OpenAI Function Calling</a><br/> <pre>{ "type": "function", "function": { "name": "findBusinessLinks", "description": "Find relevant links for a business.", "parameters": { "type": "object", "properties": { "business_name": { "type": "string" }, "website": { "type": "string", "format": "uri" } }, "required": ["business_name", "website"] } } }</pre>` }, { section_end: "schema" }, { section_start: "execution", display: "Server Execution" }, { name: "server_code", type: "code", display: "Code to Execute (Node.js async)", height: "300px", comment: "Use `args` as input. Return a string, object, or promise.<br/>e.g. <code>return await joe.search(args.dataset, args.query);</code>" }, { section_end: "execution" }, { section_start: "meta", collapsed: true }, "tags", "datasets", { section_end: "meta" }, { section_start: "system", collapsed: true }, "_id", "created", "itemtype", { section_end: "system" } ]; }, idprop: "_id" }; module.exports = schema;