李富豪 пре 1 година
родитељ
комит
c99d8545ac
5 измењених фајлова са 131 додато и 217 уклоњено
  1. 0 80
      app/api/bigModel/route.ts
  2. 1 3
      app/client/platforms/bigmodel.ts
  3. 9 12
      app/components/chat.tsx
  4. 0 1
      package.json
  5. 121 121
      yarn.lock

+ 0 - 80
app/api/bigModel/route.ts

@@ -1,80 +0,0 @@
-import { NextResponse } from 'next/server';
-import mysql from 'mysql2/promise';
-
-// 创建全局的 MySQL 连接池
-const pool = mysql.createPool({
-  connectionLimit: 100,
-  host: '60.204.184.98', // 服务器地址
-  port: 33308,
-  user: 'chat',
-  password: 'DZzx6ACMhinTtTtS', // 密码
-  database: 'chat',
-})
-
-interface Request {
-  id: string;
-  messages: {
-    id: string;
-    date: string;
-    role: "system" | "user" | "assistant";
-    content: string;
-  }[];
-}
-
-// 插入数据
-export async function POST(req: any) {
-  try {
-    // 从连接池中获取连接
-    const connection = await pool.getConnection()
-    const data: Request = await req.json();
-    const id = data.id;
-    const messages = data.messages;
-
-    const [rows, fields] = await connection.query('SELECT * FROM dialog where id = ?', [id]);
-
-    if ((rows as any).length === 0) {
-      // 执行 MySQL 添加头表
-      await connection.execute('INSERT INTO dialog (id, create_time) VALUES (?,?)', [id, new Date])
-    }
-
-    messages.forEach(async function (message) {
-      const detailId = message.id;
-      const role = message.role;
-      const createDate = message.date;
-      const content = message.content;
-      const [detailRows, fields] = await connection.query('SELECT * FROM dialog_detail where id = ?', [detailId]);
-      if ((detailRows as any).length === 0) {
-        // 执行 MySQL 添加明细表
-        await connection.execute('INSERT INTO dialog_detail (id,dialog_id,type,content,create_by, create_time) VALUES (?, ?, ?,?,?,?)', [detailId, id, role, content, role, createDate])
-      }
-    });
-
-    // 释放连接回连接池
-    connection.release()
-
-    return NextResponse.json({ message: 'success', data: {} }, { status: 200 })
-  } catch (e) {
-    console.error('Error:', e)
-    return NextResponse.json({ message: 'error' }, { status: 500 })
-  }
-}
-
-// 查询数据
-export async function GET() {
-  try {
-    // 从连接池中获取连接
-    const connection = await pool.getConnection()
-
-    // 执行 MySQL 查询
-    const [rows, fields] = await connection.query('SELECT he.id,he.dialog_name,de.id did,de.dialog_id,de.type,de.content,de.create_time ' +
-      'FROM dialog he left join dialog_detail de on he.id = de.dialog_id order by he.create_time desc, he.id , de.create_time, type desc')
-
-    // 释放连接回连接池
-    connection.release()
-
-    return NextResponse.json({ message: 'success', data: rows }, { status: 200 })
-  } catch (e) {
-    console.error('Error:', e)
-    return NextResponse.json({ message: 'error' }, { status: 500 })
-  }
-}

+ 1 - 3
app/client/platforms/bigmodel.ts

@@ -64,7 +64,6 @@ export class BigModelApi implements LLMApi {
         signal: controller.signal,
         headers: {
           'Content-Type': 'application/json',
-          Authorization: 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImQwNDljOTY1LWZiYjYtNDIyNy1iNWExLWEwZGYwMWRmMzE5YyJ9.Ij4Ztl-MX1jrJHBPg7NV35MiaXLTyrSdMlwQaKZsGI0S9BD6TZFrRo6yqhXsSX2K8-hhYLTipE7_lO69cnZyPw',
         },
       };
 
@@ -78,7 +77,6 @@ export class BigModelApi implements LLMApi {
         if (finished || controller.signal.aborted) {
           responseText += remainText;
           if (responseText?.length === 0) {
-            // options.onError?.(new Error("empty response from server"));
             options.onError?.(new Error("请求已中止,请检查网络环境。"));
           }
           return;
@@ -108,7 +106,7 @@ export class BigModelApi implements LLMApi {
 
       fetchEventSource(chatPath, {
         ...chatPayload,
-        async onopen(res) {
+        async onopen(res: any) {
           clearTimeout(requestTimeoutId);
           const contentType = res.headers.get("content-type");
 

+ 9 - 12
app/components/chat.tsx

@@ -921,9 +921,16 @@ function _Chat() {
         }
       })
       setAppList(list);
-      if (!session.appId) {
+      const appId = localStorage.getItem('appId');
+      let newAppValue = '';
+      if (appId) {
+        setAppValue(appId);
+        newAppValue = appId;
+      } else {
         setAppValue(list[0]?.value);
+        newAppValue = list[0]?.value;
       }
+      chatStore.updateCurrentSession((session) => (session.appId = newAppValue));
     } catch (error) {
       console.error(error);
     } finally {
@@ -932,17 +939,9 @@ function _Chat() {
   }
 
   useEffect(() => {
-    if (session.appId) {
-      setAppValue(session.appId);
-    }
     init();
   }, [])
 
-  useEffect(() => {
-    chatStore.updateCurrentSession((session) => (session.appId = appValue as string));
-  }, [appValue])
-
-  // auto grow input
   const [inputRows, setInputRows] = useState(2);
   const measure = useDebouncedCallback(
     () => {
@@ -1479,9 +1478,7 @@ function _Chat() {
                 onChange={(value) => {
                   setAppValue(value);
                   localStorage.clear();
-                  chatStore.updateCurrentSession((session) => (session.appId = value as string));
-                  chatStore.updateCurrentSession((session) => (session.messages = []));
-                  chatStore.updateCurrentSession((session) => (session.id = ''));
+                  localStorage.setItem('appId', value as string);
                   location.reload()
                 }}
               />

+ 0 - 1
package.json

@@ -34,7 +34,6 @@
     "js-export-excel": "^1.1.4",
     "lodash-es": "^4.17.21",
     "mermaid": "^10.6.1",
-    "mysql2": "^3.11.0",
     "nanoid": "^5.0.3",
     "next": "^14.1.1",
     "node-fetch": "^3.3.1",

Разлика између датотеке није приказан због своје велике величине
+ 121 - 121
yarn.lock


Неке датотеке нису приказане због велике количине промена