chatGPT部分完成

This commit is contained in:
aixianling
2023-05-15 17:58:00 +08:00
parent b773d87ff3
commit 8e894760a7
3 changed files with 18 additions and 11 deletions

View File

@@ -17,7 +17,7 @@ export default {
components: {Settings, Chat},
data() {
return {
showSettings: false,
showSettings: true,
setting: {
model: new ChatGPT(),
stream: true

View File

@@ -13,10 +13,10 @@
<el-form-item label="API KEY">
<el-input v-model="settings.model.apiKey" clearable @change="v=>settings.model.setApiKey(v),getModelAccount()"/>
</el-form-item>
<el-button type="text" @click="getModelAccount">刷新账号信息</el-button>
<el-row>
<el-form-item label="账号用户" class="fill color-999">{{ account.username }}</el-form-item>
<el-form-item label="账户余额" class="fill color-999">{{ [account.usage, account.total].join(" / ") }}</el-form-item>
<el-row v-loading="loadingAccount" element-loading-background="#272A37">
<el-form-item label="账号用户" class="fill">{{ account.username }}</el-form-item>
<el-form-item label="账户余额" class="fill">{{ [account.usage, account.total].join(" / ") }}</el-form-item>
<el-button type="text" @click="getModelAccount">刷新</el-button>
</el-row>
</el-form>
</section>
@@ -26,7 +26,6 @@
import AiModel from "../ui/AiModel";
import AiSelect from "../ui/AiSelect";
import * as models from "../utils/models";
import {scopy} from "../utils/tools";
export default {
@@ -38,14 +37,15 @@ export default {
emits: ["update:modelValue"],
data() {
return {
settings: {}
settings: {},
loadingAccount: false
}
},
watch: {
modelValue: {
immediate: true,
handler(v) {
this.settings = scopy(v)
this.settings = v
}
}
},
@@ -55,8 +55,11 @@ export default {
},
methods: {
getModelAccount() {
console.log(this.settings.model)
this.settings.model.getAccount?.().then(v => this.settings.account = v)
const ai = this.settings.model
if (ai.getAccount) {
this.loadingAccount = true
ai.getAccount().then(v => this.settings.account = v).finally(() => this.loadingAccount = false)
}
}
},
created() {
@@ -70,6 +73,10 @@ export default {
:deep(.el-form) {
.el-form-item__label {
color: #bbb;
}
.el-form-item__content {
color: white;
}

View File

@@ -55,7 +55,7 @@ export class ChatGPT extends BaseModel {
if (endDate) {
const startDate = new Date(endDate - 90 * 24 * 60 * 60);
const formattedDate = time => dayjs(time).format("YYYY-MM-DD")
return axios.get(`${ChatGPT.base}/v1/dashboard/billing/usage?start_date=${formattedDate(startDate * 1000)}&end_date=${formattedDate(endDate * 1000)}`,
return await axios.get(`${ChatGPT.base}/v1/dashboard/billing/usage?start_date=${formattedDate(startDate * 1000)}&end_date=${formattedDate(endDate * 1000)}`,
{headers}).then(res => res.json()).then(res => {
usages.total_usage = res.total_usage
const names = usages.account_name.split(" ")