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,15 +122,19 @@ 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) {
getChartOpenId()
} else {
applicationApi.postChatMessage(chartOpenId.value, inputValue.value).then(async (response) => {
const reader = response.body.getReader() const reader = response.body.getReader()
while (true) { while (true) {
const { done, value } = await reader.read() const { done, value } = await reader.read()
@ -142,6 +148,7 @@ function chatMessage(chatId: string) {
} }
}) })
} }
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.ai-dialog { .ai-dialog {