Beschrijf een functie voor een AI-model met een JSON-schema
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:
| Aanroep | Resultaat |
|---|---|
'<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.
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 });
}
});