# Popiš funkci pro model AI pomocí schématu JSON

> Změň kompaktní schéma Total.js na nástroj nebo definici objektu, kterou očekává model AI, pomocí toAITool() a toAIObject(), a nech akci vytvořit vlastní nástroj MCP.

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

Kompaktní schéma, které už píšeš pro `input` (`'*name:String // The name, age:Number'`), stačí k popisu funkce pro model AI. `0.0.20` přidává tři převody:

| Volání | Výsledek |
|---|---|
| `'<schema>'.toJSONSchema().toAITool(name)` | Definice funkce ve tvaru chatových API: `{ type: 'function', function: { name, description, parameters } }` |
| `'<schema>'.toJSONSchema().toAIObject(name, description)` | Objekt JSON Schema s `name`, `description`, `properties` a `required`, abys po modelu mohl chtít strukturovaný výstup |
| `Total.actions['Name'].toAITool()` | Nástroj MCP akce (název, popis, `inputSchema` a `outputSchema`) |

Text za `//` v poli se stane jeho `description`, který model čte, aby se rozhodl, co tam doplní. Pole označené `*` jde do `required`. Neposílej modelu vstup uživatele jako instrukci: schéma popisuje jen tvar argumentů.

```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 });
	}
});
```
