Verwenden von Tools
Um ein Tool verwenden zu können, muss es als Teil des promptStart-Ereignisses in Ihrer Sitzungskonfiguration definiert werden. Dies wird im folgenden Code gezeigt:
{ "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": "{}" } } } ] } } } }
Tool-Definitionskomponenten
Für jede Tool-Spezifikation sind die folgenden Elemente erforderlich:
-
Name – eine eindeutige Kennung für das Tool
-
Beschreibung – Eine Erklärung, was das Tool macht und wann es verwendet werden sollte.
-
Eingabeschema – Das JSON-Schema, das die erforderlichen Parameter definiert.
Beispiel für ein grundlegendes Tool
Hier ist ein Beispiel für ein einfaches Tool, das Informationen zum aktuellen Datum abruft. Weitere Informationen über das Definieren eines Tools finden Sie unter Definieren eines Tools.
// 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: [] }) } } };
Und so würde das promptStart-Ereignis aussehen:
{ 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: [] }) } } } ] } } } }