# Опишете функция за ИИ модел със схема JSON

> Превърнете компактна схема на Total.js в инструмента или дефиницията на обект, които очаква ИИ модел, с toAITool() и toAIObject(), и оставете действие да създаде свой собствен MCP инструмент.

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

Компактната схема, която вече пишете за `input` (`'*name:String // The name, age:Number'`), е достатъчна, за да опишете функция на ИИ модел. `0.0.20` добавя три преобразувания:

| Извикване | Резултат |
|---|---|
| `'<schema>'.toJSONSchema().toAITool(name)` | Дефиниция на функция във вида на чат API: `{ type: 'function', function: { name, description, parameters } }` |
| `'<schema>'.toJSONSchema().toAIObject(name, description)` | Обект JSON Schema с `name`, `description`, `properties` и `required`, за да поискате от модела структуриран изход |
| `Total.actions['Name'].toAITool()` | MCP инструментът на действие (име, описание, `inputSchema` и `outputSchema`) |

Текстът след `//` в поле става негово `description`, което моделът чете, за да реши какво да попълни. Поле, маркирано с `*`, влиза в `required`. Не изпращайте входа на потребител към модел като инструкция: схемата описва само формата на аргументите.

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