Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): fix tokenizer issue (Issue #2753) #2763

Merged
merged 11 commits into from
Dec 11, 2024
10 changes: 2 additions & 8 deletions apps/chat/src/hooks/useTokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ import { useCallback, useEffect, useState } from 'react';

import { DialAIEntityModel } from '../types/models';

import { Tiktoken, get_encoding } from '@dqbd/tiktoken';
import { Tiktoken, getEncoding } from 'js-tiktoken';
IlyaBondar marked this conversation as resolved.
Show resolved Hide resolved

export const useTokenizer = (tokenizer: DialAIEntityModel['tokenizer']) => {
const [encoding, setEncoding] = useState<Tiktoken | undefined>(undefined);

useEffect(() => {
if (tokenizer?.encoding) {
setEncoding(get_encoding(tokenizer.encoding));
setEncoding(getEncoding(tokenizer.encoding));
}
}, [tokenizer]);

useEffect(() => {
return () => {
encoding?.free();
};
}, [encoding]);

const getTokensLength = useCallback(
(str: string) => {
return encoding?.encode(str).length ?? new Blob([str]).size;
Expand Down
8 changes: 8 additions & 0 deletions apps/overlay-sandbox/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const nextConfig = {
// See: https://github.com/gregberge/svgr
svgr: false,
},
webpack(config) {
config.experiments = {
asyncWebAssembly: true,
layers: true,
};

return config;
},
};

const plugins = [
Expand Down
Loading
Loading