Skip to content

Commit

Permalink
Added highlighting of included cells when mousing over chat inputs an…
Browse files Browse the repository at this point in the history
…d exposed `GetChatHistory` in main context
  • Loading branch information
rhennigan committed Nov 6, 2023
1 parent 4c2f092 commit f802270
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 28 deletions.
28 changes: 25 additions & 3 deletions Developer/Resources/Styles.wl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Cell[
CellInsertionPointCell -> $cellInsertionPointCell,

CellTrayWidgets -> <|
"GearMenu" -> <| "Condition" -> False |>,
"ChatWidget" -> <|
"GearMenu" -> <| "Condition" -> False |>,
"ChatIncluded" -> <| "Condition" -> False, "Content" -> $includedCellWidget |>,
"ChatWidget" -> <|
"Type" -> "Focus",
"Content" -> Cell[ BoxData @ TemplateBox[ { }, "ChatWidgetButton" ], "ChatWidget" ]
|>
Expand All @@ -25,7 +26,13 @@ Cell[
"CellBracket" -> contextMenu[ $askMenuItem, $excludeMenuItem, Delimiter, "CellBracket" ],
"CellGroup" -> contextMenu[ $excludeMenuItem, Delimiter, "CellGroup" ],
"CellRange" -> contextMenu[ $excludeMenuItem, Delimiter, "CellRange" ]
|>
|>,

PrivateCellOptions -> {
"AccentStyle" -> {
CellTrayWidgets -> <| "ChatIncluded" -> <| "Condition" -> True |> |>
}
}
]


Expand Down Expand Up @@ -145,20 +152,35 @@ Cell[
Symbol[ "Wolfram`Chatbook`ChatbookAction" ][ "EvaluateChatInput", $CellContext`cell ]
],
CellEventActions -> {
(* Insert persona prompt input template: *)
{ "KeyDown", "@" } :> With[ { $CellContext`cell = EvaluationCell[ ] },
Quiet @ Needs[ "Wolfram`Chatbook`" -> None ];
Symbol[ "Wolfram`Chatbook`ChatbookAction" ][ "InsertInlineReference", "PersonaTemplate", $CellContext`cell ]
]
,
(* Insert function prompt input template: *)
{ "KeyDown", "!" } :> With[ { $CellContext`cell = EvaluationCell[ ] },
Quiet @ Needs[ "Wolfram`Chatbook`" -> None ];
Symbol[ "Wolfram`Chatbook`ChatbookAction" ][ "InsertInlineReference", "FunctionTemplate", $CellContext`cell ]
]
,
(* Insert modifier prompt input template: *)
{ "KeyDown", "#" } :> With[ { $CellContext`cell = EvaluationCell[ ] },
Quiet @ Needs[ "Wolfram`Chatbook`" -> None ];
Symbol[ "Wolfram`Chatbook`ChatbookAction" ][ "InsertInlineReference", "ModifierTemplate", $CellContext`cell ]
]
,
(* Highlight cells that will be included in chat context: *)
"MouseEntered" :> With[ { $CellContext`cell = EvaluationCell[ ] },
Quiet @ Needs[ "Wolfram`Chatbook`" -> None ];
Symbol[ "Wolfram`Chatbook`ChatbookAction" ][ "AccentIncludedCells", $CellContext`cell ]
]
,
(* Remove cell highlights: *)
"MouseExited" :> With[ { $CellContext`cell = EvaluationCell[ ] },
Quiet @ Needs[ "Wolfram`Chatbook`" -> None ];
Symbol[ "Wolfram`Chatbook`ChatbookAction" ][ "RemoveCellAccents", $CellContext`cell ]
]
}
]

Expand Down
11 changes: 11 additions & 0 deletions Developer/StylesheetBuilder.wl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ Developer`WriteWXFFile[ $iconManifestFile, AssociationMap[ RawBoxes @ TemplateBo



(* ::Subsection::Closed:: *)
(*$includedCellWidget*)


$includedCellWidget = Cell[
BoxData @ ToBoxes @ Dynamic[ $IncludedCellWidget, SingleEvaluation -> True ],
"ChatIncluded"
];



(* ::Subsection::Closed:: *)
(*makeIconTemplateBoxStyle*)

Expand Down
38 changes: 36 additions & 2 deletions FrontEnd/StyleSheets/Chatbook.nb
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,19 @@ Notebook[
TaggingRules -> <|"ChatNotebookSettings" -> <||>|>,
CellTrayWidgets -> <|
"GearMenu" -> <|"Condition" -> False|>,
"ChatIncluded" -> <|
"Condition" -> False,
"Content" ->
Cell[
BoxData[
DynamicBox[
ToBoxes[Wolfram`Chatbook`$IncludedCellWidget, StandardForm],
SingleEvaluation -> True
]
],
"ChatIncluded"
]
|>,
"ChatWidget" -> <|
"Type" -> "Focus",
"Content" ->
Expand Down Expand Up @@ -1139,11 +1152,16 @@ Notebook[
}
]
}
|>
|>,
PrivateCellOptions -> {
"AccentStyle" -> {
CellTrayWidgets -> <|"ChatIncluded" -> <|"Condition" -> True|>|>
}
}
],
Cell[
StyleData["ChatStyleSheetInformation"],
TaggingRules -> <|"StyleSheetVersion" -> "1.2.4.3907141550"|>
TaggingRules -> <|"StyleSheetVersion" -> "1.3.1.3908279596"|>
],
Cell[
StyleData["Text"],
Expand Down Expand Up @@ -1602,6 +1620,22 @@ Notebook[
"ModifierTemplate",
cell
]
],
"MouseEntered" :>
With[ { cell = EvaluationCell[] },
Quiet[Needs["Wolfram`Chatbook`" -> None]];
Symbol["Wolfram`Chatbook`ChatbookAction"][
"AccentIncludedCells",
cell
]
],
"MouseExited" :>
With[ { cell = EvaluationCell[] },
Quiet[Needs["Wolfram`Chatbook`" -> None]];
Symbol["Wolfram`Chatbook`ChatbookAction"][
"RemoveCellAccents",
cell
]
]
},
CellFrameColor -> RGBColor[0.639216, 0.788235, 0.94902],
Expand Down
5 changes: 4 additions & 1 deletion Source/Chatbook/Actions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ BeginPackage[ "Wolfram`Chatbook`Actions`" ];
Begin[ "`Private`" ];

Needs[ "Wolfram`Chatbook`" ];
Needs[ "Wolfram`Chatbook`ChatHistory`" ];
Needs[ "Wolfram`Chatbook`Common`" ];
Needs[ "Wolfram`Chatbook`Dynamics`" ];
Needs[ "Wolfram`Chatbook`Explode`" ];
Expand Down Expand Up @@ -88,6 +89,7 @@ ChatCellEvaluate[ args___ ] :=
(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*ChatbookAction*)
ChatbookAction[ "AccentIncludedCells" , args___ ] := catchMine @ accentIncludedCells @ args;
ChatbookAction[ "AIAutoAssist" , args___ ] := catchMine @ AIAutoAssist @ args;
ChatbookAction[ "Ask" , args___ ] := catchMine @ AskChat @ args;
ChatbookAction[ "AttachCodeButtons" , args___ ] := catchMine @ AttachCodeButtons @ args;
Expand All @@ -102,13 +104,14 @@ ChatbookAction[ "InsertInlineReference", args___ ] := catchMine @ InsertInlineRe
ChatbookAction[ "OpenChatBlockSettings", args___ ] := catchMine @ OpenChatBlockSettings @ args;
ChatbookAction[ "OpenChatMenu" , args___ ] := catchMine @ OpenChatMenu @ args;
ChatbookAction[ "PersonaManage" , args___ ] := catchMine @ PersonaManage @ args;
ChatbookAction[ "ToolManage" , args___ ] := catchMine @ ToolManage @ args;
ChatbookAction[ "RemoveCellAccents" , args___ ] := catchMine @ removeCellAccents @ args;
ChatbookAction[ "Send" , args___ ] := catchMine @ SendChat @ args;
ChatbookAction[ "SendFeedback" , args___ ] := catchMine @ SendFeedback @ args;
ChatbookAction[ "StopChat" , args___ ] := catchMine @ StopChat @ args;
ChatbookAction[ "TabLeft" , args___ ] := catchMine @ TabLeft @ args;
ChatbookAction[ "TabRight" , args___ ] := catchMine @ TabRight @ args;
ChatbookAction[ "ToggleFormatting" , args___ ] := catchMine @ ToggleFormatting @ args;
ChatbookAction[ "ToolManage" , args___ ] := catchMine @ ToolManage @ args;
ChatbookAction[ "WidgetSend" , args___ ] := catchMine @ WidgetSend @ args;
ChatbookAction[ name_String , args___ ] := catchMine @ throwFailure[ "NotImplemented", name, args ];
ChatbookAction[ args___ ] := catchMine @ throwInternalFailure @ ChatbookAction @ args;
Expand Down
Loading

0 comments on commit f802270

Please sign in to comment.