Skip to content

Commit

Permalink
feat: 本地存储chatGPT令牌
Browse files Browse the repository at this point in the history
  • Loading branch information
orangelckc committed Jan 25, 2023
1 parent 724c688 commit 2584e53
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/api/chatGTP.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

import { MANAGE } from "@/constants";
import { getStore } from "@/store";
import { Body } from "@tauri-apps/api/http";
import { getQueryData } from ".";

const API_KEY = "";
const API_KEY = await getStore(MANAGE.gptToken) || ''
const MAX_TOKENS = 100;
const MODEL = "text-davinci-003"; // 功能最全的模型
// const MODEL = "text-curie-001 "; // 适合聊天的模型
Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const MANAGE = {
follow: 'manage.follow',
gift: 'manage.gift',
welcome: 'manage.welcome',
gptToken: 'manage.gptToken'
};

export const MESSAGE_TYPE = {
Expand Down
4 changes: 3 additions & 1 deletion src/views/Robot/message/robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const manage = reactive({
follow: await (getStore(MANAGE.follow)) || false,
gift: await (getStore(MANAGE.gift)) || false,
welcome: await (getStore(MANAGE.welcome)) || false,
gptToken: await getStore(MANAGE.gptToken) || ''
});

// 更新store,做持久化
Expand Down Expand Up @@ -169,6 +170,7 @@ const init_listener = async () => {
messages.push(...autoSlice(`@${manage.hostName} 当前粉丝数${curFans},今日已增长${curFans - todayFans},冲~`));
return;
}
if (manage.gptToken === '') return
const result = await chatGTPApi(question);
if (!result) return;
messages.push(...autoSlice(`@${formatUname(uname)}:${result}`));
Expand Down Expand Up @@ -242,7 +244,7 @@ watch(active, async (value) => {
console.log("已得到直播间信息");
clearInterval(liveInfoIntever);
msgInterval = setInterval(() => {
if (!active.value && messages.length === 0) {
if (!active.value && messages.length === 0) {
clearInterval(msgInterval);
return;
}
Expand Down
10 changes: 9 additions & 1 deletion src/views/Robot/room.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,18 @@ const stopRecord = async () => {
<q-checkbox v-model="manage.welcome" label="欢迎词" />
<q-toggle v-model="active" size="md" :disable="!connected">
<div class="i-carbon-machine-learning text-2xl font-bold" :class="active ? 'text-green' : 'text-gray'" />
<q-tooltip v-if="active">
<q-tooltip v-if="connected">
开启机器人
</q-tooltip>
</q-toggle>
<q-icon class="i-carbon-add-alt" color="primary">
<q-tooltip>
修改GPT-Token
</q-tooltip>
<q-popup-proxy>
<q-input v-model="manage.gptToken" dense autofocus />
</q-popup-proxy>
</q-icon>
</div>
</div>
</q-card-section>
Expand Down

0 comments on commit 2584e53

Please sign in to comment.