Skip to content

Commit

Permalink
🐛 fix for custom model
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed May 29, 2024
1 parent 09bbbb7 commit a249aa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/components/DirectTokenize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const DirectTokenInner = ({
const [config, setConfig] = useState<TokenizerDefine | null>(
initConfig || null
);
const { getQueryParam } = useQueryParams();

return (
<>
Expand All @@ -54,20 +55,15 @@ export const DirectTokenInner = ({
config={config}
inputValue={inputValue}
onChange={onChange}
getInitValue={() => {
return getQueryParam("content");
}}
></TokenizerPanel>
)}
</>
);
};

const useInitContent = () => {
const { getQueryParam } = useQueryParams();
return useState(() => {
const content = getQueryParam("content");
return content || null;
})[0];
};

export const DirectTokenize = () => {
const [id, setId] = useState(1);
const { setQueryParam, getQueryParam, deleteQueryParam } = useQueryParams();
Expand All @@ -91,8 +87,6 @@ export const DirectTokenize = () => {
[setQueryParam]
);

const initContent = useInitContent();

return (
<DirectTokenizeContainer>
<h3>
Expand All @@ -111,7 +105,6 @@ export const DirectTokenize = () => {
key={id}
onConfigChanged={onConfigChanged}
initConfig={initConfig}
inputValue={initContent}
onChange={(value) => {
// 只写入 1024 字符以内的
if (value.length < 1024) {
Expand Down
6 changes: 4 additions & 2 deletions src/components/TokenizerPanel/TokenizerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ const TokenizerInfo = ({
{Object.entries(info).map(([key, value]) => {
if (key === "chat_template") {
let chat_template_content = value;
if (typeof value === "object") {
if (value && typeof value === "object") {
chat_template_content = value.default ?? Object.values(value)[0];
}
if (typeof chat_template_content !== "string") {
Expand Down Expand Up @@ -344,15 +344,17 @@ export function TokenizerPanel({
config,
onChange,
inputValue,
getInitValue,
}: {
config: TokenizerDefine;
onChange?: (content: string) => any;
inputValue?: string | null;
getInitValue?: () => string | undefined | null;
}) {
const { tokenizer } = useTokenizer(config);

const [value, setValue] = useState(
inputValue ?? "Potato potato tomato potato."
() => getInitValue?.() ?? "Potato potato tomato potato."
);
const hwtRef = useRef(null as null | Editor);

Expand Down

0 comments on commit a249aa9

Please sign in to comment.