修复ChatGLM获取token方法,并且将非流式请求也接入

This commit is contained in:
aixianling
2023-05-18 14:18:18 +08:00
parent c179400d67
commit 8b3db98ffe
3 changed files with 42 additions and 20 deletions

View File

@@ -10,7 +10,7 @@
<el-form-item label="流式输出">
<el-switch v-model="settings.stream" :active-value="true" :inactive-value="false"/>
</el-form-item>
<el-form-item label="API KEY">
<el-form-item label="API KEY" v-if="isGPT">
<el-row class="w100">
<el-input v-model="settings.model.apiKey" clearable class="fill mar-r8"/>
<el-button type="text" @click="getModelAccount">应用</el-button>
@@ -55,7 +55,9 @@ export default {
},
computed: {
models: () => Object.values(models),
account: v => v.settings.account || {usage: 0, total: 0}
account: v => v.settings.account || {usage: 0, total: 0},
apiKey: v => v.settings.model.apiKey || "key无效或网络波动,请重新尝试",
isGPT: v => v.settings.model.name == "ChatGPT"
},
methods: {
initModel(model) {
@@ -68,12 +70,13 @@ export default {
}
}, 500)
},
getModelAccount() {
getModelAccount(c = 0) {
const ai = this.settings.model
console.log(ai)
if (ai.apiKey) {
this.loadingAccount = true
ai.getAccount().then(v => this.settings.account = v).finally(() => this.loadingAccount = false)
}
} else if (c < 5) setTimeout(() => this.getModelAccount(++c), 1000)
}
}
}