Descrivi una funzione a un modello IA con uno schema JSON
Lo schema compatto che scrivi già per input ('*name:String // The name, age:Number') basta per descrivere una funzione a un modello IA. 0.0.20 aggiunge tre conversioni:
| Chiamata | Risultato |
|---|---|
'<schema>'.toJSONSchema().toAITool(name) | Una definizione di funzione nel formato delle API di chat: { type: 'function', function: { name, description, parameters } } |
'<schema>'.toJSONSchema().toAIObject(name, description) | Un oggetto JSON Schema con name, description, properties e required, per chiedere al modello un output strutturato |
Total.actions['Name'].toAITool() | Lo strumento MCP di un'azione (nome, descrizione, inputSchema e outputSchema) |
Il testo dopo // in un campo diventa la sua description, che è ciò che il modello legge per decidere cosa inserirvi. Un campo contrassegnato con * va in required. Non inviare a un modello l'input di un utente come se fosse un'istruzione: lo schema descrive soltanto la forma degli argomenti.
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 });
}
});