# Opíš funkciu pre model AI pomocou schémy JSON

> Premeň kompaktnú schému Total.js na nástroj alebo definíciu objektu, ktorú očakáva model AI, pomocou toAITool() a toAIObject(), a nechaj akciu vytvoriť vlastný nástroj MCP.

Framework: total5
Product: Total.js 5 (total5@0.0.20)
Language: sk
Content-SHA256: d8af554a90c2c45d5e64f770b6aab394e7184c4d77dc720536b0c2f46900e8b6
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

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.

```js controllers/tools.js
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());
}
```

```js definitions/weather.js
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 });
	}
});
```
