Skip to content

Commit ed3de17

Browse files
committed
feat: 支持查询是否支持GPT4模型
1 parent e8e4925 commit ed3de17

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/pages/index.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ async function submit(key) {
3434
'Authorization': `Bearer ${key}`
3535
}
3636
// 查是否订阅
37-
// const subscription = await fetch("https://openai.1rmb.tk/v1/dashboard/billing/subscription", {
3837
const subscription = await fetch("/api/v1/dashboard/billing/subscription", {
3938
method: 'get',
4039
headers: headers
@@ -48,18 +47,39 @@ async function submit(key) {
4847
const subscriptionData = await subscription.json()
4948
// console.log(subscriptionData);
5049
// console.log(subscriptionData.plan.id);
50+
const billingendDate = Math.floor(Date.now() / 1000 + 24 * 60 * 60);
51+
const billingstartDate = new Date(billingendDate - 90 * 24 * 60 * 60);
52+
53+
// 赠送额度有效期
5154
const endDate = subscriptionData.access_until
5255
const startDate = new Date(endDate - 90 * 24 * 60 * 60);
5356
console.log(formatDate(endDate, "YYYY-MM-DD"));
5457
console.log(formatDate(startDate, "YYYY-MM-DD"));
55-
// const response = await fetch(`https://openai.1rmb.tk/v1/dashboard/billing/usage?start_date=${formatDate(startDate, "YYYY-MM-DD")}&end_date=${formatDate(endDate, "YYYY-MM-DD")}`, {
56-
const response = await fetch(`/api/v1/dashboard/billing/usage?start_date=${formatDate(startDate, "YYYY-MM-DD")}&end_date=${formatDate(endDate, "YYYY-MM-DD")}`, {
58+
// const response = await fetch(`/api/v1/dashboard/billing/usage?start_date=${formatDate(startDate, "YYYY-MM-DD")}&end_date=${formatDate(endDate, "YYYY-MM-DD")}`, {
59+
60+
// 查询90天内的使用情况
61+
const response = await fetch(`/api/v1/dashboard/billing/usage?start_date=${formatDate(billingstartDate, "YYYY-MM-DD")}&end_date=${formatDate(billingendDate, "YYYY-MM-DD")}`, {
5762
method: 'get',
5863
headers: headers
5964
})
6065

6166
const usageData = await response.json();
6267
console.log(usageData);
68+
69+
// 获取apiKey支持的最高GPT模型
70+
const modelResponse = await fetch(`/api/v1/models`, {
71+
method: 'get',
72+
headers: headers
73+
});
74+
const modelData = await modelResponse.json();
75+
const gptModels = modelData.data.filter(model => model.id.includes("gpt"));
76+
const highestGPTModel = gptModels.reduce((prev, current) => {
77+
const prevVersion = parseFloat(prev.id.split("-")[1]);
78+
const currentVersion = parseFloat(current.id.split("-")[1]);
79+
return (currentVersion > prevVersion) ? current : prev;
80+
});
81+
// console.log(highestGPTModel);
82+
const GPTModel = highestGPTModel.id
6383
// 账号类型
6484
// const plan = subscriptionData.plan.title
6585
const plan = (subscriptionData.plan.title === "Pay-as-you-go") ? "Pay-as-you-go" : subscriptionData.plan.id;
@@ -71,7 +91,7 @@ async function submit(key) {
7191
// 剩余额度
7292
const total_available = total_granted - total_used;
7393

74-
return { plan, total_granted, total_used, total_available, endDate, startDate }
94+
return { plan, total_granted, total_used, total_available, endDate, startDate, GPTModel }
7595

7696
}
7797

@@ -90,10 +110,6 @@ export default function Home() {
90110
const [isLoading, setIsLoading] = useState(true);
91111
const [proxylink, setproxyLink] = useState("");
92112

93-
// const router = useRouter();
94-
95-
96-
97113
useEffect(() => {
98114
const { origin } = location;
99115
setproxyLink(`${origin}/api`);
@@ -211,8 +227,11 @@ export default function Home() {
211227
<p>额度总量:{balance.total_granted}</p>
212228
<p>已用额度:{balance.total_used}</p>
213229
<p>剩余额度:{balance.total_available}</p>
230+
<p>最高模型:{balance.GPTModel}</p>
231+
<p>有效期为赠送额度的有效期</p>
214232
<p>有效期起:{formatDate(balance.startDate)}</p>
215233
<p>有效期止:{formatDate(balance.endDate)}</p>
234+
216235
</div>
217236
)}
218237

0 commit comments

Comments
 (0)