Get settings from backend, added web search functionality
This commit is contained in:
@@ -96,10 +96,12 @@ onMounted( () => {
|
|||||||
<template v-slot:activator="{ props }">
|
<template v-slot:activator="{ props }">
|
||||||
<v-btn
|
<v-btn
|
||||||
v-bind="props"
|
v-bind="props"
|
||||||
icon="speaker_notes"
|
icon
|
||||||
title="Common prompts"
|
>
|
||||||
class="mr-3"
|
<v-icon
|
||||||
></v-btn>
|
icon="speaker_notes"
|
||||||
|
></v-icon>
|
||||||
|
</v-btn>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<v-container>
|
<v-container>
|
||||||
|
|||||||
@@ -7,4 +7,6 @@ export const useApiKey = () => useState('apiKey', () => getStoredApiKey())
|
|||||||
|
|
||||||
export const useConversion = () => useState('conversion', () => getDefaultConversionData())
|
export const useConversion = () => useState('conversion', () => getDefaultConversionData())
|
||||||
|
|
||||||
export const useConversions = () => useState('conversions', () => [])
|
export const useConversions = () => useState('conversions', () => [])
|
||||||
|
|
||||||
|
export const useSettings = () => useState('settings', () => {})
|
||||||
@@ -34,6 +34,7 @@
|
|||||||
"copied": "Copied",
|
"copied": "Copied",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
"signOut": "Sign out",
|
"signOut": "Sign out",
|
||||||
|
"webSearch": "Web Search",
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"introduction1": "is an unofficial client for ChatGPT, but uses the official OpenAI API.",
|
"introduction1": "is an unofficial client for ChatGPT, but uses the official OpenAI API.",
|
||||||
"introduction2": "You will need an OpenAI API Key before you can use this client.",
|
"introduction2": "You will need an OpenAI API Key before you can use this client.",
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
"copied": "已复制",
|
"copied": "已复制",
|
||||||
"delete": "删除",
|
"delete": "删除",
|
||||||
"signOut": "退出登录",
|
"signOut": "退出登录",
|
||||||
|
"webSearch": "网页搜索",
|
||||||
"welcomeScreen": {
|
"welcomeScreen": {
|
||||||
"introduction1": "是一个非官方的ChatGPT客户端,但使用OpenAI的官方API",
|
"introduction1": "是一个非官方的ChatGPT客户端,但使用OpenAI的官方API",
|
||||||
"introduction2": "在使用本客户端之前,您需要一个OpenAI API密钥。",
|
"introduction2": "在使用本客户端之前,您需要一个OpenAI API密钥。",
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ const loadConversations = async () => {
|
|||||||
|
|
||||||
const {mdAndUp} = useDisplay()
|
const {mdAndUp} = useDisplay()
|
||||||
|
|
||||||
|
|
||||||
const drawerPermanent = computed(() => {
|
const drawerPermanent = computed(() => {
|
||||||
return mdAndUp.value
|
return mdAndUp.value
|
||||||
})
|
})
|
||||||
@@ -97,8 +98,9 @@ const signOut = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onNuxtReady(async () => {
|
onMounted(async () => {
|
||||||
loadConversations()
|
loadConversations()
|
||||||
|
loadSettings()
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ definePageMeta({
|
|||||||
middleware: ["auth"]
|
middleware: ["auth"]
|
||||||
})
|
})
|
||||||
import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source'
|
import {EventStreamContentType, fetchEventSource} from '@microsoft/fetch-event-source'
|
||||||
import { nextTick } from 'vue'
|
|
||||||
import MessageActions from "~/components/MessageActions.vue";
|
|
||||||
|
|
||||||
const { $i18n, $auth } = useNuxtApp()
|
const { $i18n, $auth } = useNuxtApp()
|
||||||
const runtimeConfig = useRuntimeConfig()
|
const runtimeConfig = useRuntimeConfig()
|
||||||
@@ -53,11 +51,19 @@ const abortFetch = () => {
|
|||||||
const fetchReply = async (message) => {
|
const fetchReply = async (message) => {
|
||||||
ctrl = new AbortController()
|
ctrl = new AbortController()
|
||||||
|
|
||||||
|
let webSearchParams = {}
|
||||||
|
console.log(enableWebSearch.value)
|
||||||
|
if (enableWebSearch.value) {
|
||||||
|
webSearchParams['web_search'] = {
|
||||||
|
ua: navigator.userAgent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const data = Object.assign({}, currentModel.value, {
|
const data = Object.assign({}, currentModel.value, {
|
||||||
openaiApiKey: openaiApiKey.value,
|
openaiApiKey: openaiApiKey.value,
|
||||||
message: message,
|
message: message,
|
||||||
conversationId: currentConversation.value.id
|
conversationId: currentConversation.value.id
|
||||||
})
|
}, webSearchParams)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetchEventSource('/api/conversation/', {
|
await fetchEventSource('/api/conversation/', {
|
||||||
@@ -157,6 +163,18 @@ const deleteMessage = (index) => {
|
|||||||
currentConversation.value.messages.splice(index, 1)
|
currentConversation.value.messages.splice(index, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showWebSearchToggle = ref(false)
|
||||||
|
const enableWebSearch = ref(false)
|
||||||
|
|
||||||
|
const settings = useSettings()
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
if (settings.value) {
|
||||||
|
const settingsValue = toRaw(settings.value)
|
||||||
|
showWebSearchToggle.value = settingsValue.open_web_search && settingsValue.open_web_search === 'True'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -209,31 +227,19 @@ const deleteMessage = (index) => {
|
|||||||
></v-btn>
|
></v-btn>
|
||||||
<MsgEditor ref="editor" :send-message="send" :disabled="fetchingResponse" :loading="fetchingResponse" />
|
<MsgEditor ref="editor" :send-message="send" :disabled="fetchingResponse" :loading="fetchingResponse" />
|
||||||
</div>
|
</div>
|
||||||
<v-toolbar>
|
<v-toolbar
|
||||||
|
density="comfortable"
|
||||||
|
color="transparent"
|
||||||
|
>
|
||||||
<Prompt v-show="!fetchingResponse" :use-prompt="usePrompt" />
|
<Prompt v-show="!fetchingResponse" :use-prompt="usePrompt" />
|
||||||
<v-switch
|
<v-switch
|
||||||
|
v-if="showWebSearchToggle"
|
||||||
|
v-model="enableWebSearch"
|
||||||
hide-details
|
hide-details
|
||||||
inset
|
|
||||||
color="primary"
|
color="primary"
|
||||||
label="Search on the web"
|
:label="$t('webSearch')"
|
||||||
></v-switch>
|
></v-switch>
|
||||||
<v-btn
|
|
||||||
icon
|
|
||||||
class="hidden-xs-only"
|
|
||||||
>
|
|
||||||
<v-icon>mdi-arrow-left</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
|
|
||||||
<v-toolbar-title>Title</v-toolbar-title>
|
|
||||||
|
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
|
|
||||||
<v-btn
|
|
||||||
icon
|
|
||||||
class="hidden-xs-only"
|
|
||||||
>
|
|
||||||
<v-icon>mdi-magnify</v-icon>
|
|
||||||
</v-btn>
|
|
||||||
</v-toolbar>
|
</v-toolbar>
|
||||||
|
|
||||||
<!-- <div class="py-2 text-disabled text-caption font-weight-light text-center">-->
|
<!-- <div class="py-2 text-disabled text-caption font-weight-light text-center">-->
|
||||||
|
|||||||
@@ -50,4 +50,23 @@ export const genTitle = async (conversationId) => {
|
|||||||
return data.value.title
|
return data.value.title
|
||||||
}
|
}
|
||||||
return null
|
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 loadSettings = async () => {
|
||||||
|
const settings = useSettings()
|
||||||
|
const { data, error } = await useAuthFetch('/api/chat/settings/', {
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
if (!error.value) {
|
||||||
|
settings.value = transformData(data.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user