Descrie o funcție pentru un model de IA cu o schemă JSON
Schema compactă pe care o scrii deja pentru input ('*name:String // The name, age:Number') este suficientă pentru a descrie o funcție unui model de IA. 0.0.20 adaugă trei conversii:
| Apel | Rezultat |
|---|---|
'<schema>'.toJSONSchema().toAITool(name) | O definiție de funcție în forma API-urilor de chat: { type: 'function', function: { name, description, parameters } } |
'<schema>'.toJSONSchema().toAIObject(name, description) | Un obiect JSON Schema cu name, description, properties și required, pentru a cere modelului o ieșire structurată |
Total.actions['Name'].toAITool() | Instrumentul MCP al unei acțiuni (nume, descriere, inputSchema și outputSchema) |
Textul de după // dintr-un câmp devine description-ul lui, adică ceea ce citește modelul ca să decidă ce să pună acolo. Un câmp marcat cu * intră în required. Nu trimite intrarea unui utilizator unui model ca instrucțiune: schema descrie doar forma argumentelor.
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 });
}
});