Describe una función para un modelo de IA con un esquema JSON
El esquema compacto que ya escribes para input ('*name:String // The name, age:Number') basta para describir una función a un modelo de IA. 0.0.20 añade tres conversiones:
| Llamada | Resultado |
|---|---|
'<schema>'.toJSONSchema().toAITool(name) | Una definición de función con la forma de las APIs de chat: { type: 'function', function: { name, description, parameters } } |
'<schema>'.toJSONSchema().toAIObject(name, description) | Un objeto JSON Schema con name, description, properties y required, para pedirle al modelo una salida estructurada |
Total.actions['Name'].toAITool() | La herramienta MCP de una acción (nombre, descripción, inputSchema y outputSchema) |
El texto que sigue a // en un campo se convierte en su description, que es lo que lee el modelo para decidir qué poner ahí. Un campo marcado con * pasa a required. No envíes al modelo la entrada de un usuario como si fuera una instrucción: el esquema solo describe la forma de los argumentos.
exports.install = function() {
ROUTE('GET /tool/', tool);
ROUTE('GET /object/', object);
ROUTE('GET /action/', action);
};
const SCHEMA = '*city:String // The name of the city, unit:String // celsius or fahrenheit';
function tool($) {
$.json(SCHEMA.toJSONSchema().toAITool('weather'));
}
function object($) {
$.json(SCHEMA.toJSONSchema().toAIObject('weather', 'The weather of a city'));
}
function action($) {
$.json(Total.actions['Weather/get'].toAITool());
}NEWACTION('Weather/get', {
name: 'Get the weather',
summary: 'Returns the weather of a city',
input: '*city:String // The name of the city',
action: function($, model) {
$.callback({ city: model.city, temperature: 21 });
}
});