From 09f405dfd1cce97a54a5e6da7538979000290f99 Mon Sep 17 00:00:00 2001 From: wood Date: Sat, 26 Aug 2023 08:43:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=B5=8B=E6=9C=89=E6=95=88=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=94=B9=E4=B8=BA=E5=90=91openai=E5=8F=91?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=AF=B7=E6=B1=82=EF=BC=8C=E5=BD=93=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=B8=BA=E6=AD=A3=E7=A1=AE=E6=97=B6=E4=B8=BA=E6=9C=89?= =?UTF-8?q?=E6=95=88=20Fixes=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index dd29fee..7d0879e 100644 --- a/index.html +++ b/index.html @@ -561,10 +561,42 @@ console.error(error); errors['modelsCheck'] = error.message; } + // 是否有效查询 + async function checkCompletion(apiKey, apiUrl) { + const urlCompletion = `${apiUrl}/v1/chat/completions`; + const headers = { + "Authorization": "Bearer " + apiKey, + "Content-Type": "application/json" + }; + const postBody = JSON.stringify({ + "model": "gpt-3.5-turbo", + "messages": [{ + "role": "user", + "content": "Hello" + }], + "max_tokens": 5 + }); + + let response = await fetch(urlCompletion, { + method: 'POST', + headers: headers, + body: postBody + }); + + let data = await response.json(); + // 判断请求是否成功 + if (response.status === 200) { + return ['✅', data.usage.total_tokens]; // 返回状态和 total_tokens + } else { + return ['❌', null]; + } + } + // 调用 checkCompletion 函数并获取结果 + let completionCheckResult = await checkCompletion(apiKey, apiUrl); //返回值 - return [totalAmount, totalUsage, remaining, formattedDate, GPT35CheckResult, GPT4CheckResult, GPT432kCheckResult, isSubscrible, SubInformation, setid, errors, GPT35CheckSuccess]; + return [totalAmount, totalUsage, remaining, formattedDate, GPT35CheckResult, GPT4CheckResult, GPT432kCheckResult, isSubscrible, SubInformation, setid, errors, GPT35CheckSuccess, completionCheckResult]; } catch (error) { - return ["Error", null, null, null, null, null, null, null]; + return ["Error", null, null, null, null, null, null, null, null]; } } @@ -728,11 +760,13 @@ // 是否有效列 - let isSubscriptionValid = document.createElement("td"); - isSubscriptionValid.textContent = data[4] === '✅' ? '🥰' : '🥶'; // 使用 GPT35CheckResult 的值进行判断 - // 添加自定义类名 - isSubscriptionValid.classList.add('emoji'); - row.appendChild(isSubscriptionValid); + let completionCheckResultCell = document.createElement("td"); + completionCheckResultCell.innerHTML = `${data[12][0]}
消耗${data[12][1]} tokens`; // 使用 innerHTML 添加两行内容 + row.appendChild(completionCheckResultCell); + // let isSubscriptionValid = document.createElement("td"); + // isSubscriptionValid.textContent = data[4] === '✅' ? '✅' : '❌'; // 使用 GPT35CheckResult 的值进行判断 + + // row.appendChild(completionCheckResultCell); }