Skip to content

Commit

Permalink
Merge pull request #927 from WolframResearch/bugfix/fix-regressions-f…
Browse files Browse the repository at this point in the history
…rom-bad-merge

Bugfix: Fix several regressions due to bad merge
  • Loading branch information
rhennigan authored Nov 15, 2024
2 parents fb1afb0 + c517df1 commit b81161b
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 44 deletions.
34 changes: 28 additions & 6 deletions Developer/VectorDatabases/VectorDatabaseBuilder.wl
Original file line number Diff line number Diff line change
Expand Up @@ -536,14 +536,36 @@ createEmbeddings[ string_String ] :=
(* ::**************************************************************************************************************:: *)
(* ::Subsubsection::Closed:: *)
(*sentenceBERTEmbedding*)
sentenceBERTEmbedding // beginDefinition;
sentenceBERTEmbedding := getSentenceBERTEmbeddingFunction[ ];

sentenceBERTEmbedding[ args___ ] := (
Needs[ "SemanticSearch`" -> None ];
SemanticSearch`SemanticSearch`Private`SentenceBERTEmbedding @ args
);
(* ::**************************************************************************************************************:: *)
(* ::Subsubsubsection::Closed:: *)
(*getSentenceBERTEmbeddingFunction*)
getSentenceBERTEmbeddingFunction // beginDefinition;

getSentenceBERTEmbeddingFunction[ ] := Enclose[
Module[ { name },

Needs[ "SemanticSearch`" -> None ];

name = ConfirmBy[
SelectFirst[
{
"SemanticSearch`SentenceBERTEmbedding",
"SemanticSearch`SemanticSearch`Private`SentenceBERTEmbedding"
},
NameQ @ # && ToExpression[ #, InputForm, System`Private`HasAnyEvaluationsQ ] &
],
StringQ,
"SymbolName"
];

getSentenceBERTEmbeddingFunction[ ] = Symbol @ name
],
throwInternalFailure
];

sentenceBERTEmbedding // endDefinition;
getSentenceBERTEmbeddingFunction // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
Expand Down
5 changes: 1 addition & 4 deletions Source/Chatbook/ChatMessageToCell.wl
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ workspaceOutput // beginDefinition;

workspaceOutput[ text_TextData ] :=
wrapCellContent[
TextData @ Cell[
BoxData @ TemplateBox[ { Cell[ text, $selectableOptions ] }, "AssistantMessageBox" ],
Background -> None
],
BoxData @ TemplateBox[ { Cell[ text, $selectableOptions ] }, "AssistantMessageBox" ],
"Assistant",
"Default"
];
Expand Down
24 changes: 6 additions & 18 deletions Source/Chatbook/ChatModes/UI.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1133,19 +1133,16 @@ $inlineToWorkspaceConversionRules := $inlineToWorkspaceConversionRules = Dispatc
]
,
Cell[
TextData @ { Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], ___ ] },
BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ],
"ChatOutput",
___,
TaggingRules -> tags_,
___
] :>
Cell[
TextData @ Cell[
BoxData @ TemplateBox[
{ Cell[ Flatten @ TextData @ text, Background -> None, Editable -> True, Selectable -> True ] },
"AssistantMessageBox"
],
Background -> None
BoxData @ TemplateBox[
{ Cell[ Flatten @ TextData @ text, Background -> None, Editable -> True, Selectable -> True ] },
"AssistantMessageBox"
],
"ChatOutput",
TaggingRules -> tags,
Expand Down Expand Up @@ -1200,17 +1197,8 @@ $fromWorkspaceChatConversionRules := $fromWorkspaceChatConversionRules = Dispatc
Cell[ BoxData @ TemplateBox[ { text_ }, "UserMessageBox", ___ ], "ChatInput", ___ ] :>
Cell[ Flatten @ TextData @ text, "ChatInput" ]
,
Cell[
TextData @ Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], ___ ],
"ChatOutput",
___
] :> Cell[ Flatten @ TextData @ text, "ChatOutput" ]
,
Cell[
TextData @ { Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], ___ ] },
"ChatOutput",
___
] :> Cell[ Flatten @ TextData @ text, "ChatOutput" ]
Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], "ChatOutput", ___ ] :>
Cell[ Flatten @ TextData @ text, "ChatOutput" ]
};

(* ::**************************************************************************************************************:: *)
Expand Down
2 changes: 2 additions & 0 deletions Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,8 @@ $dynamicSplitRules = {
(* ::Subsection::Closed:: *)
(*$stringFormatRules*)
$stringFormatRules = {
"```" ~~ code: Except[ "\n" ].. ~~ "```" :> inlineCodeCell @ code,

"***" ~~ text: Except[ "*" ].. ~~ "***" /; StringFreeQ[ text, "\n" ] :>
styleBox[ text, FontWeight -> Bold, FontSlant -> Italic ],

Expand Down
5 changes: 4 additions & 1 deletion Source/Chatbook/PromptGenerators/VectorDatabases.wl
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,10 @@ getAndCacheEmbeddings[ { } ] :=
getAndCacheEmbeddings[ strings: { __String } ] /; $embeddingModel === "SentenceBERT" := Enclose[
Module[ { vectors },
vectors = ConfirmBy[
Developer`ToPackedArray @ sentenceBERTEmbedding @ strings,
If[ AllTrue[ strings, StringMatchQ[ WhitespaceCharacter... ] ],
Developer`ToPackedArray @ Rest @ sentenceBERTEmbedding @ Prepend[ strings, "hello" ],
Developer`ToPackedArray @ sentenceBERTEmbedding @ strings
],
Developer`PackedArrayQ,
"PackedArray"
];
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/Search.wl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ addChatToSearchIndex[ spec_ ] := Enclose[
Catch @ Module[ { data, appName, uuid, vectors, metadata },
If[ $noSemanticSearch, Throw @ Missing[ "NoSemanticSearch" ] ];
data = ConfirmMatch[ getChatConversationData @ spec, _Association|_Missing, "Data" ];
If[ MissingQ @ data, Throw @ data ]; (* TODO: auto-save here? *)
If[ MissingQ @ data, Throw @ Missing[ "NoVectors" ] ]; (* TODO: auto-save here? *)
appName = ConfirmBy[ data[ "AppName" ], StringQ, "AppName" ];
uuid = ConfirmBy[ data[ "ConversationUUID" ], StringQ, "ConversationUUID" ];
vectors = ConfirmMatch[ data[ "Vectors" ], { ___NumericArray }, "Vectors" ];
Expand Down
27 changes: 13 additions & 14 deletions Source/Chatbook/SendChat.wl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ sendChat[ evalCell_, nbo_, settings0_ ] /; $useLLMServices := catchTopAs[ Chatbo
];

AppendTo[ settings, "Data" -> data ];
CurrentValue[ cellObject, { TaggingRules, "ChatNotebookSettings", "Data" } ] = data;
CurrentChatSettings[ cellObject, "Data" ] = data;

$resultCellCache = <| |>;
$debugLog = Internal`Bag[ ];
Expand Down Expand Up @@ -145,8 +145,8 @@ sendChat[ evalCell_, nbo_, settings0_ ] /; $useLLMServices := catchTopAs[ Chatbo

addHandlerArguments[ "Task" -> task ];

CurrentValue[ cellObject, { TaggingRules, "ChatNotebookSettings", "CellObject" } ] = cellObject;
CurrentValue[ cellObject, { TaggingRules, "ChatNotebookSettings", "Task" } ] = task;
CurrentChatSettings[ cellObject, "CellObject" ] = cellObject;
CurrentChatSettings[ cellObject, "Task" ] = task;

If[ FailureQ @ task, throwTop @ writeErrorCell[ cellObject, task ] ];
setProgressDisplay[ "Waiting for response", 1.0 ];
Expand Down Expand Up @@ -895,6 +895,7 @@ autoCorrect[ string_String ] := StringReplace[ string, $llmAutoCorrectRules ];
autoCorrect // endDefinition;

$llmAutoCorrectRules := $llmAutoCorrectRules = Flatten @ {
"```" ~~ code: Except[ "\n" ].. ~~ "```" :> "``"<>code<>"``",
"wolfram_language_evaliator" -> "wolfram_language_evaluator",
"\\!\\(\\*MarkdownImageBox[\"" ~~ Shortest[ uri__ ] ~~ "\"]\\)" :> uri,
"\\!\\(MarkdownImageBox[\"" ~~ Shortest[ uri__ ] ~~ "\"]\\)" :> uri,
Expand Down Expand Up @@ -2264,15 +2265,10 @@ reformatCell[ settings_, string_, tag_, open_, label_, pageData_, cellTags_, uui
dingbat = makeOutputDingbat @ settings;

outer = If[ TrueQ @ $WorkspaceChat,
TextData @ {
Cell[
BoxData @ TemplateBox[
{ Cell[ #, Background -> None, Editable -> True, Selectable -> True ] },
"AssistantMessageBox"
],
Background -> None
]
} &,
BoxData @ TemplateBox[
{ Cell[ #, Background -> None, Editable -> True, Selectable -> True ] },
"AssistantMessageBox"
] &,
# &
];

Expand Down Expand Up @@ -2524,11 +2520,14 @@ restoreLastPage // endDefinition;
(*attachChatOutputMenu*)
attachChatOutputMenu // beginDefinition;

attachChatOutputMenu[ cell_CellObject ] /; $cloudNotebooks := Null;
attachChatOutputMenu[ cell_CellObject ] /; $cloudNotebooks || $WorkspaceChat || $InlineChat := Null;

attachChatOutputMenu[ cell_CellObject ] := (
$lastChatOutput = cell;
Lookup[ Options[ cell, Initialization ] /. HoldPattern @ EvaluationCell[ ] -> cell, Initialization ]
Quiet[
Lookup[ Options[ cell, Initialization ] /. HoldPattern @ EvaluationCell[ ] -> cell, Initialization ],
Lookup::invrl
]
);

attachChatOutputMenu // endDefinition;
Expand Down
18 changes: 18 additions & 0 deletions Source/Chatbook/UI.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,24 @@ makeServiceModelMenu[ Dynamic[ display_ ], obj_, root_, currentModel_, service_S
200
];

makeServiceModelMenu[ Dynamic[ display_ ], obj_, root_, currentModel_, service_String, Missing[ "NoModelList" ] ] :=
display = MakeMenu[
{
{ service },
{
Spacer[ 0 ],
Automatic,
Hold[
removeChatMenus @ EvaluationCell[ ];
(* TODO: this could probably prompt the user with an InputField to enter a name: *)
setModel[ obj, <| "Service" -> service, "Name" -> Automatic |> ]
]
}
},
GrayLevel[ 0.85 ],
200
];

makeServiceModelMenu // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand Down

0 comments on commit b81161b

Please sign in to comment.