Décrivez une fonction pour un modèle d'IA avec un schéma JSON
Le schéma compact que vous écrivez déjà pour input ('*name:String // The name, age:Number') suffit pour décrire une fonction à un modèle d'IA. 0.0.20 ajoute trois conversions :
| Appel | Résultat |
|---|---|
'<schema>'.toJSONSchema().toAITool(name) | Une définition de fonction au format des API de chat : { type: 'function', function: { name, description, parameters } } |
'<schema>'.toJSONSchema().toAIObject(name, description) | Un objet JSON Schema avec name, description, properties et required, pour demander au modèle une sortie structurée |
Total.actions['Name'].toAITool() | L'outil MCP d'une action (nom, description, inputSchema et outputSchema) |
Le texte après // dans un champ devient sa description, que le modèle lit pour décider quoi y mettre. Un champ marqué * va dans required. N'envoyez pas la saisie d'un utilisateur à un modèle comme une instruction : le schéma ne décrit que la forme des arguments.
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 });
}
});