diff --git a/PacletInfo.wl b/PacletInfo.wl index 0dfe4d32..9ab63331 100644 --- a/PacletInfo.wl +++ b/PacletInfo.wl @@ -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", diff --git a/Source/Chatbook/Actions.wl b/Source/Chatbook/Actions.wl index ba1e9efe..d05b332e 100644 --- a/Source/Chatbook/Actions.wl +++ b/Source/Chatbook/Actions.wl @@ -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; diff --git a/Source/Chatbook/ChatModes/ContentSuggestions.wl b/Source/Chatbook/ChatModes/ContentSuggestions.wl index ef7c2745..9ceb6ff3 100644 --- a/Source/Chatbook/ChatModes/ContentSuggestions.wl +++ b/Source/Chatbook/ChatModes/ContentSuggestions.wl @@ -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", { @@ -522,7 +522,9 @@ executeWLSuggestions0[ instructions_, context_ ] := "MaxTokens" -> $wlSuggestionsMaxTokens, "Temperature" -> $wlSuggestionsTemperature } - ]; + ], + "WLSuggestions" +]; executeWLSuggestions0 // endDefinition; @@ -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" @@ -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" ]; @@ -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" ]; diff --git a/Source/Chatbook/ChatState.wl b/Source/Chatbook/ChatState.wl index 3c1bbb54..fcd3da15 100644 --- a/Source/Chatbook/ChatState.wl +++ b/Source/Chatbook/ChatState.wl @@ -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 ] := @@ -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): *) @@ -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*) diff --git a/Source/Chatbook/ChatTitle.wl b/Source/Chatbook/ChatTitle.wl index 58d8c250..f7deb78c 100644 --- a/Source/Chatbook/ChatTitle.wl +++ b/Source/Chatbook/ChatTitle.wl @@ -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" ] diff --git a/Source/Chatbook/PromptGenerators/DefaultPromptGenerators.wl b/Source/Chatbook/PromptGenerators/DefaultPromptGenerators.wl index c2bc597f..a43ca3a5 100644 --- a/Source/Chatbook/PromptGenerators/DefaultPromptGenerators.wl +++ b/Source/Chatbook/PromptGenerators/DefaultPromptGenerators.wl @@ -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 ] ]; @@ -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 ] ];