Phoenix 8 months ago
parent 7beb84b385
commit 0338d00d35

@ -77,7 +77,7 @@
</div>
</div>
</div>
<script type="module" src="/src/main.ts"></script>
<script type="module" src="/src/main.js"></script>
</body>
</html>

1465
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -23,14 +23,21 @@
"common:prepare": "husky install"
},
"dependencies": {
"@quasar/extras": "^1.16.9",
"@traptitech/markdown-it-katex": "^3.6.0",
"@vueuse/core": "^9.13.0",
"ant-design-vue": "^4.1.1",
"dayjs": "^1.11.10",
"highlight.js": "^11.7.0",
"html2canvas": "^1.4.1",
"katex": "^0.16.4",
"markdown-it": "^13.0.1",
"naive-ui": "^2.34.3",
"pinia": "^2.0.33",
"primeflex": "^3.3.1",
"primeicons": "^6.0.1",
"primevue": "^3.46.0",
"quasar": "^2.14.2",
"vite-plugin-qiankun": "^1.0.15",
"vue": "^3.2.47",
"vue-i18n": "^9.2.2",
@ -60,7 +67,8 @@
"rimraf": "^4.3.0",
"tailwindcss": "^3.2.7",
"typescript": "~4.9.5",
"vite": "^5.0.12",
"unplugin-vue-components": "^0.26.0",
"vite": "^4.2.0",
"vite-plugin-pwa": "^0.14.4",
"vue-tsc": "^1.2.0"
},

@ -6,6 +6,7 @@ import { useLanguage } from '@/hooks/useLanguage'
const { theme, themeOverrides } = useTheme()
const { language } = useLanguage()
localStorage.setItem('token','46d71a72d8d845ad7ed23eba9bdde260e635407190c2ce1bf7fd22088e41682ea07773ec65cae8946d2003f264d55961f96e0fc5da10eb96d3a348c1664e9644e756eda7154e1af9e70d1c9d2f100823a26885ea6df3249fe619995cb79dc5dbd5ead32d43b955d6b3ce83129097bb21bb8169898f48692de4f966db140c71b85a2065acfc948561c465279fc05194a79a1115f3b00170944b6c4bd6c52ada909a075c55d18d76c2ed2175602421b34b27362a05c350733ed73382471df0a08950f7f1e812a610c17bdac82d82d54be38969f6b41201af79b8d36ef177c5b94bdd0b97501291f5dc1988d078f75b7de79982f003b0d7c5ba286511f285173cc55eb06d64ee6a12f0de1add728edd6b4632a432be8221f44bb864b0e9e4985ca7b47a53f8d55c0171f6f9465e063db4881b1dd87b8f903f3959a83ec525aa0695')
</script>
<template>

@ -7,10 +7,24 @@ export const getSessionList = (data) => {
data
})
}
export const sessionDetail = (data) => {
export const sessionDetailReq = (data) => {
return request({
url: '/chat/detail',
method: 'post',
data
})
}
export const createSession = (data) => {
return request({
url: '/chat/create',
method: 'post',
data
})
}
export const postRequest = (url,data) => {
return request({
url,
method: 'post',
data
})
}

@ -4,20 +4,22 @@ import { setupI18n } from './locales'
import { setupAssets, setupScrollbarStyle } from './plugins'
import { setupStore } from './store'
import { setupRouter } from './router'
import Antd from "ant-design-vue";
import 'ant-design-vue/dist/reset.css';
async function bootstrap() {
const app = createApp(App)
setupAssets()
app.use(Antd);
setupScrollbarStyle()
setupStore(app)
setupI18n(app)
await setupRouter(app)
app.mount('#app')
app.mount('#app')
}
bootstrap()

@ -5,4 +5,5 @@ export function setupStore(app: App) {
app.use(store)
}
export * from './modules'
// @ts-ignore
export * from './modules/index.js'

@ -4,3 +4,4 @@ export * from './user'
export * from './prompt'
export * from './settings'
export * from './auth'
export * from './session'

@ -0,0 +1,59 @@
import {createSession, getSessionList, postRequest, sessionDetailReq} from "@/api/api";
import dayjs from "dayjs";
import { ref } from 'vue';
import { defineStore } from 'pinia';
export const sessionDetailForSetup = defineStore('session', () => {
const sessionDetail = ref([]);
const currentListUuid=ref('')
const gptMode=ref('gpt-3.5-turbo')
const dataList = ref([]);
const getDataList = async () => {
const data = {
page: 1,
pageSize: 9999,
}
const res=await getSessionList(data)
if (res.code===0){
dataList.value=res.data.data
}
}
const detailData=ref([])
const getSessionDetail =async () => {
const res= await sessionDetailReq({listUuid:currentListUuid.value})
if (res.code===0){
sessionDetail.value=res.data.map((x)=>{
return {
dateTime:dayjs.unix(x.CreatedAt).format('YYYY/M/D HH:mm:ss'),
text:(() => {
try {
return JSON.parse(x.message)?.find(m => m.type === 'text')?.text ?? '';
} catch (e) {
return '';
}
})(),
inversion:x.role==='user',
error:false,
conversationOpt:null,
}
})
detailData.value=res.data
}
}
const createSessionStore=async ()=>{
const data={
gptModel:gptMode.value
}
const res=await createSession(data)
if (res.code===0){
getDataList()
}
}
const deleteSession =async () => {
const res=await postRequest('/chat/del', {listUuid:currentListUuid.value})
if (res.code === 0) {
getDataList()
}
}
return { sessionDetail,currentListUuid ,gptMode,getDataList,dataList,getSessionDetail,createSessionStore,deleteSession};
});

@ -7,7 +7,7 @@ const request = axios.create({
});
request.interceptors.request.use((config)=>{
config.headers.Authorization = "46d71a72d8d845ad7ed23eba9bdde260e635407190c2ce1bf7fd22088e41682ea07773ec65cae8946d2003f264d55961f96e0fc5da10eb96d3a348c1664e9644e756eda7154e1af9e70d1c9d2f100823a26885ea6df3249fe619995cb79dc5dbd5ead32d43b955d6b3ce83129097bb21bb8169898f48692de4f966db140c71b85a2065acfc948561c465279fc05194a79a1115f3b00170944b6c4bd6c52ada909a075c55d18d76c2ed2175602421b34b27362a05c350733ed73382471df0a08950f7f1e812a610c17bdac82d82d54be38969f6b41201af79b8d36ef177c5b94b77a297c94f40d4036d2bd3a7ceac5cb29b191ba490d59fc77c794d533c2d078304c7642e8ae7d697ff83e4cc5dd96f685b7c30f18877f2c1672219ba649e17fdfee148c51f63f1875beb019586995f51fd1a51c55e3e62f09727a44181fa46ff"
config.headers.Authorization = "46d71a72d8d845ad7ed23eba9bdde260e635407190c2ce1bf7fd22088e41682ea07773ec65cae8946d2003f264d55961f96e0fc5da10eb96d3a348c1664e9644e756eda7154e1af9e70d1c9d2f100823a26885ea6df3249fe619995cb79dc5dbd5ead32d43b955d6b3ce83129097bb21bb8169898f48692de4f966db140c71b85a2065acfc948561c465279fc05194a79a1115f3b00170944b6c4bd6c52ada909a075c55d18d76c2ed2175602421b34b27362a05c350733ed73382471df0a08950f7f1e812a610c17bdac82d82d54be38969f6b41201af79b8d36ef177c5b94bdd0b97501291f5dc1988d078f75b7de774c3731c3c9c46b80f79c664fd16568e0b12316c09aa60453346b960b888f074045242038258c55452ce5d275f05aaead8f7653f8448035dd6c6cff9ee8cd2d8c1e41bdbfb90320b2ac30e3a2e0e63e6"
return config;
});
request.interceptors.response.use((res)=>{

@ -1,5 +1,5 @@
<script setup lang='ts'>
import type { Ref } from 'vue'
<script setup >
import dayjs from "dayjs";
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
@ -15,7 +15,8 @@ import { useBasicLayout } from '@/hooks/useBasicLayout'
import { useChatStore, usePromptStore } from '@/store'
import { fetchChatAPIProcess } from '@/api'
import { t } from '@/locales'
import { sessionDetailForSetup } from '@/store'
const sessionDetailData=sessionDetailForSetup()
let controller = new AbortController()
const openLongReply = import.meta.env.VITE_GLOB_OPEN_LONG_REPLY === 'true'
@ -31,30 +32,114 @@ const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll()
const { usingContext, toggleUsingContext } = useUsingContext()
const { uuid } = route.params as { uuid: string }
const dataSources = computed(() => chatStore.getChatByUuid(+uuid))
const conversationList = computed(() => dataSources.value.filter(item => (!item.inversion && !!item.conversationOptions)))
const { uuid } = route.params
const prompt = ref<string>('')
const loading = ref<boolean>(false)
const inputRef = ref<Ref | null>(null)
const dataSources = sessionDetailForSetup().sessionDetail
const conversationList = computed(() => dataSources.filter(item => (!item.inversion && !!item.conversationOptions)))
const dataSessionDetail=ref([])
const prompt = ref('')
const loading = ref(false)
const inputRef = ref(null)
// PromptStore
const promptStore = usePromptStore()
// 使storeToRefsstore
const { promptList: promptTemplate } = storeToRefs<any>(promptStore)
const { promptList: promptTemplate } = storeToRefs(promptStore)
// loading
dataSources.value.forEach((item, index) => {
dataSources.forEach((item, index) => {
if (item.loading)
updateChatSome(+uuid, index, { loading: false })
})
function handleSubmit() {
onConversation()
dataSources.push({
dateTime: dayjs().format('YYYY/MM/DD HH:mm:ss'),
text: prompt.value,
inversion: true,
error: false,
})
sendDataStream()
console.log(sessionDetailForSetup().sessionDetail,'sessionDetailForSetup().sessionDetail')
/* onConversation() */
}
const API_URL = 'http://114.218.158.24:9020/chat/completion';
const createParams = () => {
const sessionDetail = sessionDetailForSetup().sessionDetail;
const messages = sessionDetail.map(x => ({
content: x.text,
role: x.inversion ? 'user' : 'assistant'
}));
return {
listUuid: sessionDetailForSetup().currentListUuid,
messages,
frequency_penalty: 0,
max_tokens: 1000,
model: sessionDetailForSetup().gptMode,
presence_penalty: 0,
stream: true,
temperature: 1,
top_p: 1
};
};
const handleResponseStream = async (reader) => {
const { done, value } = await reader.read();
if (!done) {
let decoded = new TextDecoder().decode(value);
let decodedArray = decoded.split("data: ");
decodedArray.forEach((decoded) => {
if (decoded !== "") {
if (decoded.trim() === "[DONE]") {
return;
} else {
const response = JSON.parse(decoded).choices[0].delta.content
? JSON.parse(decoded).choices[0].delta.content
: "";
dataSources[dataSources.length - 1].text += response;
}
}
});
await handleResponseStream(reader);
}
};
const sendDataStream = async () => {
dataSources.push({
dateTime: dayjs().format('YYYY/MM/DD HH:mm:ss'),
text: '',
inversion: false,
error: false,
});
const params = createParams();
try {
const response = await fetch(API_URL, {
method: "POST",
timeout: 10000,
body: JSON.stringify(params),
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: localStorage.getItem('token'),
},
});
const contentType = response.headers.get('Content-Type');
if (!contentType || !contentType.includes('application/json')) {
const reader = response.body.getReader();
await handleResponseStream(reader);
}
} catch (error) {
console.error('发生错误:', error);
}
};
async function onConversation() {
let message = prompt.value
@ -83,7 +168,7 @@ async function onConversation() {
loading.value = true
prompt.value = ''
let options: Chat.ConversationRequest = {}
let options= {}
const lastContext = conversationList.value[conversationList.value.length - 1]?.conversationOptions
if (lastContext && usingContext.value)
@ -122,7 +207,7 @@ async function onConversation() {
const data = JSON.parse(chunk)
updateChat(
+uuid,
dataSources.value.length - 1,
dataSources.length - 1,
{
dateTime: new Date().toLocaleString(),
text: lastText + (data.text ?? ''),
@ -147,18 +232,18 @@ async function onConversation() {
}
},
})
updateChatSome(+uuid, dataSources.value.length - 1, { loading: false })
updateChatSome(+uuid, dataSources.length - 1, { loading: false })
}
await fetchChatAPIOnce()
}
catch (error: any) {
catch (error) {
const errorMessage = error?.message ?? t('common.wrong')
if (error.message === 'canceled') {
updateChatSome(
+uuid,
dataSources.value.length - 1,
dataSources.length - 1,
{
loading: false,
},
@ -167,12 +252,12 @@ async function onConversation() {
return
}
const currentChat = getChatByUuidAndIndex(+uuid, dataSources.value.length - 1)
const currentChat = getChatByUuidAndIndex(+uuid, dataSources.length - 1)
if (currentChat?.text && currentChat.text !== '') {
updateChatSome(
+uuid,
dataSources.value.length - 1,
dataSources.length - 1,
{
text: `${currentChat.text}\n[${errorMessage}]`,
error: false,
@ -184,7 +269,7 @@ async function onConversation() {
updateChat(
+uuid,
dataSources.value.length - 1,
dataSources.length - 1,
{
dateTime: new Date().toLocaleString(),
text: errorMessage,
@ -202,17 +287,17 @@ async function onConversation() {
}
}
async function onRegenerate(index: number) {
async function onRegenerate(index) {
if (loading.value)
return
controller = new AbortController()
const { requestOptions } = dataSources.value[index]
const { requestOptions } = dataSources[index]
let message = requestOptions?.prompt ?? ''
let options: Chat.ConversationRequest = {}
let options = {}
if (requestOptions.options)
options = { ...requestOptions.options }
@ -280,7 +365,7 @@ async function onRegenerate(index: number) {
}
await fetchChatAPIOnce()
}
catch (error: any) {
catch (error) {
if (error.message === 'canceled') {
updateChatSome(
+uuid,
@ -326,7 +411,7 @@ function handleExport() {
try {
d.loading = true
const ele = document.getElementById('image-wrapper')
const canvas = await html2canvas(ele as HTMLDivElement, {
const canvas = await html2canvas(ele, {
useCORS: true,
})
const imgUrl = canvas.toDataURL('image/png')
@ -345,7 +430,7 @@ function handleExport() {
ms.success(t('chat.exportSuccess'))
Promise.resolve()
}
catch (error: any) {
catch (error) {
ms.error(t('chat.exportFailed'))
}
finally {
@ -355,7 +440,7 @@ function handleExport() {
})
}
function handleDelete(index: number) {
function handleDelete(index) {
if (loading.value)
return
@ -385,7 +470,7 @@ function handleClear() {
})
}
function handleEnter(event: KeyboardEvent) {
function handleEnter(event) {
if (!isMobile.value) {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault()
@ -412,7 +497,7 @@ function handleStop() {
// key,renderOptionvaluerenderLabel
const searchOptions = computed(() => {
if (prompt.value.startsWith('/')) {
return promptTemplate.value.filter((item: { key: string }) => item.key.toLowerCase().includes(prompt.value.substring(1).toLowerCase())).map((obj: { value: any }) => {
return promptTemplate.value.filter((item) => item.key.toLowerCase().includes(prompt.value.substring(1).toLowerCase())).map((obj) => {
return {
label: obj.value,
value: obj.value,
@ -425,7 +510,7 @@ const searchOptions = computed(() => {
})
// valuekey
const renderOption = (option: { label: string }) => {
const renderOption = (option) => {
for (const i of promptTemplate.value) {
if (i.value === option.label)
return [i.key]
@ -460,10 +545,24 @@ onUnmounted(() => {
if (loading.value)
controller.abort()
})
</script>
const value = ref('gpt-3.5-turbo');
const options=ref([{ label: 'GPT-3.5', value: 'gpt-3.5-turbo' },
{ label: 'GPT-4.0', value: 'gpt-4-1106-preview' },
{ label: 'GPT-V', value: 'gpt-4-vision-preview' }])
</script>
<template>
<div class="flex flex-col w-full h-full">
<div style="margin-top: 15px;margin-left: 15px">
<a-select
align="center"
v-model:value="sessionDetailForSetup().gptMode"
style="width: 120px"
:dropdown-match-select-width="false"
>
<a-select-option align="center" v-for="(item,index) in options" :key="index" :value="item.value">{{item.label}}</a-select-option>
</a-select>
</div>
<HeaderComponent
v-if="isMobile"
:using-context="usingContext"
@ -511,7 +610,7 @@ onUnmounted(() => {
</main>
<footer :class="footerClass">
<div class="w-full max-w-screen-xl m-auto">
<div class="flex items-center justify-between space-x-2">
<div class="flex items-center justify-between space-x-2" style="flex-wrap: initial">
<HoverButton v-if="!isMobile" @click="handleClear">
<span class="text-xl text-[#4f555e] dark:text-white">
<SvgIcon icon="ri:delete-bin-line" />

@ -1,18 +1,20 @@
<script setup >
import {computed, ref} from 'vue'
import dayjs from "dayjs";
import { NInput, NPopconfirm, NScrollbar } from 'naive-ui'
import {getSessionList, sessionDetail} from '@/api/api'
import { SvgIcon } from '@/components/common'
import { useAppStore, useChatStore } from '@/store'
import { useBasicLayout } from '@/hooks/useBasicLayout'
import { debounce } from '@/utils/functions/debounce'
import { sessionDetailForSetup } from '@/store'
const sessionDetailData=sessionDetailForSetup()
const { isMobile } = useBasicLayout()
const appStore = useAppStore()
const chatStore = useChatStore()
const dataSources = computed(() => chatStore.history)
async function handleSelect({ listUuid }) {
currentListUuid.value=listUuid
getSessionDetail()
sessionDetailData.currentListUuid=listUuid
sessionDetailData.getSessionDetail()
if (isActive(listUuid)){
return
}
@ -24,42 +26,24 @@ async function handleSelect({ listUuid }) {
if (isMobile.value)
appStore.setSiderCollapsed(true)
}
const dataList=ref([])
const currentListUuid=ref('')
const detailData=ref([])
const getSessionDetail =async () => {
const res= await sessionDetail({listUuid:currentListUuid.value})
if (res.code===0){
detailData.value=res.data
}
}
const getDataList = async () => {
const data = {
page: 1,
pageSize: 9999,
}
const res=await getSessionList(data).then((res)=>{
if (res.code===0){
dataList.value=res.data.data
console.log(dataList.value,'dataList.value')
}
})
}
getDataList()
sessionDetailData.getDataList()
function handleEdit({ listUuid }, isEdit, event) {
console.log('1111')
event?.stopPropagation()
chatStore.updateHistory(listUuid, { isEdit })
}
function handleDelete(index, event) {
/* function handleDelete(index, event) {
event?.stopPropagation()
chatStore.deleteHistory(index)
if (isMobile.value)
appStore.setSiderCollapsed(true)
}
} */
const handleDeleteDebounce = debounce(handleDelete, 600)
//const handleDeleteDebounce = debounce(handleDelete, 600)
const handleDeleteDebounce = ()=>{
sessionDetailData.deleteSession()
}
function handleEnter({ listUuid }, isEdit, event) {
event?.stopPropagation()
@ -75,14 +59,14 @@ function isActive(listUuid) {
<template>
<NScrollbar class="px-4">
<div class="flex flex-col gap-2 text-sm">
<template v-if="!dataList.length">
<template v-if="!sessionDetailData.dataList.length">
<div class="flex flex-col items-center mt-4 text-center text-neutral-300">
<SvgIcon icon="ri:inbox-line" class="mb-2 text-3xl" />
<span>{{ $t('common.noData') }}</span>
</div>
</template>
<template v-else>
<div v-for="(item, index) of dataList" :key="item.listUuid">
<div v-for="(item, index) of sessionDetailData.dataList.filter(item => item.gptModel===sessionDetailData.gptMode)" :key="item.listUuid">
<a
class="relative flex items-center gap-3 px-3 py-3 break-all border rounded-md cursor-pointer hover:bg-neutral-100 group dark:border-neutral-800 dark:hover:bg-[#24272e]"
:class="isActive(item.listUuid) && ['border-[#4b9e5f]', 'bg-neutral-100', 'text-[#4b9e5f]', 'dark:bg-[#24272e]', 'dark:border-[#4b9e5f]', 'pr-14']"

@ -1,5 +1,5 @@
<script setup lang='ts'>
import type { CSSProperties } from 'vue'
<script setup>
import {createSession} from "@/api/api";
import { computed, ref, watch } from 'vue'
import { NButton, NLayoutSider, useDialog } from 'naive-ui'
import List from './List.vue'
@ -8,6 +8,7 @@ import { useAppStore, useChatStore } from '@/store'
import { useBasicLayout } from '@/hooks/useBasicLayout'
import { PromptStore, SvgIcon } from '@/components/common'
import { t } from '@/locales'
import {sessionDetailForSetup} from "@/store";
const appStore = useAppStore()
const chatStore = useChatStore()
@ -19,10 +20,11 @@ const show = ref(false)
const collapsed = computed(() => appStore.siderCollapsed)
function handleAdd() {
chatStore.addHistory({ title: t('chat.newChatTitle'), uuid: Date.now(), isEdit: false })
async function handleAdd() {
await sessionDetailForSetup().createSessionStore()
/* chatStore.addHistory({ title: t('chat.newChatTitle'), uuid: Date.now(), isEdit: false })
if (isMobile.value)
appStore.setSiderCollapsed(true)
appStore.setSiderCollapsed(true) */
}
function handleUpdateCollapsed() {
@ -43,7 +45,7 @@ function handleClearAll() {
})
}
const getMobileClass = computed<CSSProperties>(() => {
const getMobileClass = computed(() => {
if (isMobile.value) {
return {
position: 'fixed',

@ -3,7 +3,6 @@ import type { PluginOption } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'
import qiankun from 'vite-plugin-qiankun'
function setupPlugins(env: ImportMetaEnv): PluginOption[] {
return [
vue(),
@ -30,9 +29,7 @@ export default defineConfig((env) => {
'@': path.resolve(process.cwd(), 'src'),
},
},
plugins: [setupPlugins(viteEnv), qiankun('testapp', {
useDevMode: true,
})],
plugins: [setupPlugins(viteEnv)],
server: {
host: '0.0.0.0',
port: 1002,

Loading…
Cancel
Save