This commit is contained in:
wangdan-fit2cloud 2023-11-27 18:57:52 +08:00
parent d9c373b15e
commit 4c3dbbf6af

View File

@ -73,7 +73,7 @@
text text
class="sent-button" class="sent-button"
:disabled="!(inputValue && data?.name && data?.model_id)" :disabled="!(inputValue && data?.name && data?.model_id)"
@click="chatHandle" @click="chatMessage"
> >
<img <img
v-show="!(inputValue && data?.name && data?.model_id)" v-show="!(inputValue && data?.name && data?.model_id)"
@ -103,6 +103,8 @@ const props = defineProps({
}) })
const loading = ref(false) const loading = ref(false)
const inputValue = ref('') const inputValue = ref('')
const chartOpenId = ref('')
function quickProblemHandel(val: string) { function quickProblemHandel(val: string) {
inputValue.value = val inputValue.value = val
} }
@ -110,7 +112,7 @@ function quickProblemHandel(val: string) {
/** /**
* 对话 * 对话
*/ */
function chatHandle() { function getChartOpenId() {
loading.value = true loading.value = true
const obj = { const obj = {
model_id: props.data.model_id, model_id: props.data.model_id,
@ -120,27 +122,32 @@ function chatHandle() {
applicationApi applicationApi
.postChatOpen(obj) .postChatOpen(obj)
.then((res) => { .then((res) => {
chatMessage(res.data) chartOpenId.value = res.data
chatMessage()
}) })
.catch(() => { .catch(() => {
loading.value = false loading.value = false
}) })
} }
function chatMessage(chatId: string) { function chatMessage() {
applicationApi.postChatMessage(chatId, inputValue.value).then(async (response) => { if (!chartOpenId.value) {
const reader = response.body.getReader() getChartOpenId()
while (true) { } else {
const { done, value } = await reader.read() applicationApi.postChatMessage(chartOpenId.value, inputValue.value).then(async (response) => {
if (done) { const reader = response.body.getReader()
loading.value = false while (true) {
break const { done, value } = await reader.read()
if (done) {
loading.value = false
break
}
const decoder = new TextDecoder('utf-8')
const str = decoder.decode(value, { stream: true })
console.log('value', JSON.parse(str.replace('data:', '')))
} }
const decoder = new TextDecoder('utf-8') })
const str = decoder.decode(value, { stream: true }) }
console.log('value', JSON.parse(str.replace('data:', '')))
}
})
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>