mirror of
http://112.124.100.131/ebiz-ai/ebiz-base-ai.git
synced 2025-12-09 02:46:50 +08:00
Merge remote-tracking branch 'origin/feature/changesheng' into feature/changesheng
# Conflicts: # src/views/AI-new/components/chat-new.vue
This commit is contained in:
@@ -56,54 +56,54 @@ import { audioToText, gwcsChat } from '@/api/generatedApi'
|
|||||||
|
|
||||||
const MESSAGE_STATUS = {
|
const MESSAGE_STATUS = {
|
||||||
processing: 1,
|
processing: 1,
|
||||||
end: 0,
|
end: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
SvgIcon,
|
SvgIcon
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
messages: {
|
messages: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => []
|
||||||
},
|
},
|
||||||
messageStatus: {
|
messageStatus: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'stop',
|
default: 'stop'
|
||||||
},
|
},
|
||||||
isDeep: {
|
isDeep: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false
|
||||||
},
|
},
|
||||||
isSearching: {
|
isSearching: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false
|
||||||
},
|
},
|
||||||
conversationId: {
|
conversationId: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: ''
|
||||||
},
|
},
|
||||||
productName: {
|
productName: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: ''
|
||||||
},
|
},
|
||||||
autoScrollEnabled: {
|
autoScrollEnabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false
|
||||||
},
|
},
|
||||||
chatData: {
|
chatData: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({}),
|
default: () => ({})
|
||||||
},
|
},
|
||||||
appType: {
|
appType: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'gwcsHelper',
|
default: 'gwcsHelper'
|
||||||
},
|
},
|
||||||
action: {
|
action: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'normal_chat',
|
default: 'normal_chat'
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -124,7 +124,7 @@ export default {
|
|||||||
genMessage: null,
|
genMessage: null,
|
||||||
messageInfo: {
|
messageInfo: {
|
||||||
is_complete: false.toString(),
|
is_complete: false.toString(),
|
||||||
information: '',
|
information: ''
|
||||||
},
|
},
|
||||||
currentMessageID: '',
|
currentMessageID: '',
|
||||||
// 打字机相关
|
// 打字机相关
|
||||||
@@ -154,7 +154,7 @@ export default {
|
|||||||
this.genMessage.status = MESSAGE_STATUS.processing
|
this.genMessage.status = MESSAGE_STATUS.processing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
deepInternet() {
|
deepInternet() {
|
||||||
@@ -178,7 +178,7 @@ export default {
|
|||||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
|
||||||
this.mediaRecorder = new MediaRecorder(stream)
|
this.mediaRecorder = new MediaRecorder(stream)
|
||||||
this.audioChunks = []
|
this.audioChunks = []
|
||||||
this.mediaRecorder.ondataavailable = (event) => {
|
this.mediaRecorder.ondataavailable = event => {
|
||||||
if (event.data.size > 0) {
|
if (event.data.size > 0) {
|
||||||
this.audioChunks.push(event.data)
|
this.audioChunks.push(event.data)
|
||||||
}
|
}
|
||||||
@@ -222,17 +222,17 @@ export default {
|
|||||||
formData.append('appType', 'haslBigHelper')
|
formData.append('appType', 'haslBigHelper')
|
||||||
formData.append('user', 'chenyuda')
|
formData.append('user', 'chenyuda')
|
||||||
audioToText(formData)
|
audioToText(formData)
|
||||||
.then((res) => {
|
.then(res => {
|
||||||
if (res) {
|
if (res) {
|
||||||
resolve(res.content)
|
resolve(res.content)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
axiosGetAiChat() {
|
axiosGetAiChat(requestIndex = 1) {
|
||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
this.requestSingle = abortController
|
this.requestSingle = abortController
|
||||||
this.messageInfo.information = this.single ? this.messageInfo.information : this.newMessage
|
this.messageInfo.information = this.single ? this.messageInfo.information : this.newMessage
|
||||||
@@ -259,7 +259,7 @@ export default {
|
|||||||
conversationId: this.conversationId,
|
conversationId: this.conversationId,
|
||||||
message: this.action === 'normal_chat' ? this.newMessage : JSON.stringify(this.messageInfo),
|
message: this.action === 'normal_chat' ? this.newMessage : JSON.stringify(this.messageInfo),
|
||||||
user: 'gwcs-test',
|
user: 'gwcs-test',
|
||||||
inputs: {},
|
inputs: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentMessage = {
|
this.currentMessage = {
|
||||||
@@ -271,7 +271,7 @@ export default {
|
|||||||
isThink: false,
|
isThink: false,
|
||||||
showThink: false,
|
showThink: false,
|
||||||
isLike: false,
|
isLike: false,
|
||||||
isDisLike: false,
|
isDisLike: false
|
||||||
}
|
}
|
||||||
if (this.single) {
|
if (this.single) {
|
||||||
// this.$set(this.messages, this.messages.length - 1, { ...this.currentMessage })
|
// this.$set(this.messages, this.messages.length - 1, { ...this.currentMessage })
|
||||||
@@ -291,13 +291,13 @@ export default {
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
signal: abortController.signal,
|
signal: abortController.signal,
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
timeout: 60000,
|
timeout: 60000
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async res => {
|
||||||
await this.processStreamResponse(res, this.requestIndex)
|
await this.processStreamResponse(res, requestIndex)
|
||||||
this.single = false
|
this.single = false
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
// debugger
|
// debugger
|
||||||
this.$emit('update:messageStatus', 'stop')
|
this.$emit('update:messageStatus', 'stop')
|
||||||
})
|
})
|
||||||
@@ -316,7 +316,7 @@ export default {
|
|||||||
if (done) break
|
if (done) break
|
||||||
buffer += new TextDecoder().decode(value)
|
buffer += new TextDecoder().decode(value)
|
||||||
const lines = buffer.split('\n')
|
const lines = buffer.split('\n')
|
||||||
lines.slice(0, -1).forEach((line) => {
|
lines.slice(0, -1).forEach(line => {
|
||||||
const parsed = this.parseStreamLine(line)
|
const parsed = this.parseStreamLine(line)
|
||||||
if (parsed) this.updateMessageContent(parsed, requestIndex)
|
if (parsed) this.updateMessageContent(parsed, requestIndex)
|
||||||
})
|
})
|
||||||
@@ -348,8 +348,8 @@ export default {
|
|||||||
if (is_complete && is_complete[1] === 'true' && text && text[1].trim() === '') {
|
if (is_complete && is_complete[1] === 'true' && text && text[1].trim() === '') {
|
||||||
this.requestSingle.abort()
|
this.requestSingle.abort()
|
||||||
this.single = true
|
this.single = true
|
||||||
this.axiosGetAiChat()
|
this.axiosGetAiChat(2)
|
||||||
this.requestIndex++
|
|
||||||
// this.typingQueue = []
|
// this.typingQueue = []
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -392,7 +392,7 @@ export default {
|
|||||||
const chars = {
|
const chars = {
|
||||||
answer: answer,
|
answer: answer,
|
||||||
isThink: isThink,
|
isThink: isThink,
|
||||||
message_id,
|
message_id
|
||||||
}
|
}
|
||||||
|
|
||||||
this.typingQueue.push(chars)
|
this.typingQueue.push(chars)
|
||||||
@@ -410,13 +410,6 @@ export default {
|
|||||||
|
|
||||||
// 取出一个完整文本块
|
// 取出一个完整文本块
|
||||||
const chunk = this.typingQueue.shift()
|
const chunk = this.typingQueue.shift()
|
||||||
// if (chunk.message_id !== this.currentMessageID) {
|
|
||||||
// console.log('message_id !== this.currentMessageID');
|
|
||||||
// typeNextChar()
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// console.log(this.messages);
|
|
||||||
|
|
||||||
const chars = Array.from(chunk.answer)
|
const chars = Array.from(chunk.answer)
|
||||||
|
|
||||||
const isThink = chunk.isThink
|
const isThink = chunk.isThink
|
||||||
@@ -474,8 +467,8 @@ export default {
|
|||||||
|
|
||||||
cancelSend() {
|
cancelSend() {
|
||||||
this.requestSingle.abort()
|
this.requestSingle.abort()
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user