From d8aa80fa0b5952f5941e36698f675b0fb1b6387d Mon Sep 17 00:00:00 2001 From: xiaofan <2023210156@qq.com> Date: Wed, 5 Jun 2024 09:21:28 +0800 Subject: [PATCH] xf --- answer.py | 34 -------------------------- docs/问题反馈/常见问题.md | 4 ++-- src/pages/MyForm.js | 40 ++++++++++++++++++------------- 3 files changed, 26 insertions(+), 52 deletions(-) delete mode 100644 answer.py diff --git a/answer.py b/answer.py deleted file mode 100644 index 7686223..0000000 --- a/answer.py +++ /dev/null @@ -1,34 +0,0 @@ -import os -import json -import requests - -from pdfminer.high_level import extract_text -import re - -def send_pdf_and_get_response(message): - # Moonshot API 密钥 - MOONSHOT_API_KEY = "fea58b082997a69f199264ce8221430a.zC0hu8lce49CNBPJ" - - # 构造请求的 headers - headers = { - 'Content-Type': 'application/json', - 'Authorization': f'Bearer {MOONSHOT_API_KEY}', - } - # 构造请求数据 - data = { - "model": "glm-4", # Moonshot 模型 - "messages": [ - {"role": "user", "content":message} - ], - "temperature": 0.01, # 温度参数,控制助手回复的多样性 - } - - # 发送 POST 请求 - response = requests.post('https://open.bigmodel.cn/api/paas/v4/chat/completions', headers=headers, data=json.dumps(data)) - response_json = response.json() - - # 提取助手的回复 - assistant_response = response_json['choices'][0]['message']['content'] - - return assistant_response -print(send_pdf_and_get_response(1)) \ No newline at end of file diff --git a/docs/问题反馈/常见问题.md b/docs/问题反馈/常见问题.md index 35b317a..24780a6 100644 --- a/docs/问题反馈/常见问题.md +++ b/docs/问题反馈/常见问题.md @@ -4,7 +4,7 @@ sidebar_position: 1 --- import { MDXCreateElement } from '@mdx-js/react'; -import MyForm from '../../src/pages/MyForm'; +import YourComponent from '../../src/pages/MyForm'; # 常见问题 @@ -25,4 +25,4 @@ import MyForm from '../../src/pages/MyForm'; ## 提出你的问题 - + diff --git a/src/pages/MyForm.js b/src/pages/MyForm.js index 85fc7b9..022080f 100644 --- a/src/pages/MyForm.js +++ b/src/pages/MyForm.js @@ -1,26 +1,34 @@ -// MyForm.js -import React, { useRef } from 'react'; +import React, { useState } from 'react'; +import axios from 'axios'; -const MyForm = () => { - const inputRef = useRef(null); +const YourComponent = () => { + const [message, setMessage] = useState(''); + const [assistantResponse, setAssistantResponse] = useState(''); - const handleSubmit = (event) => { + const handleSubmit = async (event) => { event.preventDefault(); - const inputValue = event.target.inputText.value; - alert('AI智能回答:' + inputValue); - - // 清空输入框的值 - inputRef.current.value = ''; - // 在这里可以添加向后端发送数据的逻辑 + try { + const response = await axios.post('http://localhost:5000/moonshot', { message }); + setAssistantResponse(response.data.assistantResponse); + } catch (error) { + console.error('Error communicating with backend:', error); + } }; return ( -
- - -
+
+
+ setMessage(e.target.value)} /> + +
+
+ AI回复: {assistantResponse} +
+
); }; -export default MyForm; + +export default YourComponent; +