From ddee6aecfb9d3449ddf87dfd91f76fa169d1656f Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Wed, 16 Oct 2024 16:41:53 -0700 Subject: [PATCH] Tools: edit invocation/responses --- .../DocAttachmentFragment.tsx | 2 +- .../BlockEdit_TextFragment.tsx | 6 +- .../fragments-content/ContentFragments.tsx | 102 +++++++++++------- 3 files changed, 69 insertions(+), 41 deletions(-) diff --git a/src/apps/chat/components/message/fragments-attachment-doc/DocAttachmentFragment.tsx b/src/apps/chat/components/message/fragments-attachment-doc/DocAttachmentFragment.tsx index 7dd75b9b0..fb6fd4727 100644 --- a/src/apps/chat/components/message/fragments-attachment-doc/DocAttachmentFragment.tsx +++ b/src/apps/chat/components/message/fragments-attachment-doc/DocAttachmentFragment.tsx @@ -258,7 +258,7 @@ export function DocAttachmentFragment(props: { {isEditing ? ( // Document Editor {props.inputLabel} : undefined} placeholder={'Edit the message...'} minRows={1.5} // unintuitive onFocus={() => setIsFocused(true)} diff --git a/src/apps/chat/components/message/fragments-content/ContentFragments.tsx b/src/apps/chat/components/message/fragments-content/ContentFragments.tsx index ddf52be0e..aea6281c2 100644 --- a/src/apps/chat/components/message/fragments-content/ContentFragments.tsx +++ b/src/apps/chat/components/message/fragments-content/ContentFragments.tsx @@ -141,16 +141,42 @@ export function ContentFragments(props: { if (!isContentFragment(fragment)) return null; - // editing for text parts - if (props.textEditsState && !!props.setEditedText && (isTextPart(fragment.part) || fragment.part.pt === 'error')) { + // simplify + const { fId, part } = fragment; + + // Determine the text to edit based on the part type + let editText = ''; + let editLabel; + if (isTextPart(part)) + editText = part.text; + else if (part.pt === 'error') + editText = part.error; + else if (part.pt === 'tool_invocation') { + if (part.invocation.type === 'function_call') { + editText = part.invocation.args /* string | null */ || ''; + editLabel = `[Invocation] Function Call: \`${part.invocation.name}\``; + } else { + editText = part.invocation.code; + editLabel = `[Invocation] Code Execution: \`${part.invocation.language}\``; + } + } else if (part.pt === 'tool_response') { + if (!part.error) { + editText = part.response.result; + editLabel = `[Response]: ${part.response.type === 'function_call' ? 'Function Call' : 'Code Execution'}: \`${part.id}\``; + } + } + + // editing for text parts, tool invocations, or tool responses + if (props.textEditsState && !!props.setEditedText && (isTextPart(part) || part.pt === 'error' || part.pt === 'tool_invocation' || part.pt === 'tool_response')) { return ( @@ -174,9 +200,9 @@ export function ContentFragments(props: { case 'image_ref': return ( - {fragment.part.invocation.type === 'function_call' ? ( + + {part.invocation.type === 'function_call' ? (
Id
-
{fragment.part.id}
+
{part.id}
Name
-
{fragment.part.invocation.name}
+
{part.invocation.name}
Args
-
{fragment.part.invocation.args/*?.replaceAll('{', '').replaceAll('}', '').replaceAll('","', '", "')*/}
+
{part.invocation.args/*?.replaceAll('{', '').replaceAll('}', '').replaceAll('","', '", "')*/}
) : (
Id
-
{fragment.part.id}
+
{part.id}
Language
-
{fragment.part.invocation.language}
+
{part.invocation.language}
Code
-
{fragment.part.invocation.code?.trim()}
+
{part.invocation.code?.trim()}
Author
-
{fragment.part.invocation.author}
+
{part.invocation.author}
)}
@@ -263,8 +289,8 @@ export function ContentFragments(props: { case 'tool_response': return ( - - {fragment.part.response.type === 'function_call' ? ( + + {part.response.type === 'function_call' ? ( Type
Function Call Response
Id
-
{fragment.part.id}
+
{part.id}
Error
-
{fragment.part.error === null ? 'null' : fragment.part.error === 'false' ? '' : fragment.part.error}
+
{part.error === null ? 'null' : part.error === 'false' ? '' : part.error}
Name
-
{fragment.part.response.name}
+
{part.response.name}
Result
-
{fragment.part.response.result}
+
{part.response.result}
Environment
-
{fragment.part.environment}
+
{part.environment}
) : ( Type
Code Execution Response
Id
-
{fragment.part.id}
+
{part.id}
Error
-
{fragment.part.error === null ? 'null' : fragment.part.error === 'false' ? '' : fragment.part.error}
+
{part.error === null ? 'null' : part.error === 'false' ? '' : part.error}
Result
-
{fragment.part.response.result}
+
{part.response.result}
Executor
-
{fragment.part.response.executor}
+
{part.response.executor}
Environment
-
{fragment.part.environment}
+
{part.environment}
)}
@@ -330,8 +356,8 @@ export function ContentFragments(props: { default: return (