Skip to content

Commit

Permalink
Merge pull request #987 from WolframResearch/feature/more-usage-reduc…
Browse files Browse the repository at this point in the history
…tion

Avoid excessively large context lengths in regular chat notebooks
  • Loading branch information
rhennigan authored Dec 18, 2024
2 parents 8242697 + 0b59347 commit 2a09469
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Source/Chatbook/Settings.wl
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ $autoSettingKeyDependencies = <|
"HandlerFunctionsKeys" -> "EnableLLMServices",
"HybridToolMethod" -> { "Model", "ToolsEnabled" },
"MaxCellStringLength" -> { "Model", "MaxContextTokens" },
"MaxContextTokens" -> "Model",
"MaxContextTokens" -> { "Authentication", "Model" },
"MaxOutputCellStringLength" -> "MaxCellStringLength",
"MaxTokens" -> "Model",
"Multimodal" -> { "EnableLLMServices", "Model" },
Expand Down Expand Up @@ -621,7 +621,7 @@ styleStopTokens // endDefinition;
chooseMaxCellStringLength // beginDefinition;
chooseMaxCellStringLength[ as_Association ] := chooseMaxCellStringLength[ as, as[ "MaxContextTokens" ] ];
chooseMaxCellStringLength[ as_, Infinity ] := Infinity;
chooseMaxCellStringLength[ as_, tokens: $$size ] := Ceiling[ $defaultMaxCellStringLength * tokens / 2^13 ];
chooseMaxCellStringLength[ as_, tokens: $$size ] := Ceiling[ $defaultMaxCellStringLength * tokens / 2^14 ];
chooseMaxCellStringLength // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand All @@ -637,6 +637,7 @@ chooseMaxOutputCellStringLength // endDefinition;
(*autoMaxContextTokens*)
autoMaxContextTokens // beginDefinition;
autoMaxContextTokens[ as_? ollamaQ ] := serviceMaxContextTokens @ as;
autoMaxContextTokens[ as_Association? llmKitQ ] := Min[ 2^16, autoMaxContextTokens[ as, as[ "Model" ] ] ];
autoMaxContextTokens[ as_Association ] := autoMaxContextTokens[ as, as[ "Model" ] ];
autoMaxContextTokens[ as_, model_ ] := autoMaxContextTokens[ as, model, toModelName @ model ];
autoMaxContextTokens[ _, _, name_String ] := autoMaxContextTokens0 @ name;
Expand Down

0 comments on commit 2a09469

Please sign in to comment.