UNPKG

json-object-editor

Version:

JOE the Json Object Editor | Platform Edition

95 lines (86 loc) 3.36 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.", //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;