Skip to content

Commit

Permalink
fix: Remove redundant code and normalize naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleurxxx committed Aug 17, 2024
1 parent a754872 commit cfb6489
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
31 changes: 14 additions & 17 deletions packages/plugins/robot/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<tiny-dropdown-item
v-for="item in AIModelOptions"
:key="item.label"
:class="{ 'selected-model': unrefSelectedModel === item.value }"
:class="{ 'selected-model': currentModel === item.value }"
@click="changeModel(item)"
>{{ item.label }}</tiny-dropdown-item
>
Expand Down Expand Up @@ -85,14 +85,14 @@
</div>
<token-dialog
:dialog-visible="tokenDialogVisible"
:current-model="currentModel"
:current-model="selectedModel"
@dialog-status="getTokenDialogStatus"
@token-status="updateTokenStatus"
></token-dialog>
</template>

<script>
import { ref, unref, onMounted, watch, watchEffect } from 'vue'
import { ref, onMounted, watch, watchEffect } from 'vue'
import {
Layout,
Row,
Expand Down Expand Up @@ -142,7 +142,7 @@ export default {
const inputContent = ref('')
const inProcesing = ref(false)
const selectedModel = ref(AIModelOptions[0])
let unrefSelectedModel = unref(AIModelOptions[0])
let currentModel = AIModelOptions[0]
const { confirm } = useModal()
const { pageSettingState, DEFAULT_PAGE } = usePage()
Expand All @@ -159,9 +159,9 @@ export default {
? JSON.stringify(sessionProcess)
: JSON.stringify({
foundationModel: {
manufacturer: unrefSelectedModel.manufacturer,
model: unrefSelectedModel.value,
token: localStorage.getItem(unrefSelectedModel.localKey)
manufacturer: currentModel.manufacturer,
model: currentModel.value,
token: localStorage.getItem(currentModel.modelKey)
},
messages: [],
displayMessages: [] // 专门用来进行展示的消息,非原始消息,仅作为展示但是不作为请求的发送
Expand Down Expand Up @@ -247,7 +247,7 @@ export default {
.catch((error) => {
switch (error.code) {
case 'CM001':
localStorage.removeItem(unrefSelectedModel.localKey)
localStorage.removeItem(currentModel.modelKey)
tokenDialogVisible.value = true
break
default:
Expand Down Expand Up @@ -334,12 +334,12 @@ export default {
// 根据localstorage初始化AI大模型
const initCurrentModel = (aiSession) => {
const currentModelValue = JSON.parse(aiSession)?.foundationModel?.model
unrefSelectedModel = AIModelOptions.find((item) => item.value === currentModelValue)
currentModel = AIModelOptions.find((item) => item.value === currentModelValue)
}
const initChat = () => {
const aiChatSession = localStorage.getItem('aiChat')
if (localStorage.getItem(unrefSelectedModel.localKey)) {
if (localStorage.getItem(currentModel.modelKey)) {
if (!aiChatSession) {
setContextSession()
} else {
Expand Down Expand Up @@ -384,7 +384,7 @@ export default {
}
const changeModel = (model) => {
if (unrefSelectedModel.value !== model.value) {
if (currentModel.value !== model.value) {
confirm({
title: '切换AI大模型',
message: '切换AI大模型将导致当前会话被清空,重新开启新会话,是否继续?',
Expand All @@ -395,13 +395,11 @@ export default {
})
}
}
const currentModel = ref(selectedModel.value)
watch(
() => selectedModel.value.value,
() => {
unrefSelectedModel = selectedModel.value
if (!localStorage.getItem(unrefSelectedModel.localKey)) {
currentModel.value = unrefSelectedModel
currentModel = selectedModel.value
if (!localStorage.getItem(currentModel.modelKey)) {
tokenDialogVisible.value = true
} else {
tokenDialogVisible.value = false
Expand Down Expand Up @@ -438,10 +436,9 @@ export default {
setToken,
AIModelOptions,
selectedModel,
unrefSelectedModel,
currentModel,
changeModel,
tokenDialogVisible,
currentModel,
getTokenDialogStatus,
updateTokenStatus
}
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/robot/src/TokenDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
const submitKeyForm = () => {
keyFormRef.value.validate((valid) => {
if (valid) {
localStorage.setItem(props.currentModel.localKey, keyForm.value.token)
localStorage.setItem(props.currentModel.modelKey, keyForm.value.token)
emit('token-status', true)
closeKeyFormDialog()
}
Expand Down Expand Up @@ -94,12 +94,12 @@ export default {
<tiny-alert
:icon="TinyIconCommission"
:closable="false"
:description="`尝试用自己的${model.localKey}开启AI对话功能吧!`"
:description="`尝试用自己的${model.modelKey}开启AI对话功能吧!`"
></tiny-alert>
<tiny-form-item label="" prop="token">
<tiny-input
v-model="keyForm.token"
:placeholder="`点击这里输入你的${model.localKey}`"
:placeholder="`点击这里输入你的${model.modelKey}`"
validate-event
></tiny-input>
</tiny-form-item>
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/robot/src/js/robotSetting.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const { getBlockList } = useBlock()

export const AIModelOptions = [
// 暂时不能使用,预留模型信息
// { label: 'ChatGPT:gpt-3.5-turbo', value: 'gpt-3.5-turbo', manufacturer: 'openai', localKey: '' },
// { label: '文心一言:ERNIE-Bot-turbo', value: 'ERNIE-Bot-turbo', manufacturer: 'baiduai', localKey: 'ACCESS_TOKEN' },
{ label: 'Kimi:moonshot-v1-8k', value: 'moonshot-v1-8k', manufacturer: 'kimi', localKey: 'MOONSHOT_API_KEY' }
// { label: 'ChatGPT:gpt-3.5-turbo', value: 'gpt-3.5-turbo', manufacturer: 'openai', modelKey: '' },
{ label: '文心一言:ERNIE-Bot-turbo', value: 'ERNIE-Bot-turbo', manufacturer: 'baiduai', modelKey: 'ACCESS_TOKEN' },
{ label: 'Kimi:moonshot-v1-8k', value: 'moonshot-v1-8k', manufacturer: 'kimi', modelKey: 'MOONSHOT_API_KEY' }
]

// 这里存放的是aichat的响应式数据
Expand Down

0 comments on commit cfb6489

Please sign in to comment.