From 065d1b556f92cef307ff4b7dca58cdd605ad420c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9F=A9=E5=BA=86=E4=BC=9F?= <1208669287@qq.com>
Date: Tue, 20 May 2025 16:55:52 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=9F=A5=E8=AF=86?=
=?UTF-8?q?=E5=BA=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
src/manifest.json | 1 -
src/pages/index/index.vue | 153 +++++++++++++++++++-------
src/pages/preview/index.vue | 45 +++++---
src/static/aichat/Knowledge-close.png | Bin 0 -> 776 bytes
src/static/aichat/Knowledge-open.png | Bin 0 -> 827 bytes
src/static/logo.png | Bin 0 -> 10513 bytes
7 files changed, 141 insertions(+), 60 deletions(-)
create mode 100644 src/static/aichat/Knowledge-close.png
create mode 100644 src/static/aichat/Knowledge-open.png
create mode 100644 src/static/logo.png
diff --git a/README.md b/README.md
index 7049379..8029803 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-
+
diff --git a/src/manifest.json b/src/manifest.json
index 692398c..30e9fa2 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -6,7 +6,6 @@
"versionCode": "100",
"transformPx": false,
"app-plus": {
-
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 3094c6b..72b3a2d 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -8,10 +8,10 @@
-
+
小墨
@@ -25,14 +25,14 @@
嗨! 我是小墨
@@ -41,7 +41,7 @@
@@ -60,11 +60,11 @@
/>
@@ -72,12 +72,22 @@
+
- +{{ msg.content.length - 3 }}
+ +{{ msg.content.length - 4 }}
-
@@ -155,11 +175,7 @@
class="absolute bottom--3.5 flex space-x-3 ml-1"
>
-
+
@@ -234,16 +250,42 @@
+
+
+
@@ -264,7 +307,10 @@
@@ -433,13 +479,12 @@ async function goChat(listUuid: string) {
const listUuid = ref('')
async function createChatSession() {
- console.log(token.value, 'wwww')
try {
const createResp: any = await uni.request({
url: `${baseUrl}/chat/create`,
method: 'POST',
data: {
- gptModel: 'gpt-3.5-turbo',
+ gptModel: 'gpt-4-vision-preview',
},
header: {
Authorization: token.value,
@@ -487,7 +532,7 @@ async function fetchHistoryDiets(value) {
method: 'POST',
data: {
listUuid: value,
- gptModel: 'gpt-3.5-turbo',
+ gptModel: 'gpt-4-vision-preview',
},
header: {
Authorization: token.value,
@@ -501,7 +546,9 @@ async function fetchHistoryDiets(value) {
console.error('fetchHistoryList error:', err)
}
}
-const token = ref('')
+const token = ref(
+ '79b5c732d96d2b27a48a99dfd4a5566c43aaa5796242e854ebe3ffc198d6876b9628e7b764d9af65ab5dbb2d517ced88170491b74b048c0ba827c0d3741462cb89dc59ed46653a449af837a8262941ca1430937103230a1e32a1715f569f3efdbe6f8cb8b7b8642bd679668081b9b08f693d1b5be6002d936ec51e1e3e0c4927de9e32ac99a109b326e5d2bda27ec87624bb416ec70d2a95a2e190feeba9f0d6bae8571b3dfe89c824712344759a8f2bff9d70747c52525cf6a5614f9c770bca461a9b9c247b6dca97bcf83bbaf99bb726752c4fe1e9a4aa7de5c4cf3e88a3e480801280d45cdc124f9d8221105d852945dc6ce10bc1647e4f09dff4d52ffdfc3ee452912e5908e2c574b766448c260449904f2a3c5ab9ed0235cfc8d5ba01f5d7c370733b136f7775849b03324fc6532d108779f9a7ff8dc40f235c56fec1b7a11ad61ac7e0a6a86f198079f4b92d61',
+)
const userInfo = ref({})
const refreshToken = ref('')
const statusBarHeight = ref(0)
@@ -513,7 +560,7 @@ onMounted(() => {
const init = async () => {
const wv = plus.webview.currentWebview()
- token.value = wv.token || uni.getStorageSync('token') || import.meta.env.VITE_DEV_TOKEN
+ // token.value = wv.token || uni.getStorageSync('token') || import.meta.env.VITE_DEV_TOKEN
userInfo.value = JSON.parse(wv.userInfo) || {}
refreshToken.value = wv.refreshToken || uni.getStorageSync('refreshToken')
statusBarHeight.value = wv.statusBarHeight || uni.getSystemInfoSync().statusBarHeight
@@ -558,6 +605,9 @@ const onScroll = (e) => {
//查看更多图片
const previewMoreImg = (files) => {
+ uni.removeStorageSync('previewImages')
+ uni.removeStorageSync('previewVideos')
+
uni.setStorageSync('previewImages', files)
uni.navigateTo({
@@ -567,6 +617,9 @@ const previewMoreImg = (files) => {
//查看视频
const previewVideo = (files) => {
+ uni.removeStorageSync('previewVideos')
+ uni.removeStorageSync('previewImages')
+
uni.setStorageSync('previewVideos', files)
uni.navigateTo({
@@ -769,7 +822,6 @@ const uploadFile = (file: UploadFile) => {
// 照片
const onPickImage = () => {
loading.value = true
-
uni.chooseImage({
count: 10, // 最多选择9张
sizeType: ['original', 'compressed'],
@@ -818,7 +870,7 @@ const onPickVideo = () => {
const onPickFile = () => {
uni.chooseFile({
count: 10,
- extension: uploadConfig.file.supportType,
+ type: uploadConfig.file.supportType,
success: (res: any) => {
console.log(res)
// 开始上传
@@ -859,11 +911,17 @@ const previewFile = (url: string) => {
url: '/pages/webview/index?link=' + encodeURIComponent(url),
})
}
-
+const msgLoading = ref(true)
// 发送消息
-async function sendText(msg) {
+async function sendText(msgData) {
+ msgLoading.value = true
const text = inputText.value.trim()
- if (!text || loading.value) return
+ if (!text) {
+ uni.showToast({ title: '请输入信息', icon: 'error' })
+
+ return
+ }
+ if (loading.value) return
//获取本次发送的消息和文件
const tempUploadList = Object.assign([], uploadList)
@@ -930,9 +988,10 @@ async function sendText(msg) {
content: text,
timestamp: new Date(),
}
-
+ addMessage(aiMsg)
//清除上传列表
uploadList.splice(0, uploadList.length)
+ // resds.value = historyUserMsgs
const body: IGptRequestBody = {
model: 'gpt-4-vision-preview',
@@ -942,7 +1001,7 @@ async function sendText(msg) {
top_p: 1,
presence_penalty: 0,
frequency_penalty: 0,
- messages: historyUserMsgs,
+ messages: msgData || historyUserMsgs,
stream: true,
}
@@ -979,7 +1038,10 @@ async function sendText(msg) {
const delta = json.choices?.[0]?.delta?.content
if (delta) {
+ msgLoading.value = false
aiMsg.content += delta
+ //每次更新messages消息,实现流式输出
+ messages[messages.length - 1] = { ...aiMsg }
scrollToBottom()
console.log('2')
}
@@ -988,8 +1050,6 @@ async function sendText(msg) {
}
}
- // 添加AI消息
- addMessage(aiMsg)
//更新上下文消息
historyUserMsgs.push(aiMsg)
scrollToBottom()
@@ -1016,10 +1076,19 @@ function copyText(msg: IMessage) {
}
}
-function refreshText(msg: IMessage) {
- const lastUserMsg = historyUserMsgs[historyUserMsgs.length - 1]
+function refreshText() {
+ const lastUserMsg = historyUserMsgs[historyUserMsgs.length - 2]
+ // resds.value = lastUserMsg
+
sendText(lastUserMsg)
}
+
+const knowledgeOpen = ref(false)
+function toggleKnowledge() {
+ knowledgeOpen.value = !knowledgeOpen.value
+ showActions.value = false
+ rotation.value = 0
+}