Skip to content

Commit c517df1

Browse files
committed
Bugfix: Fix several regressions due to bad merge
1 parent fb1afb0 commit c517df1

File tree

8 files changed

+73
-44
lines changed

8 files changed

+73
-44
lines changed

Developer/VectorDatabases/VectorDatabaseBuilder.wl

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,36 @@ createEmbeddings[ string_String ] :=
536536
(* ::**************************************************************************************************************:: *)
537537
(* ::Subsubsection::Closed:: *)
538538
(*sentenceBERTEmbedding*)
539-
sentenceBERTEmbedding // beginDefinition;
539+
sentenceBERTEmbedding := getSentenceBERTEmbeddingFunction[ ];
540540

541-
sentenceBERTEmbedding[ args___ ] := (
542-
Needs[ "SemanticSearch`" -> None ];
543-
SemanticSearch`SemanticSearch`Private`SentenceBERTEmbedding @ args
544-
);
541+
(* ::**************************************************************************************************************:: *)
542+
(* ::Subsubsubsection::Closed:: *)
543+
(*getSentenceBERTEmbeddingFunction*)
544+
getSentenceBERTEmbeddingFunction // beginDefinition;
545+
546+
getSentenceBERTEmbeddingFunction[ ] := Enclose[
547+
Module[ { name },
548+
549+
Needs[ "SemanticSearch`" -> None ];
550+
551+
name = ConfirmBy[
552+
SelectFirst[
553+
{
554+
"SemanticSearch`SentenceBERTEmbedding",
555+
"SemanticSearch`SemanticSearch`Private`SentenceBERTEmbedding"
556+
},
557+
NameQ @ # && ToExpression[ #, InputForm, System`Private`HasAnyEvaluationsQ ] &
558+
],
559+
StringQ,
560+
"SymbolName"
561+
];
562+
563+
getSentenceBERTEmbeddingFunction[ ] = Symbol @ name
564+
],
565+
throwInternalFailure
566+
];
545567

546-
sentenceBERTEmbedding // endDefinition;
568+
getSentenceBERTEmbeddingFunction // endDefinition;
547569

548570
(* ::**************************************************************************************************************:: *)
549571
(* ::Subsection::Closed:: *)

Source/Chatbook/ChatMessageToCell.wl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ workspaceOutput // beginDefinition;
101101

102102
workspaceOutput[ text_TextData ] :=
103103
wrapCellContent[
104-
TextData @ Cell[
105-
BoxData @ TemplateBox[ { Cell[ text, $selectableOptions ] }, "AssistantMessageBox" ],
106-
Background -> None
107-
],
104+
BoxData @ TemplateBox[ { Cell[ text, $selectableOptions ] }, "AssistantMessageBox" ],
108105
"Assistant",
109106
"Default"
110107
];

Source/Chatbook/ChatModes/UI.wl

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,19 +1133,16 @@ $inlineToWorkspaceConversionRules := $inlineToWorkspaceConversionRules = Dispatc
11331133
]
11341134
,
11351135
Cell[
1136-
TextData @ { Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], ___ ] },
1136+
BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ],
11371137
"ChatOutput",
11381138
___,
11391139
TaggingRules -> tags_,
11401140
___
11411141
] :>
11421142
Cell[
1143-
TextData @ Cell[
1144-
BoxData @ TemplateBox[
1145-
{ Cell[ Flatten @ TextData @ text, Background -> None, Editable -> True, Selectable -> True ] },
1146-
"AssistantMessageBox"
1147-
],
1148-
Background -> None
1143+
BoxData @ TemplateBox[
1144+
{ Cell[ Flatten @ TextData @ text, Background -> None, Editable -> True, Selectable -> True ] },
1145+
"AssistantMessageBox"
11491146
],
11501147
"ChatOutput",
11511148
TaggingRules -> tags,
@@ -1200,17 +1197,8 @@ $fromWorkspaceChatConversionRules := $fromWorkspaceChatConversionRules = Dispatc
12001197
Cell[ BoxData @ TemplateBox[ { text_ }, "UserMessageBox", ___ ], "ChatInput", ___ ] :>
12011198
Cell[ Flatten @ TextData @ text, "ChatInput" ]
12021199
,
1203-
Cell[
1204-
TextData @ Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], ___ ],
1205-
"ChatOutput",
1206-
___
1207-
] :> Cell[ Flatten @ TextData @ text, "ChatOutput" ]
1208-
,
1209-
Cell[
1210-
TextData @ { Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], ___ ] },
1211-
"ChatOutput",
1212-
___
1213-
] :> Cell[ Flatten @ TextData @ text, "ChatOutput" ]
1200+
Cell[ BoxData @ TemplateBox[ { Cell[ text_, ___ ] }, "AssistantMessageBox", ___ ], "ChatOutput", ___ ] :>
1201+
Cell[ Flatten @ TextData @ text, "ChatOutput" ]
12141202
};
12151203

12161204
(* ::**************************************************************************************************************:: *)

Source/Chatbook/Formatting.wl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ $dynamicSplitRules = {
11731173
(* ::Subsection::Closed:: *)
11741174
(*$stringFormatRules*)
11751175
$stringFormatRules = {
1176+
"```" ~~ code: Except[ "\n" ].. ~~ "```" :> inlineCodeCell @ code,
1177+
11761178
"***" ~~ text: Except[ "*" ].. ~~ "***" /; StringFreeQ[ text, "\n" ] :>
11771179
styleBox[ text, FontWeight -> Bold, FontSlant -> Italic ],
11781180

Source/Chatbook/PromptGenerators/VectorDatabases.wl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ getAndCacheEmbeddings[ { } ] :=
603603
getAndCacheEmbeddings[ strings: { __String } ] /; $embeddingModel === "SentenceBERT" := Enclose[
604604
Module[ { vectors },
605605
vectors = ConfirmBy[
606-
Developer`ToPackedArray @ sentenceBERTEmbedding @ strings,
606+
If[ AllTrue[ strings, StringMatchQ[ WhitespaceCharacter... ] ],
607+
Developer`ToPackedArray @ Rest @ sentenceBERTEmbedding @ Prepend[ strings, "hello" ],
608+
Developer`ToPackedArray @ sentenceBERTEmbedding @ strings
609+
],
607610
Developer`PackedArrayQ,
608611
"PackedArray"
609612
];

Source/Chatbook/Search.wl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ addChatToSearchIndex[ spec_ ] := Enclose[
9999
Catch @ Module[ { data, appName, uuid, vectors, metadata },
100100
If[ $noSemanticSearch, Throw @ Missing[ "NoSemanticSearch" ] ];
101101
data = ConfirmMatch[ getChatConversationData @ spec, _Association|_Missing, "Data" ];
102-
If[ MissingQ @ data, Throw @ data ]; (* TODO: auto-save here? *)
102+
If[ MissingQ @ data, Throw @ Missing[ "NoVectors" ] ]; (* TODO: auto-save here? *)
103103
appName = ConfirmBy[ data[ "AppName" ], StringQ, "AppName" ];
104104
uuid = ConfirmBy[ data[ "ConversationUUID" ], StringQ, "ConversationUUID" ];
105105
vectors = ConfirmMatch[ data[ "Vectors" ], { ___NumericArray }, "Vectors" ];

Source/Chatbook/SendChat.wl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ sendChat[ evalCell_, nbo_, settings0_ ] /; $useLLMServices := catchTopAs[ Chatbo
110110
];
111111

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

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

146146
addHandlerArguments[ "Task" -> task ];
147147

148-
CurrentValue[ cellObject, { TaggingRules, "ChatNotebookSettings", "CellObject" } ] = cellObject;
149-
CurrentValue[ cellObject, { TaggingRules, "ChatNotebookSettings", "Task" } ] = task;
148+
CurrentChatSettings[ cellObject, "CellObject" ] = cellObject;
149+
CurrentChatSettings[ cellObject, "Task" ] = task;
150150

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

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

22662267
outer = If[ TrueQ @ $WorkspaceChat,
2267-
TextData @ {
2268-
Cell[
2269-
BoxData @ TemplateBox[
2270-
{ Cell[ #, Background -> None, Editable -> True, Selectable -> True ] },
2271-
"AssistantMessageBox"
2272-
],
2273-
Background -> None
2274-
]
2275-
} &,
2268+
BoxData @ TemplateBox[
2269+
{ Cell[ #, Background -> None, Editable -> True, Selectable -> True ] },
2270+
"AssistantMessageBox"
2271+
] &,
22762272
# &
22772273
];
22782274

@@ -2524,11 +2520,14 @@ restoreLastPage // endDefinition;
25242520
(*attachChatOutputMenu*)
25252521
attachChatOutputMenu // beginDefinition;
25262522

2527-
attachChatOutputMenu[ cell_CellObject ] /; $cloudNotebooks := Null;
2523+
attachChatOutputMenu[ cell_CellObject ] /; $cloudNotebooks || $WorkspaceChat || $InlineChat := Null;
25282524

25292525
attachChatOutputMenu[ cell_CellObject ] := (
25302526
$lastChatOutput = cell;
2531-
Lookup[ Options[ cell, Initialization ] /. HoldPattern @ EvaluationCell[ ] -> cell, Initialization ]
2527+
Quiet[
2528+
Lookup[ Options[ cell, Initialization ] /. HoldPattern @ EvaluationCell[ ] -> cell, Initialization ],
2529+
Lookup::invrl
2530+
]
25322531
);
25332532

25342533
attachChatOutputMenu // endDefinition;

Source/Chatbook/UI.wl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,24 @@ makeServiceModelMenu[ Dynamic[ display_ ], obj_, root_, currentModel_, service_S
10391039
200
10401040
];
10411041

1042+
makeServiceModelMenu[ Dynamic[ display_ ], obj_, root_, currentModel_, service_String, Missing[ "NoModelList" ] ] :=
1043+
display = MakeMenu[
1044+
{
1045+
{ service },
1046+
{
1047+
Spacer[ 0 ],
1048+
Automatic,
1049+
Hold[
1050+
removeChatMenus @ EvaluationCell[ ];
1051+
(* TODO: this could probably prompt the user with an InputField to enter a name: *)
1052+
setModel[ obj, <| "Service" -> service, "Name" -> Automatic |> ]
1053+
]
1054+
}
1055+
},
1056+
GrayLevel[ 0.85 ],
1057+
200
1058+
];
1059+
10421060
makeServiceModelMenu // endDefinition;
10431061

10441062
(* ::**************************************************************************************************************:: *)

0 commit comments

Comments
 (0)