Просмотр исходного кода

Claude: Improve error handling and reporting for tool use

Alessandro Pignotti 6 месяцев назад
Родитель
Сommit
d4f632e76c
2 измененных файлов с 18 добавлено и 6 удалено
  1. 5 4
      src/lib/WebVM.svelte
  2. 13 2
      src/lib/anthropic.js

+ 5 - 4
src/lib/WebVM.svelte

@@ -412,8 +412,8 @@
 							// Delay at most 3 times
 							if(delayCount < 3)
 							{
-								// TODO: Defensive check, validate and remove
-								debugger;
+								// TODO: Defensive message, validate and remove
+								console.warn("Identical screenshot, rate limiting");
 								delayCount++;
 								// Wait some time and retry
 								await new Promise(function(f, r) { setTimeout(f, 5000); });
@@ -557,11 +557,12 @@
 					break;
 				}
 			}
-			debugger;
+			return new Error("Error: Invalid action");
 		}
 		else
 		{
-			debugger;
+			// We can get there due to model hallucinations
+			return new Error("Error: Invalid tool syntax");
 		}
 	}
 </script>

+ 13 - 2
src/lib/anthropic.js

@@ -63,13 +63,24 @@ async function sendMessages(handleTool)
 				var commandResponse = await handleTool(c.input);
 				var responseObj = {type: "tool_result", tool_use_id: c.id };
 				if(commandResponse != null)
-					responseObj.content = commandResponse;
+				{
+					if(commandResponse instanceof Error)
+					{
+						console.warn(`Tool error: ${commandResponse.message}`);
+						responseObj.content = commandResponse.message;
+						responseObj.is_error = true;
+					}
+					else
+					{
+						responseObj.content = commandResponse;
+					}
+				}
 				addMessageInternal("user", [responseObj]);
 				sendMessages(handleTool);
 			}
 			else
 			{
-				debugger;
+				console.warn(`Invalid response type: ${c.type}`);
 			}
 		}
 		if(response.stop_reason == "end_turn")