Opíš funkciu pre model AI pomocou schémy JSON
Kompaktná schéma, ktorú už píšeš pre input ('*name:String // The name, age:Number'), stačí na opis funkcie pre model AI. 0.0.20 pridáva tri konverzie:
| Volanie | Výsledok |
|---|---|
'<schema>'.toJSONSchema().toAITool(name) | Definícia funkcie v tvare chatových API: { type: 'function', function: { name, description, parameters } } |
'<schema>'.toJSONSchema().toAIObject(name, description) | Objekt JSON Schema s name, description, properties a required, aby si od modelu vyžiadal štruktúrovaný výstup |
Total.actions['Name'].toAITool() | Nástroj MCP akcie (názov, popis, inputSchema a outputSchema) |
Text za // v poli sa stane jeho description, ktorý model číta, aby rozhodol, čo tam doplní. Pole označené * ide do required. Neposielaj modelu vstup používateľa ako inštrukciu: schéma opisuje iba tvar argumentov.
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 });
}
});