From 881c36542ca9d9549ab26097189d084c70dda4b3 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Thu, 6 Apr 2023 16:02:35 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=BF=9E=E7=BB=AD=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/model/detail/components/InputDataModal.tsx | 11 +++++++---- src/service/events/generateQA.ts | 9 +++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pages/model/detail/components/InputDataModal.tsx b/src/pages/model/detail/components/InputDataModal.tsx index 3859e8f46..ca7ff155a 100644 --- a/src/pages/model/detail/components/InputDataModal.tsx +++ b/src/pages/model/detail/components/InputDataModal.tsx @@ -35,7 +35,7 @@ const InputDataModal = ({ const [importing, setImporting] = useState(false); const { toast } = useToast(); - const { register, handleSubmit } = useForm({ + const { register, handleSubmit, reset } = useForm({ defaultValues }); @@ -64,14 +64,17 @@ const InputDataModal = ({ title: res === 0 ? '导入数据成功,需要一段时间训练' : '数据导入异常', status: res === 0 ? 'success' : 'warning' }); - onClose(); + reset({ + text: '', + q: '' + }); onSuccess(); } catch (err) { console.log(err); } setImporting(false); }, - [modelId, onClose, onSuccess, toast] + [modelId, onSuccess, reset, toast] ); const updateData = useCallback( @@ -91,7 +94,7 @@ const InputDataModal = ({ onClose(); onSuccess(); }, - [defaultValues.q, onClose, onSuccess, toast] + [defaultValues, onClose, onSuccess, toast] ); return ( diff --git a/src/service/events/generateQA.ts b/src/service/events/generateQA.ts index b5c1d0186..843636004 100644 --- a/src/service/events/generateQA.ts +++ b/src/service/events/generateQA.ts @@ -97,18 +97,19 @@ export async function generateQA(next = false): Promise { } ) .then((res) => { - const rawContent = res?.data.choices[0].message?.content || ''; + const rawContent = res?.data.choices[0].message?.content || ''; // chatgpt 原本的回复 + const result = splitText(res?.data.choices[0].message?.content || ''); // 格式化后的QA对 // 计费 pushSplitDataBill({ - isPay: !userApiKey, + isPay: !userApiKey && result.length > 0, userId: dataItem.userId, type: 'QA', text: systemPrompt.content + text + rawContent, tokenLen: res.data.usage?.total_tokens || 0 }); return { - rawContent, // chatgpt 原本的回复 - result: splitText(res?.data.choices[0].message?.content || '') // 格式化后的QA对 + rawContent, + result }; }) )