From 6c2da264db1b07b7bea209d60ae5a7d24fccce2c Mon Sep 17 00:00:00 2001 From: jialin Date: Wed, 2 Jul 2025 19:13:21 +0800 Subject: [PATCH] fix: image generating flickering, #1415 --- src/components/seal-form/simple-select.tsx | 5 -- src/global.less | 2 +- .../components/ground-embedding.tsx | 20 +++++- .../playground/components/ground-reranker.tsx | 31 ++++++-- .../playground/components/image-edit.tsx | 2 + src/pages/playground/config/samples.ts | 71 +++++++++++++++++++ 6 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 src/pages/playground/config/samples.ts diff --git a/src/components/seal-form/simple-select.tsx b/src/components/seal-form/simple-select.tsx index 777b8328..d0e560f8 100644 --- a/src/components/seal-form/simple-select.tsx +++ b/src/components/seal-form/simple-select.tsx @@ -53,7 +53,6 @@ const SimpleSelect: React.FC = (props) => { checked: false, indeterminate: false }); - const [searchValue, setSearchValue] = React.useState(''); const [optionsList, setOptionsList] = React.useState(options || []); const selectRef = React.useRef(null); @@ -79,8 +78,6 @@ const SimpleSelect: React.FC = (props) => { const isChecked = e.target.checked; const allValues = optionsList?.map((opt: any) => opt.value) || []; - console.log('isChecked', isChecked, allValues); - setAllSelection({ checked: isChecked, indeterminate: false @@ -163,8 +160,6 @@ const SimpleSelect: React.FC = (props) => { selectedValues.has(val) ); - console.log('isAllSelected', isAllSelected, selectedValues, allValues); - setAllSelection({ checked: isAllSelected, indeterminate: isSomeSelected && !isAllSelected diff --git a/src/global.less b/src/global.less index b39fc1bc..8b51bc1c 100644 --- a/src/global.less +++ b/src/global.less @@ -758,7 +758,7 @@ body { &.scatter { display: grid; - grid-template-columns: repeat(2, minmax(0, 1fr)); + grid-template-columns: repeat(auto-fit, minmax(48%, 1fr)); gap: 8px; } diff --git a/src/pages/playground/components/ground-embedding.tsx b/src/pages/playground/components/ground-embedding.tsx index ff80a43c..0f092042 100644 --- a/src/pages/playground/components/ground-embedding.tsx +++ b/src/pages/playground/components/ground-embedding.tsx @@ -29,6 +29,7 @@ import React, { } from 'react'; import { EMBEDDING_API, handleEmbedding } from '../apis'; import { extractErrorMessage } from '../config'; +import { embeddingSamples } from '../config/samples'; import { LLM_METAKEYS } from '../hooks/config'; import useEmbeddingWorker from '../hooks/use-embedding-worker'; import { useInitLLmMeta } from '../hooks/use-init-meta'; @@ -49,7 +50,6 @@ interface MessageProps { const GroundEmbedding: React.FC = forwardRef((props, ref) => { const { modelList } = props; - const messageId = useRef(0); const intl = useIntl(); const { workerRef, createWorker, postMessage, terminateWorker } = @@ -158,7 +158,7 @@ const GroundEmbedding: React.FC = forwardRef((props, ref) => { }, [textList, fileList]); const setMessageId = () => { - messageId.current = messageId.current + 1; + return inputListRef.current?.setMessageId?.(); }; const handleStopConversation = () => { @@ -425,6 +425,22 @@ const GroundEmbedding: React.FC = forwardRef((props, ref) => { messageListLengthCache.current = textList.length + fileList.length; }, [textList.length, fileList.length]); + useEffect(() => { + if (intl.locale || 'en-US') { + const sample = embeddingSamples[intl.locale]; + + if (sample) { + setTextList( + sample.map((item: string, index: number) => ({ + text: item, + uid: setMessageId(), + name: `Document ${index + 1}` + })) + ); + } + } + }, []); + return (
diff --git a/src/pages/playground/components/ground-reranker.tsx b/src/pages/playground/components/ground-reranker.tsx index 9376ec24..3c83c0bd 100644 --- a/src/pages/playground/components/ground-reranker.tsx +++ b/src/pages/playground/components/ground-reranker.tsx @@ -34,6 +34,7 @@ import React, { import styled from 'styled-components'; import { rerankerQuery } from '../apis'; import { extractErrorMessage } from '../config'; +import { rerankerSamples } from '../config/samples'; import { ParamsSchema } from '../config/types'; import { LLM_METAKEYS } from '../hooks/config'; import { useInitLLmMeta } from '../hooks/use-init-meta'; @@ -174,6 +175,30 @@ const GroundReranker: React.FC = forwardRef((props, ref) => { }; }); + const setMessageId = () => { + const uid = inputListRef.current?.setMessageId(); + return uid; + }; + + useEffect(() => { + if (intl.locale || 'en-US') { + const sample = rerankerSamples[intl.locale]; + if (sample) { + setTextList( + sample.documents.map((item: string, index: number) => ({ + text: item, + uid: setMessageId(), + name: `Document ${index + 1}`, + percent: undefined, + score: undefined, + rank: undefined + })) + ); + setQueryValue(sample.query); + } + } + }, []); + const viewCodeContent = useMemo(() => { return generateRerankCode({ api: '/v1/rerank', @@ -234,11 +259,6 @@ const GroundReranker: React.FC = forwardRef((props, ref) => { ); }; - const setMessageId = () => { - const uid = inputListRef.current?.setMessageId(); - return uid; - }; - const handleStopConversation = () => { requestToken.current?.cancel?.(); setLoading(false); @@ -460,6 +480,7 @@ const GroundReranker: React.FC = forwardRef((props, ref) => { = forwardRef((props, ref) => {
= forwardRef((props, ref) => { = { + 'zh-CN': [ + '最近哪家咖啡店评价最好?', + '附近有没有推荐的咖啡厅?', + '明天天气预报说会下雨。', + '北京是中国的首都。', + '我想找一个适合学习的地方。' + ], + 'en-US': [ + 'What are the best cafes nearby?', + 'Can you recommend a quiet coffee shop?', + 'I’m planning a trip to Japan next month.', + 'The capital of France is Paris.', + "I'm looking for a place to study." + ], + 'ja-JP': [ + '近くにおすすめのカフェはありますか?', + '静かな喫茶店を探しています。', + '明日の天気はどうですか?', + '富士山は日本で一番高い山です。', + '勉強に集中できる場所を知っていますか?' + ], + 'ru-RU': [ + 'Где находится ближайшая аптека?', + 'Можете подсказать, где купить лекарства?', + 'Погода сегодня очень хорошая.', + 'Я ищу кафе рядом с вокзалом.', + 'Как добраться до аэропорта?' + ] +}; + +export const rerankerSamples: Record< + string, + { + query: string; + documents: string[]; + } +> = { + 'zh-CN': { + query: '', + documents: [ + '保持规律的作息时间,晚上避免使用电子产品。', + '参加更多社交活动有助于提高情绪。', + '多喝咖啡可以让你更有精神。' + ] + }, + 'en-US': { + query: 'What are the benefits of regular exercise?', + documents: [ + 'Regular physical activity helps improve cardiovascular health and mental well-being.', + 'Eating too much sugar can lead to health issues.', + 'Exercise is often done in gyms or outdoors.' + ] + }, + 'ja-JP': { + query: '効果的な英語の勉強法は?', + documents: [ + '毎日少しずつでも英語に触れることが大切です。', + '睡眠時間を削ると集中力が低下します。', + '文法よりも単語を先に覚えましょう。' + ] + }, + 'ru-RU': { + query: 'Как улучшить концентрацию во время учёбы?', + documents: [ + 'Регулярные перерывы помогают поддерживать концентрацию.', + 'Учёба ночью может быть неэффективной.', + 'Прогулка на свежем воздухе улучшает работу мозга.' + ] + } +};