Total.js ForgeTotal.js 5
Čeština

Total.js 5

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

Total.js 5 · total5@0.0.20 aischemamcp

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ů.

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