Browse Source

改为输入框

visuddhinanda 1 year ago
parent
commit
6f07e609ad
1 changed files with 67 additions and 36 deletions
  1. 67 36
      dashboard-v4/dashboard/src/components/nut/test/AI.tsx

+ 67 - 36
dashboard-v4/dashboard/src/components/nut/test/AI.tsx

@@ -1,48 +1,79 @@
 import { Button, Input } from "antd";
+import { useState } from "react";
+interface IOpenAi {
+  model: string;
+  messages: Message[];
+  prompt: string;
+  temperature: number;
+  stream: boolean;
+}
 
+interface Message {
+  role: string;
+  content: string;
+}
 const AI = () => {
-  interface IOpenAi {
-    model: string;
-    messages: Message[];
-    prompt: string;
-    temperature: number;
-    stream: boolean;
-  }
-
-  interface Message {
-    role: string;
-    content: string;
-  }
-
-  const url =
-    "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
-  const key = "sk-ab723c6d5f6a4a3ca3ec362b0042ed94";
-  const model = "qwen-max-latest";
+  const [url, setUrl] = useState(
+    "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
+  );
+  const [key, setKey] = useState("");
+  const [model, setModel] = useState("qwen-max-latest");
+  const [concurrent, setConcurrent] = useState(10);
   return (
     <>
-      <Input placeholder="并发请求数量" />
+      <Input
+        placeholder="url"
+        value={url}
+        onChange={(event) => {
+          setUrl(event.target.value);
+        }}
+      />
+      <Input
+        placeholder="key"
+        value={key}
+        onChange={(event) => {
+          setKey(event.target.value);
+        }}
+      />
+      <Input
+        placeholder="model"
+        value={model}
+        onChange={(event) => {
+          setModel(event.target.value);
+        }}
+      />
+      <Input
+        placeholder="并发请求数量"
+        value={concurrent}
+        onChange={(event) => {
+          setConcurrent(parseInt(event.target.value));
+        }}
+      />
       <Button
         onClick={() => {
           console.info("model", model);
           // 模拟请求数据,这里假设是向模型发送的文本等请求内容,实际按接口要求调整
-          const requests: IOpenAi[] = Array.from({ length: 50 }, (_, i) => ({
-            model: model,
-            messages: [
-              {
-                role: "system",
-                content: "you are translate assistant",
-              },
-              {
-                role: "user",
-                content:
-                  "巴利文:‘‘ Sammā mānābhisamayā antamakāsi dukkhassā ’’ tiādīsu ( a . ni .7.9) pahānaṃ .\n中文译文:\n“通过正确(sammā)地觉悟(mānābhisamayā),他终结了(antamakāsi)痛苦(dukkhassa)”等(iti ādīsu)句子中,放弃(pahānaṃ)的含义被阐明。\n请从不同角度分析和评价译文,指出翻译错误,并给出建议的译文。\n",
-              },
-            ],
-            prompt:
-              "巴利文:‘‘ Sammā mānābhisamayā antamakāsi dukkhassā ’’ tiādīsu ( a . ni .7.9) pahānaṃ .\n中文译文:\n“通过正确(sammā)地觉悟(mānābhisamayā),他终结了(antamakāsi)痛苦(dukkhassa)”等(iti ādīsu)句子中,放弃(pahānaṃ)的含义被阐明。\n请从不同角度分析和评价译文,指出翻译错误,并给出建议的译文。\n",
-            temperature: 0.7,
-            stream: false,
-          }));
+          const requests: IOpenAi[] = Array.from(
+            { length: concurrent },
+            (_, i) => ({
+              model: model,
+              messages: [
+                {
+                  role: "system",
+                  content: "you are translate assistant",
+                },
+                {
+                  role: "user",
+                  content:
+                    "巴利文:‘‘ Sammā mānābhisamayā antamakāsi dukkhassā ’’ tiādīsu ( a . ni .7.9) pahānaṃ .\n中文译文:\n“通过正确(sammā)地觉悟(mānābhisamayā),他终结了(antamakāsi)痛苦(dukkhassa)”等(iti ādīsu)句子中,放弃(pahānaṃ)的含义被阐明。\n请从不同角度分析和评价译文,指出翻译错误,并给出建议的译文。\n",
+                },
+              ],
+              prompt:
+                "巴利文:‘‘ Sammā mānābhisamayā antamakāsi dukkhassā ’’ tiādīsu ( a . ni .7.9) pahānaṃ .\n中文译文:\n“通过正确(sammā)地觉悟(mānābhisamayā),他终结了(antamakāsi)痛苦(dukkhassa)”等(iti ādīsu)句子中,放弃(pahānaṃ)的含义被阐明。\n请从不同角度分析和评价译文,指出翻译错误,并给出建议的译文。\n",
+              temperature: 0.7,
+              stream: false,
+            })
+          );
 
           // 定义一个函数来发送单个 POST 请求
           const sendRequest = async (request: IOpenAi) => {