-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add token show switch #102
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "chat_gpt" | ||
version = "0.0.7" | ||
version = "1.0.0" | ||
description = "ChatGPT-Desktop" | ||
authors = ["orangelckc", "bilibili-ayang"] | ||
license = "MIT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码是针对一个名为 "chat_gpt" 的包进行版本控制和描述等的设置。从代码看来,这里将原先的版本号 "0.0.7" 更新为了 "1.0.0"。除此之外,其中还有作者和许可证信息的设置。目前代码看上去没有发现明显的问题或潜在风险,建议可以提交更新。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
<script setup lang="ts"> | ||
import { getName } from '@tauri-apps/api/app' | ||
import multiAvatar from '@multiavatar/multiavatar' | ||
|
||
const props = defineProps<{ value?: string }>() | ||
|
||
const avatar = computed(() => | ||
multiAvatar(props.value || import.meta.env.VITE_APP_NAME) | ||
) | ||
const appName = ref('') | ||
|
||
const avatar = computed(() => multiAvatar(props.value || appName.value)) | ||
|
||
onMounted(async () => { | ||
appName.value = await getName() | ||
}) | ||
</script> | ||
|
||
<template> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码主要实现了一个基于multiavatar库的头像组件,并引入了@tauri-apps/api/app中的getName函数来获取应用程序名称。以下是一些关于此代码段的潜在问题和改进建议:
希望这些反馈对您有所帮助。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ const marked = new MarkdownIt({ | |
.use(MarkdownItHighlight) | ||
.use(copyCode) | ||
|
||
const { uuid } = storeToRefs(useSettingsStore()) | ||
const { uuid, isTokenUsage } = storeToRefs(useSettingsStore()) | ||
const { sessionDataList, currentSession } = storeToRefs(useSessionStore()) | ||
const { currentRole } = storeToRefs(useRoleStore()) | ||
|
||
|
@@ -128,7 +128,9 @@ watch([currentSession, sessionDataList], () => { | |
class="w-12!" | ||
:value="item.is_ask ? uuid : currentRole?.name" | ||
/> | ||
<span class="text-gray text-xs">{{ calcToken(item) }}</span> | ||
<span class="text-gray text-xs" v-if="isTokenUsage"> | ||
{{ calcToken(item) }} | ||
</span> | ||
</div> | ||
<div | ||
class="relative flex w-[calc(100%-8rem)] flex-col gap-2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码的修改没有明显的错误风险,但可以提出以下改进建议:
总体而言,这段代码风格良好,逻辑清晰,并且没有明显的潜在错误。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,14 @@ const copyInfo = async () => { | |
} | ||
|
||
await writeText(JSON.stringify(info)) | ||
|
||
Message.success('复制成功') | ||
} | ||
|
||
const copyQQGroup = () => { | ||
writeText('473033518') | ||
|
||
Message.success('群号已复制,无法跳转则自行添加') | ||
} | ||
|
||
onMounted(async () => { | ||
|
@@ -49,7 +57,7 @@ onMounted(async () => { | |
</div> | ||
<span>{{ appInfo.appName }}</span> | ||
<span>v{{ appInfo.appVersion }}</span> | ||
<a class="cursor-pointer" @click="copyInfo">复制电脑信息</a> | ||
<a class="cursor-pointer" @click="copyInfo">复制信息</a> | ||
<a href="https://github.com/ChatGPT-Desktop/ChatGPT-Desktop/issues/new"> | ||
BUG 反馈 | ||
</a> | ||
|
@@ -65,11 +73,19 @@ onMounted(async () => { | |
</a> | ||
|
||
<span>官方社区</span> | ||
<div> | ||
<div class="flex gap-3"> | ||
<a href="https://discord.gg/jg4waryfA6" class="flex items-center gap-2"> | ||
<img src="@/assets/image/discord.svg" /> | ||
Discord | ||
</a> | ||
<a | ||
href="https://qm.qq.com/cgi-bin/qm/qr?k=vhU6EACVQqfxoXlVKAWCBE_dXH_qpxn2&jump_from=webapi&authKey=YTGKMbApCUrmxHWV0te4NFBWbN7YQViDrTZPH8zIdIzZLgs4xLQhcKxgaCFwqSx2" | ||
class="flex items-center gap-2" | ||
@click="copyQQGroup" | ||
> | ||
<img src="@/assets/image/qq.png" width="32" /> | ||
QQ群 | ||
</a> | ||
</div> | ||
|
||
<div class="flex flex-col gap-3" v-if="contributors.length"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码的主要功能是在网页中添加一些链接和按钮,同时增加了一个复制信息和复制QQ群号的功能。以下是我的一些建议:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ const settingsStore = useSettingsStore() | |
const { toggleTheme } = settingsStore | ||
const { themeMode, autoStart, isRememberPosition, proxy } = | ||
storeToRefs(settingsStore) | ||
|
||
const refresh = () => { | ||
window.location.reload() | ||
} | ||
</script> | ||
|
||
<template> | ||
|
@@ -45,6 +49,11 @@ const { themeMode, autoStart, isRememberPosition, proxy } = | |
<li> | ||
<i>开启代理:</i> | ||
<a-switch v-model="proxy.bypass" type="round"></a-switch> | ||
<span class="text-sm text-[var(--color-text-3)]" v-show="proxy.bypass"> | ||
填写代理地址后,请点击<span class="mark cursor-pointer" @click="refresh" | ||
>重启</span | ||
> | ||
</span> | ||
</li> | ||
|
||
<li v-show="proxy.bypass"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码主要是一个Vue组件的代码片段,它从一个名为 在模板中,这个组件渲染了一个开关控件,用于启用或禁用代理。如果启用代理,则会显示一个提示,告诉用户需要填写代理地址并点击“重启”按钮才能使代理生效。 对于这段代码的代码审查和改进建议,建议考虑以下几点:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<script setup lang="ts"> | ||
const { apiKey, isMemory, modalParams } = storeToRefs(useSettingsStore()) | ||
const { apiKey, isMemory, modalParams, isTokenUsage } = storeToRefs( | ||
useSettingsStore() | ||
) | ||
|
||
const totalCredit = ref(0) | ||
const usedCredit = ref(0) | ||
|
@@ -36,6 +38,14 @@ watch( | |
<li> | ||
<i>记忆模式:</i> | ||
<a-switch v-model="isMemory" type="round" /> | ||
<span class="text-sm text-[var(--color-text-3)]" | ||
>开启记忆模式会加倍消耗 token</span | ||
> | ||
</li> | ||
|
||
<li> | ||
<i>Token 用量:</i> | ||
<a-switch v-model="isTokenUsage" type="round" /> | ||
</li> | ||
|
||
<li> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码的功能是使用Vue.js框架实现一个交互式设置页面。以下是我的代码审查建议:
以上是我的代码审查建议,希望能对你有所帮助。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import { configDir } from '@tauri-apps/api/path' | ||
import { appConfigDir } from '@tauri-apps/api/path' | ||
import Database from 'tauri-plugin-sql-api' | ||
import type { TableName, TablePayload, WherePayload } from '@/types' | ||
|
||
const dbFile = import.meta.env.DEV ? 'sql.dev.db' : 'sql.db' | ||
const db = await Database.load( | ||
`sqlite:${await configDir()}/${import.meta.env.VITE_CONFIG_PATH}/${dbFile}` | ||
) | ||
const db = await Database.load(`sqlite:${await appConfigDir()}/${dbFile}`) | ||
|
||
/** | ||
* sql 的字符串参数需要在加一个冒号 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码看起来比较简单,有以下一些改进和潜在风险:
总体而言,这段代码看起来符合预期,但是可以通过添加更多的异常处理来提高代码的稳定性。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ export const useSettingsStore = defineStore( | |
// modal设置参数 | ||
const modalParams = reactive({ temperature: 0.6, max_tokens: 2000 }) | ||
|
||
// token 用量 | ||
const isTokenUsage = ref(false) | ||
|
||
// 绑定快捷键 | ||
const registerKey = async () => { | ||
await unregisterAll() | ||
|
@@ -133,6 +136,7 @@ export const useSettingsStore = defineStore( | |
isRememberPosition, | ||
proxy, | ||
modalParams, | ||
isTokenUsage, | ||
toggleTheme | ||
} | ||
}, | ||
|
@@ -147,7 +151,8 @@ export const useSettingsStore = defineStore( | |
'isMemory', | ||
'isRememberPosition', | ||
'proxy', | ||
'modalParams' | ||
'modalParams', | ||
'isTokenUsage' | ||
] | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码中,定义了一个名为 useSettingsStore 的 export const。该函数返回一个包含多个属性的对象。 首先,这个函数使用 defineStore 方法来创建一个响应式仓库。在该仓库中,有多个状态变量和方法:
需要注意的是,在函数的第一部分,添加了一个新的响应式状态变量 整体来看,代码逻辑较为简单,没有明显的 bug 风险。如果想要改进的话,可以考虑为每个状态变量编写对应的 getter 和 setter 方法,增强代码的可读性和可维护性。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { MessageData, SessionData } from '@/types' | ||
import GPT3Tokenizer from 'gpt3-tokenizer' | ||
import type { MessageData, SessionData } from '@/types' | ||
|
||
const tokenizer = new GPT3Tokenizer({ type: 'gpt3' }) | ||
|
||
|
@@ -37,7 +37,7 @@ export const getOpenAIKey = () => { | |
const { apiKey } = useSettingsStore() | ||
|
||
if (!apiKey) { | ||
Message.warning('请先填写 OpenAi API Key') | ||
Message.warning('请先填写 OpenAi API KEY') | ||
return false | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码看起来是用于处理文本数据的。代码中使用了一个叫做"gpt3-tokenizer"的库,用于对文本进行分词处理。 在代码审查方面,似乎没有特别大的安全风险。不过可以注意到第37行的警告信息有个拼写错误,将"KEY"写成了"Key"。可能需要修正一下。 同时,可以建议增加一些注释或者函数命名等方式,以提高代码可读性。比如说,在函数getOpenAIKey中,不太清楚变量useSettingsStore具体是从哪里引入的。如果有注释或者较为详细的函数命名会更好。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { message } from '@tauri-apps/api/dialog' | ||
import { getName } from '@tauri-apps/api/app' | ||
|
||
/** | ||
* 错误弹框 | ||
* @param errorMessage 错误信息 | ||
*/ | ||
export const dialogErrorMessage = (errorMessage: string) => { | ||
export const dialogErrorMessage = async (errorMessage: string) => { | ||
const appName = await getName() | ||
|
||
message(errorMessage, { | ||
title: import.meta.env.VITE_APP_NAME, | ||
title: appName, | ||
type: 'error' | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段代码看起来没有明显的错误风险。下面是一些建议:
希望对你有所帮助,祝你编码愉快! |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码补丁主要修改了几个图片的引用路径,并更新了支持的操作系统信息。
代码风格看起来整洁,没有明显的bug风险。但是可以考虑一下以下改进建议: