Opisz funkcję dla modelu AI za pomocą schematu JSON
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.
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());
}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 });
}
});