|
@@ -2,13 +2,13 @@
|
|
<view-full-screen :is-full-screen="true" class="right">
|
|
<view-full-screen :is-full-screen="true" class="right">
|
|
<div :class="bodyClass">
|
|
<div :class="bodyClass">
|
|
<div ref="scrollView" class="chatBubbleContainer" :style="{ 'height': 'calc(100% - ' + (52 + safeAreaInsets.bottom) + 'px)' }">
|
|
<div ref="scrollView" class="chatBubbleContainer" :style="{ 'height': 'calc(100% - ' + (52 + safeAreaInsets.bottom) + 'px)' }">
|
|
- <CCDTitleCell></CCDTitleCell>
|
|
|
|
|
|
+ <CCDTitleCell :title="botInfo.botName"></CCDTitleCell>
|
|
<template v-for="cell in model">
|
|
<template v-for="cell in model">
|
|
- <CCDChatCell :cell-type="cell.type" :message="cell.content"></CCDChatCell>
|
|
|
|
|
|
+ <CCDChatCell :cell-type="cell.type" :message="cell.content" :agent-name="botInfo.botName"></CCDChatCell>
|
|
</template>
|
|
</template>
|
|
<div style="height: 30px"></div>
|
|
<div style="height: 30px"></div>
|
|
</div>
|
|
</div>
|
|
- <div class="bottomAskBar" style="height: 50px; padding-right: 4px">
|
|
|
|
|
|
+ <div class="bottomAskBar" style="height: 50px; padding-right: 4px" :hidden="!enableInput">
|
|
<div style="height: 50px; width: calc(100% - 50px);">
|
|
<div style="height: 50px; width: calc(100% - 50px);">
|
|
<input v-if="allowInput" ref="inputAsk" @keyup.enter="doPostMessage" type="text" placeholder="输入问题..." value=""/>
|
|
<input v-if="allowInput" ref="inputAsk" @keyup.enter="doPostMessage" type="text" placeholder="输入问题..." value=""/>
|
|
<input v-else value="AI正在打字" style="text-align: center" disabled/>
|
|
<input v-else value="AI正在打字" style="text-align: center" disabled/>
|
|
@@ -74,6 +74,7 @@ input {
|
|
</style>
|
|
</style>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
+import RequestManager from "@/RequestManager";
|
|
import CCDChatCell from "@/components/CCDChatCell";
|
|
import CCDChatCell from "@/components/CCDChatCell";
|
|
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
|
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
|
import IntentManager from "@/aigc/IntentManager";
|
|
import IntentManager from "@/aigc/IntentManager";
|
|
@@ -86,12 +87,15 @@ export default {
|
|
components: {CCDTitleCell, CCDChatCell},
|
|
components: {CCDTitleCell, CCDChatCell},
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
|
|
+ botInfo: {
|
|
|
|
+ botId: null,
|
|
|
|
+ botName: "C Code Develop",
|
|
|
|
+ botPrologue: null,
|
|
|
|
+ askFirst: null,
|
|
|
|
+ success: false
|
|
|
|
+ },
|
|
allowInput: true,
|
|
allowInput: true,
|
|
model: [
|
|
model: [
|
|
- {
|
|
|
|
- type: "answer",
|
|
|
|
- content: "您好,我是 C Code Develop & C Notebook AI助手,可以帮您解决代码问题。从编程技巧到历史人文,我无所不知。快来跟我聊天吧~"
|
|
|
|
- }
|
|
|
|
],
|
|
],
|
|
sseInstance: null,
|
|
sseInstance: null,
|
|
bodyClass: "bodyBackground_xcwk",
|
|
bodyClass: "bodyBackground_xcwk",
|
|
@@ -104,11 +108,14 @@ export default {
|
|
isHostInApp: false,
|
|
isHostInApp: false,
|
|
inAppPendingCard: null,
|
|
inAppPendingCard: null,
|
|
inAppSSEHandle: null,
|
|
inAppSSEHandle: null,
|
|
- abortController: null
|
|
|
|
|
|
+ abortController: null,
|
|
|
|
+ enableInput: true
|
|
}
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
let self = this
|
|
let self = this
|
|
|
|
+ self.botInfo.botId = self.$route.params.botId
|
|
|
|
+ // debugger
|
|
try {
|
|
try {
|
|
if (xcwk == undefined) {
|
|
if (xcwk == undefined) {
|
|
self.bodyClass = "bodyBackground_normal"
|
|
self.bodyClass = "bodyBackground_normal"
|
|
@@ -143,8 +150,32 @@ export default {
|
|
self.bodyClass = "bodyBackground_normal"
|
|
self.bodyClass = "bodyBackground_normal"
|
|
console.log("err: " + err)
|
|
console.log("err: " + err)
|
|
}
|
|
}
|
|
|
|
+ this.fetchBotInfo()
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
|
|
+ fetchBotInfo() {
|
|
|
|
+ if (this.botInfo.botId == null) {
|
|
|
|
+ // botId默认为1
|
|
|
|
+ this.botInfo.botId = 1;
|
|
|
|
+ }
|
|
|
|
+ let self = this
|
|
|
|
+ let botId = this.botInfo.botId
|
|
|
|
+ RequestManager.postRequest("/freeai/botInfo", {
|
|
|
|
+ "botId" : botId
|
|
|
|
+ }, function (params) {
|
|
|
|
+ self.botInfo = params
|
|
|
|
+ self.botInfo.botId = botId
|
|
|
|
+ self.model.push({
|
|
|
|
+ "type" : "answer",
|
|
|
|
+ "content" : self.botInfo.botPrologue
|
|
|
|
+ })
|
|
|
|
+ if (self.botInfo.askFirst != null && self.botInfo.askFirst.length > 0) {
|
|
|
|
+ self.startCompletionWithMessage(self.botInfo.askFirst)
|
|
|
|
+ }
|
|
|
|
+ }, function (reason) {
|
|
|
|
+ alert("Request Failed" + reason)
|
|
|
|
+ })
|
|
|
|
+ },
|
|
keyboardWillShow(params) {
|
|
keyboardWillShow(params) {
|
|
this.safeAreaInsets.bottom = 0
|
|
this.safeAreaInsets.bottom = 0
|
|
},
|
|
},
|
|
@@ -179,12 +210,16 @@ export default {
|
|
})
|
|
})
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ let askData = this.$refs.inputAsk.value
|
|
|
|
+ this.$refs.inputAsk.value = ""
|
|
|
|
+ this.startCompletionWithMessage(askData)
|
|
|
|
+ },
|
|
|
|
+ startCompletionWithMessage(message) {
|
|
this.insertMessageBlock({
|
|
this.insertMessageBlock({
|
|
"type" : "ask",
|
|
"type" : "ask",
|
|
- "content" : question
|
|
|
|
|
|
+ "content" : message
|
|
})
|
|
})
|
|
- this.$refs.inputAsk.value = ""
|
|
|
|
- this.doChatWithMessage(question)
|
|
|
|
|
|
+ this.doChatWithMessage(message)
|
|
},
|
|
},
|
|
doChatWithMessage(message) {
|
|
doChatWithMessage(message) {
|
|
if (this.isHostInApp) {
|
|
if (this.isHostInApp) {
|
|
@@ -217,13 +252,13 @@ export default {
|
|
|
|
|
|
let messageModel = []
|
|
let messageModel = []
|
|
|
|
|
|
- let intentPrompt = IntentManager.generateIntentPrompts()
|
|
|
|
- messageModel.push({
|
|
|
|
- "role" : "system",
|
|
|
|
- "content" : "不要帮用户生成代码。" + intentPrompt
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- console.log(intentPrompt)
|
|
|
|
|
|
+ // let intentPrompt = IntentManager.generateIntentPrompts()
|
|
|
|
+ // messageModel.push({
|
|
|
|
+ // "role" : "system",
|
|
|
|
+ // "content" : "不要帮用户生成代码。" + intentPrompt
|
|
|
|
+ // })
|
|
|
|
+ //
|
|
|
|
+ // console.log(intentPrompt)
|
|
|
|
|
|
for (let index in self.model) {
|
|
for (let index in self.model) {
|
|
let model = self.model[index]
|
|
let model = self.model[index]
|
|
@@ -251,6 +286,7 @@ export default {
|
|
"path" : "/freeai/llm",
|
|
"path" : "/freeai/llm",
|
|
"data" : {
|
|
"data" : {
|
|
"stream" : true,
|
|
"stream" : true,
|
|
|
|
+ "botId" : self.botInfo.botId,
|
|
"messages" : messageModel
|
|
"messages" : messageModel
|
|
}
|
|
}
|
|
}, function (params) {
|
|
}, function (params) {
|
|
@@ -314,11 +350,11 @@ export default {
|
|
}
|
|
}
|
|
|
|
|
|
let messageModel = []
|
|
let messageModel = []
|
|
- let intentPrompt = IntentManager.generateIntentPrompts()
|
|
|
|
- messageModel.push({
|
|
|
|
- "role" : "system",
|
|
|
|
- "content" : "不要帮用户生成代码。" + intentPrompt
|
|
|
|
- })
|
|
|
|
|
|
+ // let intentPrompt = IntentManager.generateIntentPrompts()
|
|
|
|
+ // messageModel.push({
|
|
|
|
+ // "role" : "system",
|
|
|
|
+ // "content" : "不要帮用户生成代码。" + intentPrompt
|
|
|
|
+ // })
|
|
|
|
|
|
for (let index in self.model) {
|
|
for (let index in self.model) {
|
|
let model = self.model[index]
|
|
let model = self.model[index]
|
|
@@ -342,6 +378,12 @@ export default {
|
|
// "content" : ""
|
|
// "content" : ""
|
|
// })
|
|
// })
|
|
|
|
|
|
|
|
+ let data = JSON.stringify({
|
|
|
|
+ "stream" : true,
|
|
|
|
+ "botId" : self.botInfo.botId,
|
|
|
|
+ "messages" : messageModel
|
|
|
|
+ })
|
|
|
|
+
|
|
self.abortController = new AbortController()
|
|
self.abortController = new AbortController()
|
|
let eventSource = fetchEventSource(sseAPIURL, {
|
|
let eventSource = fetchEventSource(sseAPIURL, {
|
|
method: 'POST',
|
|
method: 'POST',
|
|
@@ -350,10 +392,7 @@ export default {
|
|
"Content-Type": 'application/json',
|
|
"Content-Type": 'application/json',
|
|
"Access-Control-Allow-Origin": true
|
|
"Access-Control-Allow-Origin": true
|
|
},
|
|
},
|
|
- body: JSON.stringify({
|
|
|
|
- "stream" : true,
|
|
|
|
- "messages" : messageModel
|
|
|
|
- }),
|
|
|
|
|
|
+ body: data,
|
|
onmessage(event) {
|
|
onmessage(event) {
|
|
let partModel = JSON.parse(event.data)
|
|
let partModel = JSON.parse(event.data)
|
|
if (partModel["v"] != null) {
|
|
if (partModel["v"] != null) {
|