From 1063cbb3015c44196d0132179146b78f4f43c369 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Mon, 9 Sep 2024 09:42:02 -0400 Subject: [PATCH] Enhanced debug output for tool call events, including file search. --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- src/helpers.js | 38 ++++++++++++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 424964b..b1af5cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ See this http://keepachangelog.com link for information on how we want this document formatted. +## v1.6.1 + +### Added + +- Enhanced debug output for tool call events, including file search. + ## v1.6.0 ### Changed diff --git a/package-lock.json b/package-lock.json index f9453dd..01bb2d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "experts", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "experts", - "version": "1.6.0", + "version": "1.6.1", "license": "MIT", "dependencies": { "eventemitter2": "^6.4.9", diff --git a/package.json b/package.json index 0e3735e..6b8136f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "experts", - "version": "1.6.0", + "version": "1.6.1", "description": "An opinionated panel of experts implementation using OpenAI's Assistants API", "type": "module", "scripts": { diff --git a/src/helpers.js b/src/helpers.js index 3c63175..76cf1fe 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -11,8 +11,7 @@ const debug = (message) => { const debugEvent = (event) => { if (!DEBUG) return; - if (!DEBUG_EVENTS) return; - if (event.event.includes("delta") && !DEBUG_DELTAS) return; + const eventCopy = JSON.parse(JSON.stringify(event)); if (eventCopy.data && eventCopy.data.instructions) { eventCopy.data.instructions = "[INSTRUCTIONS REMOVED]"; @@ -29,10 +28,37 @@ const debugEvent = (event) => { return tool; }); } - const jsonOutput = DEBUG_PRETTY_JSON - ? JSON.stringify(eventCopy, null, 2) - : JSON.stringify(eventCopy); - debug(`📡 Event: ${jsonOutput}`); + + const isToolCallEvent = eventCopy.data?.step_details?.type === "tool_calls"; + + if (isToolCallEvent) { + const toolCalls = eventCopy.data.step_details.tool_calls; + toolCalls.forEach((toolCall) => { + const emoji = getToolCallEmoji(toolCall.type); + const toolCallData = toolCall[toolCall.type]; + const jsonOutput = DEBUG_PRETTY_JSON + ? JSON.stringify(toolCallData, null, 2) + : JSON.stringify(toolCallData); + debug(`${emoji} Tool Call (${toolCall.type}): ${jsonOutput}`); + }); + } else if (DEBUG_EVENTS) { + if (event.event.includes("delta") && !DEBUG_DELTAS) return; + const jsonOutput = DEBUG_PRETTY_JSON + ? JSON.stringify(eventCopy, null, 2) + : JSON.stringify(eventCopy); + debug(`📡 Event: ${jsonOutput}`); + } +}; + +const getToolCallEmoji = (toolType) => { + switch (toolType) { + case "file_search": + return "🧰 🔍"; + case "code_interpreter": + return "🧰 💻"; + default: + return "🧰"; + } }; const messagesContent = (messages) => {