✨ warning if exceeding context limit

This commit is contained in:
Nate Sesti 2023-11-08 11:37:51 -08:00
parent 62fbc61ab6
commit 32aa2d24ff
2 changed files with 33 additions and 1 deletions

View file

@ -4,7 +4,7 @@ pluginGroup = com.github.continuedev.continueintellijextension
pluginName = continue-intellij-extension
pluginRepositoryUrl = https://github.com/continuedev/continue
# SemVer format -> https://semver.org
pluginVersion = 0.0.16
pluginVersion = 0.0.17
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223

View file

@ -28,6 +28,7 @@ import {
ChevronRightIcon,
Cog6ToothIcon,
CommandLineIcon,
ExclamationTriangleIcon,
FolderIcon,
FolderOpenIcon,
GlobeAltIcon,
@ -797,6 +798,24 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
]
);
const [contextLengthFillPercentage, setContextLengthFillPercentage] =
useState<number>(0);
const contextLength = useSelector(
(store: RootStore) =>
store.serverState.config.models?.default?.context_length || 4096
);
useEffect(() => {
let tokenEstimate = selectedContextItems.reduce((acc, item) => {
return acc + item.content.length / Math.E; // Just an estimate of tokens / char
}, 0);
tokenEstimate += downshiftProps.inputValue.length / Math.E;
setContextLengthFillPercentage(
tokenEstimate / Math.max(1, contextLength - 600)
);
}, [selectedContextItems, contextLength]);
const [isComposing, setIsComposing] = useState(false);
const [showContextToggleOn, setShowContextToggleOn] = useState(false);
@ -1034,6 +1053,19 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
wFull={false}
></RingLoader>
)}
{contextLengthFillPercentage > 1 && (
<HeaderButtonWithText
text={`Context selected may exceed token limit (~${(
100 * contextLengthFillPercentage
).toFixed(0)}%)`}
>
<ExclamationTriangleIcon
width="1.0em"
height="1.0em"
color="red"
/>
</HeaderButtonWithText>
)}
</>
) : (
<div