Utilizzo degli strumenti
Per poter utilizzare uno strumento, è necessario definirlo come parte dell’evento promptStart nella configurazione della sessione. Questa procedura è illustrata nel seguente codice:
{ "event": { "promptStart": { "promptName": "string", "textOutputConfiguration": { "mediaType": "text/plain" }, "audioOutputConfiguration": { "mediaType": "audio/lpcm", "sampleRateHertz": 8000 | 16000 | 24000, "sampleSizeBits": 16, "channelCount": 1, "voiceId": "matthew" | "tiffany" | "amy", "encoding": "base64", "audioType": "SPEECH" }, "toolUseOutputConfiguration": { "mediaType": "application/json" }, "toolConfiguration": { "tools": [ { "toolSpec": { "name": "string", "description": "string", "inputSchema": { "json": "{}" } } } ] } } } }
Componenti per la definizione degli strumenti
Ogni specifica dello strumento richiede i seguenti elementi:
-
Nome: un identificatore univoco per lo strumento.
-
Descrizione: una spiegazione di cosa fa lo strumento e quando dovrebbe essere usato.
-
Schema di input: lo schema JSON che definisce i parametri richiesti.
Esempio di strumento di base
Ecco un esempio di uno strumento semplice che recupera informazioni sulla data attuale. Per ulteriori informazioni su come definire uno strumento, consulta Defining a tool.
// A simple tool with no required parameters const dateTool = { toolSpec: { name: "getDateTool", description: "Get information about the current date", inputSchema: { json: JSON.stringify({ type: "object", properties: {}, required: [] }) } } };
Ed ecco come apparirebbe l’evento promptStart:
{ event: { promptStart: { promptName: "string", textOutputConfiguration: { mediaType: "text/plain" }, audioOutputConfiguration: { mediaType: "audio/lpcm", sampleRateHertz: 24000, sampleSizeBits: 16, channelCount: 1, voiceId: "tiffany", encoding: "base64", audioType: "SPEECH" }, toolUseOutputConfiguration: { mediaType: "application/json" }, toolConfiguration: { tools: [ { toolSpec: { name: "getDateTool", description: "get information about the current date", inputSchema: { json: JSON.stringify({ type: "object", properties: {}, required: [] }) } } } ] } } } }