|
|
@ -1,5 +1,5 @@
|
|
|
|
<script setup >
|
|
|
|
<script setup >
|
|
|
|
import {uploadImg} from "@/api/api";
|
|
|
|
import {uploadFormData, uploadImg} from "@/api/api";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
import { computed, onMounted, onUnmounted, ref,watch } from 'vue'
|
|
|
|
import { computed, onMounted, onUnmounted, ref,watch } from 'vue'
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
@ -16,30 +16,21 @@ import { useBasicLayout } from '@/hooks/useBasicLayout'
|
|
|
|
import { useChatStore, usePromptStore } from '@/store'
|
|
|
|
import { useChatStore, usePromptStore } from '@/store'
|
|
|
|
import { fetchChatAPIProcess } from '@/api'
|
|
|
|
import { fetchChatAPIProcess } from '@/api'
|
|
|
|
import { t } from '@/locales'
|
|
|
|
import { t } from '@/locales'
|
|
|
|
|
|
|
|
import { UploadOutlined } from '@ant-design/icons-vue';
|
|
|
|
import {storeToRefs} from 'pinia'
|
|
|
|
import {storeToRefs} from 'pinia'
|
|
|
|
import { sessionDetailForSetup } from '@/store'
|
|
|
|
import { sessionDetailForSetup } from '@/store'
|
|
|
|
const sessionDetailData=sessionDetailForSetup()
|
|
|
|
const sessionDetailData=sessionDetailForSetup()
|
|
|
|
let controller = new AbortController()
|
|
|
|
let controller = new AbortController()
|
|
|
|
const { sessionDetail:dataSources ,currentListUuid,gptMode} = storeToRefs(sessionDetailData)
|
|
|
|
const { sessionDetail:dataSources ,currentListUuid,gptMode,isStop} = storeToRefs(sessionDetailData)
|
|
|
|
const openLongReply = import.meta.env.VITE_GLOB_OPEN_LONG_REPLY === 'true'
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
|
|
const dialog = useDialog()
|
|
|
|
const dialog = useDialog()
|
|
|
|
const ms = useMessage()
|
|
|
|
const ms = useMessage()
|
|
|
|
|
|
|
|
|
|
|
|
const chatStore = useChatStore()
|
|
|
|
const chatStore = useChatStore()
|
|
|
|
|
|
|
|
|
|
|
|
const { isMobile } = useBasicLayout()
|
|
|
|
const { isMobile } = useBasicLayout()
|
|
|
|
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
|
|
|
|
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
|
|
|
|
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll()
|
|
|
|
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll()
|
|
|
|
const { usingContext, toggleUsingContext } = useUsingContext()
|
|
|
|
const { usingContext, toggleUsingContext } = useUsingContext()
|
|
|
|
|
|
|
|
|
|
|
|
const { uuid } = route.params
|
|
|
|
|
|
|
|
if (uuid){
|
|
|
|
|
|
|
|
currentListUuid.value=uuid
|
|
|
|
|
|
|
|
sessionDetailData.getSessionDetail()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversationList = computed(() => dataSources.value.filter(item => (!item.inversion && !!item.conversationOptions)))
|
|
|
|
|
|
|
|
const dataSessionDetail=ref([])
|
|
|
|
|
|
|
|
const prompt = ref('')
|
|
|
|
const prompt = ref('')
|
|
|
|
const loading = ref(false)
|
|
|
|
const loading = ref(false)
|
|
|
|
const inputRef = ref(null)
|
|
|
|
const inputRef = ref(null)
|
|
|
@ -59,15 +50,15 @@ dataSources.value.forEach((item, index) => {
|
|
|
|
function handleSubmit() {
|
|
|
|
function handleSubmit() {
|
|
|
|
dataSources.value.push({
|
|
|
|
dataSources.value.push({
|
|
|
|
dateTime: dayjs().format('YYYY/MM/DD HH:mm:ss'),
|
|
|
|
dateTime: dayjs().format('YYYY/MM/DD HH:mm:ss'),
|
|
|
|
text: prompt.value,
|
|
|
|
text: prompt.value,
|
|
|
|
inversion: true,
|
|
|
|
inversion: true,
|
|
|
|
error: false,
|
|
|
|
error: false,
|
|
|
|
fileList:fileList.value.map(x=>x.url)
|
|
|
|
fileList:fileList.value.map(x=>x.url),
|
|
|
|
|
|
|
|
loading:false
|
|
|
|
})
|
|
|
|
})
|
|
|
|
sendDataStream()
|
|
|
|
sendDataStream()
|
|
|
|
/* onConversation() */
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const API_URL = 'http://114.218.158.24:9020/chat/completion';
|
|
|
|
const API_URL = `${import.meta.env.VITE_APP_API_BASE_URL}/chat/completion`;
|
|
|
|
|
|
|
|
|
|
|
|
const createParams = () => {
|
|
|
|
const createParams = () => {
|
|
|
|
const messages = dataSources.value.map((x) => {
|
|
|
|
const messages = dataSources.value.map((x) => {
|
|
|
@ -85,6 +76,7 @@ const createParams = () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
|
|
|
|
type:isFile.value?'custom':'',
|
|
|
|
listUuid: currentListUuid.value,
|
|
|
|
listUuid: currentListUuid.value,
|
|
|
|
messages,
|
|
|
|
messages,
|
|
|
|
frequency_penalty: 0,
|
|
|
|
frequency_penalty: 0,
|
|
|
@ -96,7 +88,6 @@ const createParams = () => {
|
|
|
|
top_p: 1
|
|
|
|
top_p: 1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleResponseStream = async (reader) => {
|
|
|
|
const handleResponseStream = async (reader) => {
|
|
|
|
const { done, value } = await reader.read();
|
|
|
|
const { done, value } = await reader.read();
|
|
|
|
if (!done) {
|
|
|
|
if (!done) {
|
|
|
@ -105,10 +96,16 @@ const handleResponseStream = async (reader) => {
|
|
|
|
decodedArray.forEach((decoded) => {
|
|
|
|
decodedArray.forEach((decoded) => {
|
|
|
|
if (decoded !== "") {
|
|
|
|
if (decoded !== "") {
|
|
|
|
if (decoded.trim() === "[DONE]") {
|
|
|
|
if (decoded.trim() === "[DONE]") {
|
|
|
|
|
|
|
|
dataSources.value[dataSources.value.length - 1].loading=false
|
|
|
|
|
|
|
|
loading.value=false
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
console.log(decoded,'decoded')
|
|
|
|
if (isStop.value){
|
|
|
|
|
|
|
|
loading.value=false
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
loading.value=true
|
|
|
|
|
|
|
|
dataSources.value[dataSources.value.length - 1].loading=true
|
|
|
|
const response = JSON.parse(decoded).choices[0].delta.content
|
|
|
|
const response = JSON.parse(decoded).choices[0].delta.content
|
|
|
|
? JSON.parse(decoded).choices[0].delta.content
|
|
|
|
? JSON.parse(decoded).choices[0].delta.content
|
|
|
|
: "";
|
|
|
|
: "";
|
|
|
@ -120,18 +117,21 @@ const handleResponseStream = async (reader) => {
|
|
|
|
await handleResponseStream(reader);
|
|
|
|
await handleResponseStream(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const sendDataStream = async () => {
|
|
|
|
const sendDataStream = async () => {
|
|
|
|
const params = createParams();
|
|
|
|
const params = createParams();
|
|
|
|
fileList.value=[]
|
|
|
|
fileList.value=[]
|
|
|
|
prompt.value=''
|
|
|
|
prompt.value=''
|
|
|
|
|
|
|
|
isStop.value=false
|
|
|
|
dataSources.value.push({
|
|
|
|
dataSources.value.push({
|
|
|
|
dateTime: dayjs().format('YYYY/MM/DD HH:mm:ss'),
|
|
|
|
dateTime: dayjs().format('YYYY/MM/DD HH:mm:ss'),
|
|
|
|
text: '',
|
|
|
|
text: '思考中..',
|
|
|
|
inversion: false,
|
|
|
|
inversion: false,
|
|
|
|
error: false,
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
loading:true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
visible.value=false
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
loading.value=true
|
|
|
|
const response = await fetch(API_URL, {
|
|
|
|
const response = await fetch(API_URL, {
|
|
|
|
method: "POST",
|
|
|
|
method: "POST",
|
|
|
|
timeout: 10000,
|
|
|
|
timeout: 10000,
|
|
|
@ -143,273 +143,16 @@ const sendDataStream = async () => {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log(dataSources.value,'dataSources.value')
|
|
|
|
|
|
|
|
const contentType = response.headers.get('Content-Type');
|
|
|
|
const contentType = response.headers.get('Content-Type');
|
|
|
|
if (!contentType || !contentType.includes('application/json')) {
|
|
|
|
if (!contentType || !contentType.includes('application/json')) {
|
|
|
|
const reader = response.body.getReader();
|
|
|
|
const reader = response.body.getReader();
|
|
|
|
|
|
|
|
dataSources.value[dataSources.value.length-1].text=''
|
|
|
|
await handleResponseStream(reader);
|
|
|
|
await handleResponseStream(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('发生错误:', error);
|
|
|
|
console.error('发生错误:', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
async function onConversation() {
|
|
|
|
|
|
|
|
let message = prompt.value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loading.value)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!message || message.trim() === '')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controller = new AbortController()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addChat(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dateTime: new Date().toLocaleString(),
|
|
|
|
|
|
|
|
text: message,
|
|
|
|
|
|
|
|
inversion: true,
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
conversationOptions: null,
|
|
|
|
|
|
|
|
requestOptions: { prompt: message, options: null },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
scrollToBottom()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
|
|
prompt.value = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let options= {}
|
|
|
|
|
|
|
|
const lastContext = conversationList.value[conversationList.value.length - 1]?.conversationOptions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lastContext && usingContext.value)
|
|
|
|
|
|
|
|
options = { ...lastContext }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addChat(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dateTime: new Date().toLocaleString(),
|
|
|
|
|
|
|
|
text: t('chat.thinking'),
|
|
|
|
|
|
|
|
loading: true,
|
|
|
|
|
|
|
|
inversion: false,
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
conversationOptions: null,
|
|
|
|
|
|
|
|
requestOptions: { prompt: message, options: { ...options } },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
scrollToBottom()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let lastText = ''
|
|
|
|
|
|
|
|
const fetchChatAPIOnce = async () => {
|
|
|
|
|
|
|
|
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
|
|
|
|
|
|
|
prompt: message,
|
|
|
|
|
|
|
|
options,
|
|
|
|
|
|
|
|
signal: controller.signal,
|
|
|
|
|
|
|
|
onDownloadProgress: ({ event }) => {
|
|
|
|
|
|
|
|
const xhr = event.target
|
|
|
|
|
|
|
|
const { responseText } = xhr
|
|
|
|
|
|
|
|
// Always process the final line
|
|
|
|
|
|
|
|
const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2)
|
|
|
|
|
|
|
|
let chunk = responseText
|
|
|
|
|
|
|
|
if (lastIndex !== -1)
|
|
|
|
|
|
|
|
chunk = responseText.substring(lastIndex)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const data = JSON.parse(chunk)
|
|
|
|
|
|
|
|
updateChat(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
dataSources.value.length - 1,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dateTime: new Date().toLocaleString(),
|
|
|
|
|
|
|
|
text: lastText + (data.text ?? ''),
|
|
|
|
|
|
|
|
inversion: false,
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
loading: true,
|
|
|
|
|
|
|
|
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
|
|
|
|
|
|
|
requestOptions: { prompt: message, options: { ...options } },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if (openLongReply && data.detail.choices[0].finish_reason === 'length') {
|
|
|
|
|
|
|
|
options.parentMessageId = data.id
|
|
|
|
|
|
|
|
lastText = data.text
|
|
|
|
|
|
|
|
message = ''
|
|
|
|
|
|
|
|
return fetchChatAPIOnce()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scrollToBottomIfAtBottom()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (error) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
updateChatSome(+uuid, dataSources.value.length - 1, { loading: false })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await fetchChatAPIOnce()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (error) {
|
|
|
|
|
|
|
|
const errorMessage = error?.message ?? t('common.wrong')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (error.message === 'canceled') {
|
|
|
|
|
|
|
|
updateChatSome(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
dataSources.value.length - 1,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
scrollToBottomIfAtBottom()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const currentChat = getChatByUuidAndIndex(+uuid, dataSources.value.length - 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentChat?.text && currentChat.text !== '') {
|
|
|
|
|
|
|
|
updateChatSome(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
dataSources.value.length - 1,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
text: `${currentChat.text}\n[${errorMessage}]`,
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
updateChat(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
dataSources.value.length - 1,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dateTime: new Date().toLocaleString(),
|
|
|
|
|
|
|
|
text: errorMessage,
|
|
|
|
|
|
|
|
inversion: false,
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
conversationOptions: null,
|
|
|
|
|
|
|
|
requestOptions: { prompt: message, options: { ...options } },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
scrollToBottomIfAtBottom()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* async function onRegenerate(index) {
|
|
|
|
|
|
|
|
if (loading.value)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
controller = new AbortController()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { requestOptions } = dataSources.value[index]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let message = requestOptions?.prompt ?? ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let options = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (requestOptions.options)
|
|
|
|
|
|
|
|
options = { ...requestOptions.options }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateChat(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
index,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dateTime: new Date().toLocaleString(),
|
|
|
|
|
|
|
|
text: '',
|
|
|
|
|
|
|
|
inversion: false,
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
loading: true,
|
|
|
|
|
|
|
|
conversationOptions: null,
|
|
|
|
|
|
|
|
requestOptions: { prompt: message, options: { ...options } },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
let lastText = ''
|
|
|
|
|
|
|
|
const fetchChatAPIOnce = async () => {
|
|
|
|
|
|
|
|
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
|
|
|
|
|
|
|
prompt: message,
|
|
|
|
|
|
|
|
options,
|
|
|
|
|
|
|
|
signal: controller.signal,
|
|
|
|
|
|
|
|
onDownloadProgress: ({ event }) => {
|
|
|
|
|
|
|
|
const xhr = event.target
|
|
|
|
|
|
|
|
const { responseText } = xhr
|
|
|
|
|
|
|
|
// Always process the final line
|
|
|
|
|
|
|
|
const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2)
|
|
|
|
|
|
|
|
let chunk = responseText
|
|
|
|
|
|
|
|
if (lastIndex !== -1)
|
|
|
|
|
|
|
|
chunk = responseText.substring(lastIndex)
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const data = JSON.parse(chunk)
|
|
|
|
|
|
|
|
updateChat(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
index,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dateTime: new Date().toLocaleString(),
|
|
|
|
|
|
|
|
text: lastText + (data.text ?? ''),
|
|
|
|
|
|
|
|
inversion: false,
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
loading: true,
|
|
|
|
|
|
|
|
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
|
|
|
|
|
|
|
requestOptions: { prompt: message, options: { ...options } },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (openLongReply && data.detail.choices[0].finish_reason === 'length') {
|
|
|
|
|
|
|
|
options.parentMessageId = data.id
|
|
|
|
|
|
|
|
lastText = data.text
|
|
|
|
|
|
|
|
message = ''
|
|
|
|
|
|
|
|
return fetchChatAPIOnce()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (error) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
updateChatSome(+uuid, index, { loading: false })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await fetchChatAPIOnce()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (error) {
|
|
|
|
|
|
|
|
if (error.message === 'canceled') {
|
|
|
|
|
|
|
|
updateChatSome(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
index,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const errorMessage = error?.message ?? t('common.wrong')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateChat(
|
|
|
|
|
|
|
|
+uuid,
|
|
|
|
|
|
|
|
index,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dateTime: new Date().toLocaleString(),
|
|
|
|
|
|
|
|
text: errorMessage,
|
|
|
|
|
|
|
|
inversion: false,
|
|
|
|
|
|
|
|
error: true,
|
|
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
|
|
conversationOptions: null,
|
|
|
|
|
|
|
|
requestOptions: { prompt: message, options: { ...options } },
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleExport() {
|
|
|
|
function handleExport() {
|
|
|
|
if (loading.value)
|
|
|
|
if (loading.value)
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -496,11 +239,10 @@ function handleEnter(event) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleStop() {
|
|
|
|
function handleStop() {
|
|
|
|
if (loading.value) {
|
|
|
|
if (loading.value) {
|
|
|
|
controller.abort()
|
|
|
|
|
|
|
|
loading.value = false
|
|
|
|
loading.value = false
|
|
|
|
|
|
|
|
isStop.value=true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -583,15 +325,38 @@ const handlePreview = async (file) => {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const value = ref('gpt-3.5-turbo');
|
|
|
|
const value = ref('gpt-3.5-turbo');
|
|
|
|
const visible=ref(false)
|
|
|
|
const visible=ref(false)
|
|
|
|
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' }])
|
|
|
|
|
|
|
|
const removeImg=(data)=>{
|
|
|
|
const removeImg=(data)=>{
|
|
|
|
fileList.value.splice(fileList.value.findIndex(x=>x.url===data.url),1)
|
|
|
|
fileList.value.splice(fileList.value.findIndex(x=>x.url===data.url),1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
watch(gptMode,()=>{
|
|
|
|
watch(gptMode,()=>{
|
|
|
|
|
|
|
|
currentListUuid.value=''
|
|
|
|
dataSources.value=[]
|
|
|
|
dataSources.value=[]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
const visible1=ref(false)
|
|
|
|
|
|
|
|
const fileList1=ref([])
|
|
|
|
|
|
|
|
const isFile=ref(false)
|
|
|
|
|
|
|
|
const upItemImage1= async (file)=>{
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
|
|
|
file: file.file,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const res=await uploadFormData(data)
|
|
|
|
|
|
|
|
if (res.code===0){
|
|
|
|
|
|
|
|
file.onSuccess()
|
|
|
|
|
|
|
|
dataSources.value=[...dataSources.value,...res.data.paragraph.flatMap(n=>[n,'']).map((x)=>{
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
dateTime: dayjs().format('YYYY/MM/DD HH:mm:ss'),
|
|
|
|
|
|
|
|
text: x,
|
|
|
|
|
|
|
|
inversion: Boolean(x),
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})]
|
|
|
|
|
|
|
|
isFile.value=true
|
|
|
|
|
|
|
|
fileList1.value=[]
|
|
|
|
|
|
|
|
visible1.value=false
|
|
|
|
|
|
|
|
sendDataStream()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
const customRequest=async (file)=>{
|
|
|
|
const customRequest=async (file)=>{
|
|
|
|
const res=await uploadImg({file:file.file,source:'approval'})
|
|
|
|
const res=await uploadImg({file:file.file,source:'approval'})
|
|
|
|
if (res.code===0){
|
|
|
|
if (res.code===0){
|
|
|
@ -600,21 +365,10 @@ const customRequest=async (file)=>{
|
|
|
|
url:res.data.ori_url
|
|
|
|
url:res.data.ori_url
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(res,'res')
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
<div class="flex flex-col w-full h-full">
|
|
|
|
<div class="flex flex-col w-full h-full">
|
|
|
|
<div style="margin-top: 15px;margin-left: 15px">
|
|
|
|
|
|
|
|
<a-select
|
|
|
|
|
|
|
|
align="center"
|
|
|
|
|
|
|
|
v-model:value="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
|
|
|
|
<HeaderComponent
|
|
|
|
v-if="isMobile"
|
|
|
|
v-if="isMobile"
|
|
|
|
:using-context="usingContext"
|
|
|
|
:using-context="usingContext"
|
|
|
@ -631,13 +385,13 @@ const customRequest=async (file)=>{
|
|
|
|
<template v-if="!dataSources.length">
|
|
|
|
<template v-if="!dataSources.length">
|
|
|
|
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
|
|
|
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
|
|
|
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
|
|
|
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
|
|
|
<span>{{ t('chat.newChatTitle') }}</span>
|
|
|
|
<span>当前没有会话哦</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<template v-else>
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<Message
|
|
|
|
<Message
|
|
|
|
v-for="(item, index) of dataSources"
|
|
|
|
v-for="(item, index) of dataSources.filter(x=>x.text||x.fileList?.length>0)"
|
|
|
|
:key="index"
|
|
|
|
:key="index"
|
|
|
|
:date-time="item.dateTime"
|
|
|
|
:date-time="item.dateTime"
|
|
|
|
:text="item.text"
|
|
|
|
:text="item.text"
|
|
|
@ -645,7 +399,6 @@ const customRequest=async (file)=>{
|
|
|
|
:inversion="item.inversion"
|
|
|
|
:inversion="item.inversion"
|
|
|
|
:error="item.error"
|
|
|
|
:error="item.error"
|
|
|
|
:loading="item.loading"
|
|
|
|
:loading="item.loading"
|
|
|
|
@regenerate="onRegenerate(index)"
|
|
|
|
|
|
|
|
@delete="handleDelete(index)"
|
|
|
|
@delete="handleDelete(index)"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<div class="sticky bottom-0 left-0 flex justify-center">
|
|
|
|
<div class="sticky bottom-0 left-0 flex justify-center">
|
|
|
@ -653,7 +406,7 @@ const customRequest=async (file)=>{
|
|
|
|
<template #icon>
|
|
|
|
<template #icon>
|
|
|
|
<SvgIcon icon="ri:stop-circle-line" />
|
|
|
|
<SvgIcon icon="ri:stop-circle-line" />
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
{{ t('common.stopResponding') }}
|
|
|
|
停止响应
|
|
|
|
</NButton>
|
|
|
|
</NButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -664,6 +417,28 @@ const customRequest=async (file)=>{
|
|
|
|
<footer :class="footerClass">
|
|
|
|
<footer :class="footerClass">
|
|
|
|
<div class="w-full max-w-screen-xl m-auto">
|
|
|
|
<div class="w-full max-w-screen-xl m-auto">
|
|
|
|
<div class="flex items-center justify-between space-x-2" style="flex-wrap: initial">
|
|
|
|
<div class="flex items-center justify-between space-x-2" style="flex-wrap: initial">
|
|
|
|
|
|
|
|
<a-popover :open="visible1" trigger="click">
|
|
|
|
|
|
|
|
<template #content>
|
|
|
|
|
|
|
|
<div class="clearfix">
|
|
|
|
|
|
|
|
<a-upload
|
|
|
|
|
|
|
|
:max-count="1"
|
|
|
|
|
|
|
|
v-model:file-list="fileList1"
|
|
|
|
|
|
|
|
name="file"
|
|
|
|
|
|
|
|
:customRequest="upItemImage1"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<a-button>
|
|
|
|
|
|
|
|
<upload-outlined></upload-outlined>
|
|
|
|
|
|
|
|
上传文件
|
|
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
|
|
</a-upload>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<HoverButton @click="visible1=!visible1">
|
|
|
|
|
|
|
|
<span class="text-xl text-[#4f555e] dark:text-white" style="display: flex;justify-content: center;align-items: center">
|
|
|
|
|
|
|
|
<SvgIcon icon="ri:upload-2-line" />
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
</HoverButton>
|
|
|
|
|
|
|
|
</a-popover>
|
|
|
|
<a-popover v-if="gptMode==='gpt-4-vision-preview'" :open="visible" trigger="click">
|
|
|
|
<a-popover v-if="gptMode==='gpt-4-vision-preview'" :open="visible" trigger="click">
|
|
|
|
<template #content>
|
|
|
|
<template #content>
|
|
|
|
<div class="clearfix">
|
|
|
|
<div class="clearfix">
|
|
|
@ -720,7 +495,7 @@ const customRequest=async (file)=>{
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</NAutoComplete>
|
|
|
|
</NAutoComplete>
|
|
|
|
<NButton type="primary" :disabled="buttonDisabled" @click="handleSubmit">
|
|
|
|
<NButton color="#8a2be2" type="primary" :disabled="buttonDisabled" @click="handleSubmit">
|
|
|
|
<template #icon>
|
|
|
|
<template #icon>
|
|
|
|
<span class="dark:text-black">
|
|
|
|
<span class="dark:text-black">
|
|
|
|
<SvgIcon icon="ri:send-plane-fill" />
|
|
|
|
<SvgIcon icon="ri:send-plane-fill" />
|
|
|
|