Total.js ForgeTotal.js 5
Deutsch

Total.js 5

Beschreibe eine Funktion für ein KI-Modell mit einem JSON-Schema

Total.js 5 · total5@0.0.20 aischemamcp

Das kompakte Schema, das du schon für input schreibst ('*name:String // The name, age:Number'), genügt, um einem KI-Modell eine Funktion zu beschreiben. 0.0.20 fügt drei Umwandlungen hinzu:

AufrufErgebnis
'<schema>'.toJSONSchema().toAITool(name)Eine Funktionsdefinition in der Form der Chat-APIs: { type: 'function', function: { name, description, parameters } }
'<schema>'.toJSONSchema().toAIObject(name, description)Ein JSON-Schema-Objekt mit name, description, properties und required, um das Modell um eine strukturierte Ausgabe zu bitten
Total.actions['Name'].toAITool()Das MCP-Tool einer Action (Name, Beschreibung, inputSchema und outputSchema)

Der Text nach // in einem Feld wird zu seiner description, und das liest das Modell, um zu entscheiden, was dort eingetragen wird. Ein mit * markiertes Feld kommt in required. Schicke die Eingabe eines Benutzers nicht als Anweisung an ein Modell: Das Schema beschreibt nur die Form der Argumente.

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