Skip to content

Commit

Permalink
Merge pull request #134 from WolframResearch/feature/improve-mx-loading
Browse files Browse the repository at this point in the history
Avoid loading extra package file at startup
  • Loading branch information
rhennigan authored May 22, 2023
2 parents 021d949 + cae905f commit 9af45d7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 58 deletions.
8 changes: 1 addition & 7 deletions PacletInfo.wl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ PacletObject[<|
"PrimaryContext" -> "Wolfram`Chatbook`",
"Extensions" -> {
{"Kernel", "Root" -> "Source/Startup/Begin", "Context" -> "Wolfram`Chatbook`BeginStartup`"},
{"Kernel",
"Root" -> "Source/Chatbook",
"Context" -> "Wolfram`Chatbook`"
},
{"Kernel",
"Root" -> "Source/ServerSentEventUtils",
"Context" -> "Wolfram`ServerSentEventUtils`"},
{"Kernel", "Root" -> "Source/Chatbook", "Context" -> "Wolfram`Chatbook`"},
{"Kernel", "Root" -> "Source/Startup/End", "Context" -> "Wolfram`Chatbook`EndStartup`"},
{"Asset",
"Root" -> "Assets",
Expand Down
35 changes: 18 additions & 17 deletions Source/Chatbook/Main.wl
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,24 @@ Chatbook is a symbol for miscellaneous chat notebook messages.\
(* ::Section::Closed:: *)
(*Load Files*)
Block[ { $ContextPath },
Get[ "Wolfram`Chatbook`Common`" ];
Get[ "Wolfram`Chatbook`Debug`" ];
Get[ "Wolfram`Chatbook`ErrorUtils`" ];
Get[ "Wolfram`Chatbook`Errors`" ];
Get[ "Wolfram`Chatbook`CreateChatNotebook`" ];
Get[ "Wolfram`Chatbook`Serialization`" ];
Get[ "Wolfram`Chatbook`Streaming`" ];
Get[ "Wolfram`Chatbook`Utils`" ];
Get[ "Wolfram`Chatbook`FrontEnd`" ];
Get[ "Wolfram`Chatbook`UI`" ];
Get[ "Wolfram`Chatbook`Formatting`" ];
Get[ "Wolfram`Chatbook`Prompting`" ];
Get[ "Wolfram`Chatbook`Actions`" ];
Get[ "Wolfram`Chatbook`Menus`" ];
Get[ "Wolfram`Chatbook`Personas`" ];
Get[ "Wolfram`Chatbook`PersonaInstaller`" ];
Get[ "Wolfram`Chatbook`InlineReferences`" ];
Get[ "Wolfram`Chatbook`Common`" ];
Get[ "Wolfram`Chatbook`Debug`" ];
Get[ "Wolfram`Chatbook`ErrorUtils`" ];
Get[ "Wolfram`Chatbook`Errors`" ];
Get[ "Wolfram`Chatbook`CreateChatNotebook`" ];
Get[ "Wolfram`Chatbook`Serialization`" ];
Get[ "Wolfram`Chatbook`Streaming`" ];
Get[ "Wolfram`Chatbook`Utils`" ];
Get[ "Wolfram`Chatbook`FrontEnd`" ];
Get[ "Wolfram`Chatbook`UI`" ];
Get[ "Wolfram`Chatbook`Formatting`" ];
Get[ "Wolfram`Chatbook`Prompting`" ];
Get[ "Wolfram`Chatbook`Actions`" ];
Get[ "Wolfram`Chatbook`Menus`" ];
Get[ "Wolfram`Chatbook`Personas`" ];
Get[ "Wolfram`Chatbook`PersonaInstaller`" ];
Get[ "Wolfram`Chatbook`InlineReferences`" ];
Get[ "Wolfram`Chatbook`ServerSentEventUtils`" ];
];

(* ::**************************************************************************************************************:: *)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BeginPackage["Wolfram`ServerSentEventUtils`"]
BeginPackage["Wolfram`Chatbook`ServerSentEventUtils`"]

(* Avoiding context aliasing due to bug 434990: *)
Needs[ "GeneralUtilities`" -> None ];
Expand Down
4 changes: 2 additions & 2 deletions Source/Chatbook/UI.wl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Needs["Wolfram`Chatbook`PersonaInstaller`"]
Needs["Wolfram`Chatbook`FrontEnd`"]


Needs["Wolfram`ServerSentEventUtils`" -> None]
Needs["Wolfram`Chatbook`ServerSentEventUtils`" -> None]


$ChatOutputTypePrompts = <|
Expand Down Expand Up @@ -710,7 +710,7 @@ doAsyncChatRequest[
task = URLSubmit[
request,
HandlerFunctions -> <|
"BodyChunkReceived" -> Wolfram`ServerSentEventUtils`ServerSentEventBodyChunkTransformer[
"BodyChunkReceived" -> Wolfram`Chatbook`ServerSentEventUtils`ServerSentEventBodyChunkTransformer[
event |-> (
AppendTo[events, event];
Handle[
Expand Down
53 changes: 22 additions & 31 deletions Tests/SSETests.wlt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Needs["Wolfram`ServerSentEventUtils`"]
Needs["Wolfram`Chatbook`ServerSentEventUtils`"]


(*=================================================*)
Expand All @@ -9,22 +9,22 @@ Module[{
generator = CreateChunkToServerSentEventGenerator[]
},
VerificationTest[
generator["data:"]
,
Missing["IncompleteData"]
];
generator["data:"],
Missing["IncompleteData"],
TestID -> "Untitled-7@@Tests/SSETests.wlt:11,2-15,2"
];

VerificationTest[
generator[" foo\n"]
,
Missing["IncompleteData"]
];
generator[" foo\n"],
Missing["IncompleteData"],
TestID -> "Untitled-8@@Tests/SSETests.wlt:17,2-21,2"
];

VerificationTest[
generator["\n"]
,
{<|"Data" -> "foo"|>}
];
generator["\n"],
{Association["Data" -> "foo"]},
TestID -> "Untitled-9@@Tests/SSETests.wlt:23,2-27,2"
];
]

(*===========================================*)
Expand All @@ -35,28 +35,19 @@ $events = {}
$func = ServerSentEventBodyChunkTransformer[event |-> AppendTo[$events, event]]

VerificationTest[
{
$func[<| "BodyChunk" -> "data: " |>],
$events
}
,
{Null, {}}
{$func[Association["BodyChunk" -> "data: "]], $events},
{Null, {}},
TestID -> "Untitled-10@@Tests/SSETests.wlt:37,1-41,2"
]

VerificationTest[
{
$func[<| "BodyChunk" -> "foo\n" |>],
$events
}
,
{Null, {}}
{$func[Association["BodyChunk" -> "foo\n"]], $events},
{Null, {}},
TestID -> "Untitled-11@@Tests/SSETests.wlt:43,1-47,2"
]

VerificationTest[
{
$func[<| "BodyChunk" -> "\n\n" |>],
$events
}
,
{Null, {<| "Data" -> "foo" |>}}
{$func[Association["BodyChunk" -> "\n\n"]], $events},
{Null, {Association["Data" -> "foo"]}},
TestID -> "Untitled-12@@Tests/SSETests.wlt:49,1-53,2"
]

0 comments on commit 9af45d7

Please sign in to comment.