Skip to content

Commit

Permalink
Merge pull request #926 from WolframResearch/feature/tool-call-progre…
Browse files Browse the repository at this point in the history
…ss-indicator

Tool call progress indicators
  • Loading branch information
rhennigan authored Nov 15, 2024
2 parents 35db7b3 + d8008d3 commit fb1afb0
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Source/Chatbook/ChatModes/Common.wl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ HoldComplete[
`createWorkspaceChat,
`evaluateAttachedInlineChat,
`findCurrentWorkspaceChat,
`getNotebookAssistanceInput,
`getContextFromSelection,
`getNotebookAssistanceInput,
`getSelectionInfo,
`moveChatInputToBottom,
`moveChatInputToTop,
Expand Down
87 changes: 67 additions & 20 deletions Source/Chatbook/ChatModes/UI.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1812,30 +1812,77 @@ $trashButtonLabel := $trashButtonLabel = chatbookIcon[ "WorkspaceHistoryTrashI
(* ::Section::Closed:: *)
(*Global Progress Bar*)

(* TODO: *)
Grid[
(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*withWorkspaceGlobalProgress*)
withWorkspaceGlobalProgress // beginDefinition;
withWorkspaceGlobalProgress // Attributes = { HoldRest };

withWorkspaceGlobalProgress[ nbo_NotebookObject, eval_ ] := Enclose[
Catch @ Module[ { attached },

attached = ConfirmMatch[
AttachCell[
nbo,
Cell[
BoxData @ ToBoxes @ $workspaceChatProgressBar,
"WorkspaceChatProgressBar",
FontSize -> 0.1,
Magnification -> AbsoluteCurrentValue[ nbo, Magnification ]
],
{ Center, Top },
Offset[ { 0, 1 }, { 0, 0 } ],
{ Center, Top },
RemovalConditions -> { "EvaluatorQuit" }
],
_CellObject,
"Attached"
];

WithCleanup[ eval, NotebookDelete @ attached ]
],
throwInternalFailure
];

withWorkspaceGlobalProgress // endDefinition;


$workspaceChatProgressBar = With[
{
background = None,
colorCenter = RGBColor[ 0.27451, 0.61961, 0.79608, 1.0 ],
colorEdges = RGBColor[ 0.27451, 0.61961, 0.79608, 0.0 ],
duration = 3,
leftOffset = -0.5,
rightOffset = 1.5,
thickness = Thickness[ 1 ]
},
Graphics[
{
Graphics[
{
RGBColor[ "#449EF7" ],
Dynamic @ Rectangle[
ImageScaled @ { Max[ 0, Clock[ { -0.5, 1.0 }, 3 ] ], 0 },
ImageScaled @ { Min[ 1, Clock[ { 0.0, 1.5 }, 3 ] ], 1 }
thickness,
Dynamic @ TemplateBox[
{ Clock[ { leftOffset, 1.0 }, duration ], Clock[ { 0.0, rightOffset }, duration ] },
"WorkspaceChatProgressBar",
DisplayFunction -> Function[
LineBox[
{
{ #1, 0 },
{ (#1 + #2) / 2, 0 },
{ #2, 0 }
},
VertexColors -> { colorEdges, colorCenter, colorEdges }
]
},
AspectRatio -> Full,
Background -> RGBColor[ "#D1D1D1" ],
ImageSize -> { Full, 2 },
PlotRangePadding -> None
]
]
}
},
Alignment -> { Center, Center },
Frame -> None,
ItemSize -> { Automatic, 0 },
Spacings -> { { 0, { }, 0 }, { 0, { }, 0 } }
]
},
AspectRatio -> Full,
Background -> background,
ImageMargins -> 0,
ImageSize -> { Full, 4 },
PlotRange -> { { 0, 1 }, Automatic },
PlotRangePadding -> None
]
];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
Expand Down
10 changes: 9 additions & 1 deletion Source/Chatbook/ChatState.wl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ withEvaluationCell // endDefinition;
(*withEvaluationNotebook*)
withEvaluationNotebook // beginDefinition;
withEvaluationNotebook // Attributes = { HoldRest };
withEvaluationNotebook[ nbo_NotebookObject, eval_ ] := Block[ { $evaluationNotebook = nbo }, eval ];

withEvaluationNotebook[ nbo_NotebookObject, eval_ ] :=
Block[ { $evaluationNotebook = nbo },
If[ TrueQ @ CurrentChatSettings[ nbo, "WorkspaceChat" ],
withWorkspaceGlobalProgress[ nbo, eval ],
eval
]
];

withEvaluationNotebook // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand Down
1 change: 1 addition & 0 deletions Source/Chatbook/CommonSymbols.wl
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ BeginPackage[ "Wolfram`Chatbook`Common`" ];
`withChatState;
`withChatStateAndFEObjects;
`withToolBox;
`withWorkspaceGlobalProgress;
`wlTemplateBoxes;
`writeInlineChatOutputCell;
`writeReformattedCell;
Expand Down
19 changes: 13 additions & 6 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,10 @@ makeToolCallBoxLabel[ as_Association, name_String ] :=
makeToolCallBoxLabel[ as, name, getToolIcon @ as ];

makeToolCallBoxLabel[ as_, name_String, icon_ ] /; $dynamicText :=
fakeOpenerView @ makeToolCallBoxLabel0[ as, name, icon ];
fakeOpenerView[
makeToolCallBoxLabel0[ as, name, icon ],
as[ "Result" ] =!= ""
];

makeToolCallBoxLabel[ as0_, name_String, icon_ ] :=
With[ { as = resolveToolFormatter @ as0 },
Expand All @@ -1523,11 +1526,15 @@ makeToolCallBoxLabel // endDefinition;

makeToolCallBoxLabel0 // beginDefinition;

makeToolCallBoxLabel0[ KeyValuePattern[ "Result" -> "" ], string_String, icon_ ] := Flatten @ {
toolCallIconPane @ icon,
Style[ tr[ "FormattingToolUsing" ], FontColor -> RGBColor[ "#3383AC" ] ],
Style[ string, FontWeight -> "DemiBold", FontColor -> RGBColor[ "#3383AC" ] ]
};
makeToolCallBoxLabel0[ KeyValuePattern[ "Result" -> "" ], string_String, icon_ ] :=
With[ { col = RGBColor[ "#3383AC" ] },
Flatten @ {
toolCallIconPane @ icon,
Style[ tr[ "FormattingToolUsing" ], FontColor -> col ],
Style[ string, FontWeight -> "DemiBold", FontColor -> col ],
RawBoxes @ DynamicBox @ FEPrivate`FrontEndResource[ "FEExpressions", "PercolateColorAnimator" ][ Small, col ]
}
];

makeToolCallBoxLabel0[ as_, string_String, icon_ ] := Flatten @ {
toolCallIconPane @ icon,
Expand Down
7 changes: 5 additions & 2 deletions Source/Chatbook/FrontEnd.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,15 @@ $openerFrameOptionsActive = Sequence[
but doesn't yet contain any inner data to reduce MathLink traffic *)
fakeOpenerView // beginDefinition;

fakeOpenerView[ label_ ] := Deploy @ Framed[
fakeOpenerView[ label_, showButton_: False ] := Deploy @ Framed[
Grid[
{
Flatten @ {
label,
RawBoxes @ TemplateBox[ { RGBColor[ "#3383AC" ] }, "DiscardedMaterialOpenerIcon" ]
If[ TrueQ @ showButton,
RawBoxes @ TemplateBox[ { RGBColor[ "#3383AC" ] }, "DiscardedMaterialOpenerIcon" ],
Nothing
]
}
},
$openerLabelGridOptions
Expand Down

0 comments on commit fb1afb0

Please sign in to comment.