Skip to content

Commit

Permalink
refactor(TokenContext): update maxTokens logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesprague committed Apr 21, 2024
1 parent ca5d26d commit 0ab3a19
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/contexts/TokenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { createContext, useContext, useEffect, useState } from 'react';
import type React from 'react';
import useLocalStorageState from 'use-local-storage-state';

import { getItem } from '@/app/utils/localStorage';

export const TokenStateContext = createContext(null);
export const TokenUpdaterContext = createContext(null);

Expand Down Expand Up @@ -37,7 +39,15 @@ export const TokenStateProvider = ({
const [inputTokens, setInputTokens] = useState(0);
const [systemMessageTokens, setSystemMessageTokens] = useState(0);

const maxTokens = 16384;
const [model, setModel] = useState('gpt-4');
useEffect(() => {
const currentModel = getItem('parameters')?.model;
if (currentModel) {
setModel(currentModel);
}
}, []);

const maxTokens = model === 'gpt-4' ? 128000 : 16384;
const [remainingTokens, setRemainingTokens] = useState(16384);
const [remainingSystemTokens, setRemainingSystemTokens] = useState(
systemMessageMaxTokens
Expand All @@ -64,6 +74,7 @@ export const TokenStateProvider = ({
});
}, [
inputTokens,
maxTokens,
remainingSystemTokens,
remainingTokens,
setTokens,
Expand Down

0 comments on commit 0ab3a19

Please sign in to comment.