Total.js ForgeTotal.js 5
Nederlands

Total.js 5

Beschrijf een functie voor een AI-model met een JSON-schema

Total.js 5 · total5@0.0.20 aischemamcp

Het compacte schema dat je al voor input schrijft ('*name:String // The name, age:Number') is genoeg om een functie aan een AI-model te beschrijven. 0.0.20 voegt drie omzettingen toe:

AanroepResultaat
'<schema>'.toJSONSchema().toAITool(name)Een functiedefinitie in de vorm van de chat-API's: { type: 'function', function: { name, description, parameters } }
'<schema>'.toJSONSchema().toAIObject(name, description)Een JSON Schema-object met name, description, properties en required, om het model om gestructureerde uitvoer te vragen
Total.actions['Name'].toAITool()De MCP-tool van een actie (naam, beschrijving, inputSchema en outputSchema)

De tekst na // in een veld wordt zijn description, en dat leest het model om te beslissen wat het invult. Een veld met * komt in required. Stuur de invoer van een gebruiker niet als instructie naar een model: het schema beschrijft alleen de vorm van de argumenten.

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