feat(settings): Add independent plugin to put loading system configuration in the lifecycle hook "app:created".
This commit is contained in:
9
app.vue
9
app.vue
@@ -1,12 +1,3 @@
|
||||
<script setup>
|
||||
onNuxtReady(() => {
|
||||
fetchSystemSettings()
|
||||
// api key
|
||||
const apiKey = useApiKey()
|
||||
apiKey.value = getStoredApiKey()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NuxtLayout>
|
||||
<NuxtLoadingIndicator />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup>
|
||||
import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source'
|
||||
|
||||
const { $i18n } = useNuxtApp()
|
||||
const { $i18n, $settings } = useNuxtApp()
|
||||
const runtimeConfig = useRuntimeConfig()
|
||||
const currentModel = useCurrentModel()
|
||||
const openaiApiKey = useApiKey()
|
||||
@@ -63,7 +63,7 @@ const fetchReply = async (message) => {
|
||||
}
|
||||
|
||||
const data = Object.assign({}, currentModel.value, {
|
||||
openaiApiKey: enableCustomApiKey.value ? openaiApiKey.value : null,
|
||||
openaiApiKey: $settings.open_api_key_setting === 'True' ? openaiApiKey.value : null,
|
||||
message: message,
|
||||
conversationId: props.conversation.id,
|
||||
frugalMode: frugalMode.value
|
||||
@@ -169,17 +169,8 @@ const deleteMessage = (index) => {
|
||||
props.conversation.messages.splice(index, 1)
|
||||
}
|
||||
|
||||
const settings = useSettings()
|
||||
const enableWebSearch = ref(false)
|
||||
|
||||
const showWebSearchToggle = computed(() => {
|
||||
return settings.value && settings.value.open_web_search && settings.value.open_web_search === 'True'
|
||||
})
|
||||
|
||||
const enableCustomApiKey = computed(() => {
|
||||
return settings.value && settings.value.open_api_key_setting && settings.value.open_api_key_setting === 'True'
|
||||
})
|
||||
|
||||
|
||||
onNuxtReady(() => {
|
||||
currentModel.value = getCurrentModel()
|
||||
@@ -260,7 +251,7 @@ onNuxtReady(() => {
|
||||
>
|
||||
<Prompt v-show="!fetchingResponse" :use-prompt="usePrompt" />
|
||||
<v-switch
|
||||
v-if="showWebSearchToggle"
|
||||
v-if="$settings.open_web_search === 'True'"
|
||||
v-model="enableWebSearch"
|
||||
inline
|
||||
hide-details
|
||||
@@ -268,36 +259,43 @@ onNuxtReady(() => {
|
||||
:label="$t('webSearch')"
|
||||
></v-switch>
|
||||
<v-spacer></v-spacer>
|
||||
<v-switch
|
||||
v-model="frugalMode"
|
||||
inline
|
||||
hide-details
|
||||
color="primary"
|
||||
:label="$t('frugalMode')"
|
||||
></v-switch>
|
||||
<v-dialog
|
||||
transition="dialog-bottom-transition"
|
||||
width="auto"
|
||||
<div
|
||||
v-if="$settings.open_frugal_mode_control === 'True'"
|
||||
class="d-flex align-center"
|
||||
>
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-icon
|
||||
color="grey"
|
||||
v-bind="props"
|
||||
icon="help_outline"
|
||||
></v-icon>
|
||||
</template>
|
||||
<template v-slot:default="{ isActive }">
|
||||
<v-card>
|
||||
<v-toolbar
|
||||
color="primary"
|
||||
:title="$t('frugalMode')"
|
||||
></v-toolbar>
|
||||
<v-card-text>
|
||||
{{ $t('frugalModeTip') }}
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</template>
|
||||
</v-dialog>
|
||||
<v-switch
|
||||
v-model="frugalMode"
|
||||
inline
|
||||
hide-details
|
||||
color="primary"
|
||||
:label="$t('frugalMode')"
|
||||
></v-switch>
|
||||
<v-dialog
|
||||
transition="dialog-bottom-transition"
|
||||
width="auto"
|
||||
>
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-icon
|
||||
color="grey"
|
||||
v-bind="props"
|
||||
icon="help_outline"
|
||||
class="ml-3"
|
||||
></v-icon>
|
||||
</template>
|
||||
<template v-slot:default="{ isActive }">
|
||||
<v-card>
|
||||
<v-toolbar
|
||||
color="primary"
|
||||
:title="$t('frugalMode')"
|
||||
></v-toolbar>
|
||||
<v-card-text>
|
||||
{{ $t('frugalModeTip') }}
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</template>
|
||||
</v-dialog>
|
||||
</div>
|
||||
|
||||
</v-toolbar>
|
||||
</div>
|
||||
</v-footer>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useDisplay } from 'vuetify'
|
||||
import {useDrawer} from "../composables/states";
|
||||
|
||||
const route = useRoute()
|
||||
const { $i18n } = useNuxtApp()
|
||||
const { $i18n, $settings } = useNuxtApp()
|
||||
const colorMode = useColorMode()
|
||||
const {mdAndUp} = useDisplay()
|
||||
const drawerPermanent = computed(() => {
|
||||
@@ -88,11 +88,6 @@ const loadConversations = async () => {
|
||||
loadingConversations.value = false
|
||||
}
|
||||
|
||||
const settings = useSettings()
|
||||
const showApiKeySetting = computed(() => {
|
||||
return settings.value && settings.value.open_api_key_setting && settings.value.open_api_key_setting === 'True'
|
||||
})
|
||||
|
||||
const signOut = async () => {
|
||||
const { data, error } = await useFetch('/api/account/logout/', {
|
||||
method: 'POST'
|
||||
@@ -277,7 +272,7 @@ const drawer = useDrawer()
|
||||
</v-dialog>
|
||||
|
||||
<ApiKeyDialog
|
||||
v-if="showApiKeySetting"
|
||||
v-if="$settings.open_api_key_setting === 'True'"
|
||||
/>
|
||||
|
||||
<ModelParameters/>
|
||||
|
||||
@@ -7,8 +7,6 @@ export const useApiKey = () => useState('apiKey', () => getStoredApiKey())
|
||||
|
||||
export const useConversations = () => useState('conversations', () => [])
|
||||
|
||||
export const useSettings = () => useState('settings', () => {})
|
||||
|
||||
export const useUser = () => useState('user', () => null)
|
||||
|
||||
export const useDrawer = () => useState('drawer', () => false)
|
||||
@@ -26,7 +26,7 @@
|
||||
"to your account.":"你的账号了。",
|
||||
"welcomeTo": "欢迎来到",
|
||||
"language": "语言",
|
||||
"setApiKey": "设置API密钥",
|
||||
"setApiKey": "API 密钥",
|
||||
"setOpenAIApiKey": "设置OpenAI的API密钥",
|
||||
"openAIApiKey": "OpenAI的API密钥",
|
||||
"getAKey": "获取钥匙",
|
||||
|
||||
6
plugins/initApiKey.js
Normal file
6
plugins/initApiKey.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.hook('app:created', async () => {
|
||||
const apiKey = useApiKey()
|
||||
apiKey.value = getStoredApiKey()
|
||||
})
|
||||
})
|
||||
24
plugins/settings.js
Normal file
24
plugins/settings.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const transformData = (list) => {
|
||||
const result = {};
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const item = list[i];
|
||||
result[item.name] = item.value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.hook('app:created', async () => {
|
||||
let settings = {}
|
||||
|
||||
const { data, error } = await useAuthFetch('/api/chat/settings/', {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
if (!error.value) {
|
||||
settings = transformData(data.value)
|
||||
}
|
||||
|
||||
nuxtApp.provide('settings', settings)
|
||||
})
|
||||
})
|
||||
@@ -44,25 +44,6 @@ export const genTitle = async (conversationId) => {
|
||||
return null
|
||||
}
|
||||
|
||||
const transformData = (list) => {
|
||||
const result = {};
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const item = list[i];
|
||||
result[item.name] = item.value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export const fetchSystemSettings = async () => {
|
||||
const { data, error } = await useAuthFetch('/api/chat/settings/', {
|
||||
method: 'GET',
|
||||
})
|
||||
if (!error.value) {
|
||||
const settings = useSettings()
|
||||
settings.value = transformData(data.value)
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchUser = async () => {
|
||||
return useMyFetch('/api/account/user/')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user