From 9b0db2cd2fb6f87ce8b64d9dcae8c220126a9b57 Mon Sep 17 00:00:00 2001 From: shuguang Date: Thu, 8 May 2025 20:56:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=88=86=E6=9E=90=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Code/index.tsx | 48 +++++----------------------------------- 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/src/pages/Code/index.tsx b/src/pages/Code/index.tsx index 90ad256..1e280fa 100644 --- a/src/pages/Code/index.tsx +++ b/src/pages/Code/index.tsx @@ -11,17 +11,8 @@ import useAIRequest from '@/hooks/useAIRequest'; const { Dragger } = Upload; const { TabPane } = Tabs; -interface AnalysisResponse { - id: string; - choices: { - message: { - content: string; - }; - }[]; -} const CodeAnalysisPage: React.FC = () => { - const [fileList, setFileList] = useState([]); const [loading, setLoading] = useState(false); const [analysisType, setAnalysisType] = useState<'er' | 'module'>('er'); const [analysisResult, setAnalysisResult] = useState(''); @@ -71,40 +62,12 @@ const CodeAnalysisPage: React.FC = () => { } setLoading(true); try { - const response = await fetch('http://8.218.106.190:3000/v1/chat/completions', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer sk-mw9ekhJlSj3GeGiw0hLRSHlwdkDFst8q6oBfQrW0L15QilbY' - }, - body: JSON.stringify({ - model: 'gpt-4o-mini', - messages: [ - { - role: 'user', - content: [ - { - type: 'text', - text: analysisType === 'er' - ? '请分析这段代码并生成对应的ER图,使用mermaid语法,用于计算机科学与技术毕业论文。分析要点:1. 实体关系 2. 属性定义 3. 关系类型' - : '请分析这段代码并生成数据流图,使用mermaid语法,用于计算机科学与技术毕业论文。。分析要点:1. 模块划分 2. 依赖关系 3. 调用流程' - }, - { - type: 'text', - text: codeContent - } - ] - } - ], - max_tokens: 2000 - }) - }); + // 删除未使用的 fetch 请求代码 - try { const content = await sendRequest([ { type: 'text', - text: analysisType === 'er' + text: analysisType === 'er' ? '请分析这段代码并生成对应的ER图,使用mermaid语法,用于计算机科学与技术毕业论文。分析要点:1. 实体关系 2. 属性定义 3. 关系类型' : '请分析这段代码并生成功能模块图,使用mermaid语法,用于计算机科学与技术毕业论文。。分析要点:1. 模块划分 2. 依赖关系 3. 调用流程' }, @@ -124,6 +87,8 @@ const CodeAnalysisPage: React.FC = () => { } catch (error) { console.error('分析失败:', error); message.error('分析失败,请重试'); + } finally { + setLoading(false); } }; @@ -152,7 +117,6 @@ const CodeAnalysisPage: React.FC = () => { value={analysisType} onChange={(e) => { setAnalysisType(e.target.value); - setFileList([]); setDiagramCode(''); setAnalysisResult(''); }} @@ -199,7 +163,7 @@ const CodeAnalysisPage: React.FC = () => { -