Опишете функция за ИИ модел със схема JSON
Компактната схема, която вече пишете за input ('*name:String // The name, age:Number'), е достатъчна, за да опишете функция на ИИ модел. 0.0.20 добавя три преобразувания:
| Извикване | Резултат |
|---|---|
'<schema>'.toJSONSchema().toAITool(name) | Дефиниция на функция във вида на чат API: { type: 'function', function: { name, description, parameters } } |
'<schema>'.toJSONSchema().toAIObject(name, description) | Обект JSON Schema с name, description, properties и required, за да поискате от модела структуриран изход |
Total.actions['Name'].toAITool() | MCP инструментът на действие (име, описание, inputSchema и outputSchema) |
Текстът след // в поле става негово description, което моделът чете, за да реши какво да попълни. Поле, маркирано с *, влиза в required. Не изпращайте входа на потребител към модел като инструкция: схемата описва само формата на аргументите.
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 });
}
});