# Opisz funkcję dla modelu AI za pomocą schematu JSON

> Zamień kompaktowy schemat Total.js na narzędzie lub definicję obiektu, której oczekuje model AI, za pomocą toAITool() i toAIObject(), i pozwól akcji utworzyć własne narzędzie MCP.

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

Kompaktowy schemat, który już piszesz dla `input` (`'*name:String // The name, age:Number'`), wystarcza do opisania funkcji modelowi AI. `0.0.20` dodaje trzy konwersje:

| Wywołanie | Wynik |
|---|---|
| `'<schema>'.toJSONSchema().toAITool(name)` | Definicja funkcji w kształcie API czatu: `{ type: 'function', function: { name, description, parameters } }` |
| `'<schema>'.toJSONSchema().toAIObject(name, description)` | Obiekt JSON Schema z `name`, `description`, `properties` i `required`, aby poprosić model o ustrukturyzowane wyjście |
| `Total.actions['Name'].toAITool()` | Narzędzie MCP akcji (nazwa, opis, `inputSchema` i `outputSchema`) |

Tekst po `//` w polu staje się jego `description`, które model czyta, aby zdecydować, co tam wpisać. Pole oznaczone `*` trafia do `required`. Nie wysyłaj modelowi danych użytkownika jako instrukcji: schemat opisuje tylko kształt argumentów.

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