Skip to content

Commit

Permalink
Merge pull request #943 from WolframResearch/bugfix/workspace-service…
Browse files Browse the repository at this point in the history
…-caller-string

Bugfix: WorkspaceChat caller string was not being set for main chat evaluation
  • Loading branch information
rhennigan authored Nov 21, 2024
2 parents a4abb69 + f9348c7 commit f07871c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 49 deletions.
2 changes: 1 addition & 1 deletion PacletInfo.wl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PacletObject[ <|
"Name" -> "Wolfram/Chatbook",
"PublisherID" -> "Wolfram",
"Version" -> "1.5.2.2",
"Version" -> "1.5.2.3",
"WolframVersion" -> "14.1+",
"Description" -> "Wolfram Notebooks + LLMs",
"License" -> "MIT",
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/Actions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ EvaluateChatInput[ evalCell_CellObject, nbo_NotebookObject ] :=
EvaluateChatInput[ evalCell_CellObject, nbo_NotebookObject, settings_Association? AssociationQ ] :=
withChatStateAndFEObjects[
{ evalCell, nbo },
Block[ { $AutomaticAssistance = False, $aborted = False },
setServiceCaller @ Block[ { $AutomaticAssistance = False, $aborted = False },
$lastCellObject = None;
$lastChatString = None;
$lastMessages = None;
Expand Down
95 changes: 53 additions & 42 deletions Source/Chatbook/ChatModes/ContentSuggestions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ executeWLSuggestions0 // beginDefinition;
executeWLSuggestions0[ KeyValuePattern @ { "Instructions" -> instructions_, "Context" -> context_ } ] :=
executeWLSuggestions0[ instructions, context ];

executeWLSuggestions0[ instructions_, context_ ] :=
setServiceCaller @ LogChatTiming @ suggestionServiceExecute[
executeWLSuggestions0[ instructions_, context_ ] := setServiceCaller[
LogChatTiming @ suggestionServiceExecute[
$suggestionsService,
"Chat",
{
Expand All @@ -522,7 +522,9 @@ executeWLSuggestions0[ instructions_, context_ ] :=
"MaxTokens" -> $wlSuggestionsMaxTokens,
"Temperature" -> $wlSuggestionsTemperature
}
];
],
"WLSuggestions"
];

executeWLSuggestions0 // endDefinition;

Expand All @@ -548,19 +550,22 @@ executeWLSuggestionsFIM[ as_Association ] := Enclose[
suffix = ConfirmBy[ after<>"\n\n\n"<>docs, StringQ, "Suffix" ];

responses = ConfirmMatch[
Table[
setServiceCaller @ LogChatTiming @ suggestionServiceExecute[
$wlFIMService,
"RawCompletion",
DeleteMissing @ <|
"model" -> $wlFIMModel,
"prompt" -> prompt,
"suffix" -> suffix,
"stream" -> False,
"options" -> $wlFIMOptions
|>
setServiceCaller[
Table[
LogChatTiming @ suggestionServiceExecute[
$wlFIMService,
"RawCompletion",
DeleteMissing @ <|
"model" -> $wlFIMModel,
"prompt" -> prompt,
"suffix" -> suffix,
"stream" -> False,
"options" -> $wlFIMOptions
|>
],
$wlFIMSuggestionsCount
],
$wlFIMSuggestionsCount
"WLSuggestions"
],
{ __Association },
"Responses"
Expand Down Expand Up @@ -839,20 +844,23 @@ generateTextSuggestions[ Dynamic[ container_ ], nbo_, root_CellObject, context0_

$lastInstructions = instructions;

response = setServiceCaller @ LogChatTiming @ suggestionServiceExecute[
$suggestionsService,
"Chat",
{
"Messages" -> {
<| "Role" -> "System", "Content" -> instructions |>,
<| "Role" -> "User" , "Content" -> context |>
},
"Model" -> $textSuggestionsModel,
"N" -> $textSuggestionsCount,
"MaxTokens" -> $textSuggestionsMaxTokens,
"Temperature" -> $textSuggestionsTemperature,
"StopTokens" -> { "\n\n" }
}
response = setServiceCaller[
LogChatTiming @ suggestionServiceExecute[
$suggestionsService,
"Chat",
{
"Messages" -> {
<| "Role" -> "System", "Content" -> instructions |>,
<| "Role" -> "User" , "Content" -> context |>
},
"Model" -> $textSuggestionsModel,
"N" -> $textSuggestionsCount,
"MaxTokens" -> $textSuggestionsMaxTokens,
"Temperature" -> $textSuggestionsTemperature,
"StopTokens" -> { "\n\n" }
}
],
"TextSuggestions"
];

suggestions = DeleteDuplicates @ ConfirmMatch[ getTextSuggestions @ response, { __TextData }, "Suggestions" ];
Expand Down Expand Up @@ -1009,19 +1017,22 @@ generateNotebookSuggestions0[ Dynamic[ container_ ], nbo_, root_NotebookObject,

$lastInstructions = instructions;

response = setServiceCaller @ LogChatTiming @ suggestionServiceExecute[
$suggestionsService,
"Chat",
{
"Messages" -> {
<| "Role" -> "System", "Content" -> instructions |>,
<| "Role" -> "User" , "Content" -> context |>
},
"Model" -> $notebookSuggestionsModel,
"N" -> $notebookSuggestionsCount,
"MaxTokens" -> $notebookSuggestionsMaxTokens,
"Temperature" -> $notebookSuggestionsTemperature
}
response = setServiceCaller[
LogChatTiming @ suggestionServiceExecute[
$suggestionsService,
"Chat",
{
"Messages" -> {
<| "Role" -> "System", "Content" -> instructions |>,
<| "Role" -> "User" , "Content" -> context |>
},
"Model" -> $notebookSuggestionsModel,
"N" -> $notebookSuggestionsCount,
"MaxTokens" -> $notebookSuggestionsMaxTokens,
"Temperature" -> $notebookSuggestionsTemperature
}
],
"NotebookSuggestions"
];

$finishReason = response[ "FinishReason" ];
Expand Down
23 changes: 21 additions & 2 deletions Source/Chatbook/ChatState.wl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ withChatStateAndFEObjects[ { cell_CellObject, None }, eval_ ] :=
withChatState @ withChatEvaluationCell[ cell, eval ];

withChatStateAndFEObjects[ { None, nbo_NotebookObject }, eval_ ] :=
withChatState @ withEvaluationNotebook[ nbo, eval ];
withChatState @ withAppNameCaller[ nbo, withEvaluationNotebook[ nbo, eval ] ];

(* Operator forms: *)
withChatStateAndFEObjects[ cell_CellObject ] :=
Expand Down Expand Up @@ -100,7 +100,7 @@ withChatEvaluationCell[ cell_CellObject, eval_ ] :=
cell,
(* Initialize settings cache: *)
AbsoluteCurrentChatSettings @ cell;
eval
withAppNameCaller[ cell, eval ]
]
,
(* CompoundExpression cannot be used here due to bug(450686): *)
Expand Down Expand Up @@ -171,6 +171,25 @@ withEvaluationNotebook[ nbo_NotebookObject, eval_ ] :=

withEvaluationNotebook // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*withAppNameCaller*)
withAppNameCaller // beginDefinition;
withAppNameCaller // Attributes = { HoldRest };

withAppNameCaller[ obj_, eval_ ] := Enclose[
Module[ { appName },
appName = CurrentChatSettings[ obj, "AppName" ];
If[ StringQ @ appName && appName =!= $defaultAppName,
setServiceCaller[ eval, appName ],
eval
]
],
throwInternalFailure
];

withAppNameCaller // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Package Footer*)
Expand Down
5 changes: 4 additions & 1 deletion Source/Chatbook/ChatTitle.wl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ generateChatTitleAsync[ messages: $$chatMessages, callback_, temperature: Automa
$lastChatTitleContext = context;

ConfirmMatch[
llmSynthesizeSubmit[ context, <| "Temperature" -> temperature |>, callback @* postProcessChatTitle ],
setServiceCaller[
llmSynthesizeSubmit[ context, <| "Temperature" -> temperature |>, callback @* postProcessChatTitle ],
"GenerateChatTitle"
],
_TaskObject,
"Task"
]
Expand Down
10 changes: 8 additions & 2 deletions Source/Chatbook/PromptGenerators/DefaultPromptGenerators.wl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ relatedDocumentationGenerator // beginDefinition;

relatedDocumentationGenerator[ messages: $$chatMessages ] :=
If[ TrueQ[ $InlineChat || $WorkspaceChat || $llmKit ],
LogChatTiming @ RelatedDocumentation[ messages, "Prompt", MaxItems -> 20, "FilterResults" -> True ],
setServiceCaller[
LogChatTiming @ RelatedDocumentation[ messages, "Prompt", MaxItems -> 20, "FilterResults" -> True ],
"RelatedDocumentation"
],
LogChatTiming @ RelatedDocumentation[ messages, "Prompt", MaxItems -> 5, "FilterResults" -> False ]
];

Expand All @@ -41,7 +44,10 @@ relatedWolframAlphaQueriesGenerator // beginDefinition;

relatedWolframAlphaQueriesGenerator[ messages: $$chatMessages ] :=
If[ TrueQ[ $InlineChat || $WorkspaceChat ],
LogChatTiming @ RelatedWolframAlphaQueries[ messages, "Prompt", MaxItems -> 20, "FilterResults" -> True ],
setServiceCaller[
LogChatTiming @ RelatedWolframAlphaQueries[ messages, "Prompt", MaxItems -> 20, "FilterResults" -> True ],
"RelatedWolframAlphaQueries"
],
LogChatTiming @ RelatedWolframAlphaQueries[ messages, "Prompt", MaxItems -> 5, "FilterResults" -> False ]
];

Expand Down

0 comments on commit f07871c

Please sign in to comment.