Browse Source

feat: 提交

master
yuanjs@qutke.com 2 months ago
parent
commit
b883f2215e
  1. 6
      src/main/java/cn/ai/springaigu/config/XiaozhiAgentConfig.java
  2. 1
      ui/package.json
  3. 85
      ui/src/components/ChatWindow.vue

6
src/main/java/cn/ai/springaigu/config/XiaozhiAgentConfig.java

@ -38,9 +38,9 @@ public class XiaozhiAgentConfig {
ContentRetriever contentRetrieverXiaozhi() { ContentRetriever contentRetrieverXiaozhi() {
//使用FileSystemDocumentLoader读取指定目录下的知识库文档 //使用FileSystemDocumentLoader读取指定目录下的知识库文档
//并使用默认的文档解析器对文档进行解析 //并使用默认的文档解析器对文档进行解析
Document document1 = FileSystemDocumentLoader.loadDocument("D:/学习/课件/knowledge/医院信息.md"); Document document1 = FileSystemDocumentLoader.loadDocument("D:/学习/sping-ai/knowledge/医院信息.md");
Document document2 = FileSystemDocumentLoader.loadDocument("D:/学习/课件/knowledge/科室信息.md"); Document document2 = FileSystemDocumentLoader.loadDocument("D:/学习/sping-ai/knowledge/科室信息.md");
Document document3 = FileSystemDocumentLoader.loadDocument("D:/学习/课件/knowledge/神经内科.md"); Document document3 = FileSystemDocumentLoader.loadDocument("D:/学习/sping-ai/knowledge/神经内科.md");
List<Document> documents = Arrays.asList(document1, document2, document3); List<Document> documents = Arrays.asList(document1, document2, document3);
//使用内存向量存储 生产不建议使用 //使用内存向量存储 生产不建议使用
InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>(); InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();

1
ui/package.json

@ -13,6 +13,7 @@
"@element-plus/icons-vue": "^2.3.1", "@element-plus/icons-vue": "^2.3.1",
"axios": "^1.7.7", "axios": "^1.7.7",
"element-plus": "^2.8.4", "element-plus": "^2.8.4",
"marked": "^15.0.11",
"uuid": "^10.0.0", "uuid": "^10.0.0",
"vue": "^3.5.13" "vue": "^3.5.13"
}, },

85
ui/src/components/ChatWindow.vue

@ -30,7 +30,7 @@
></i> ></i>
<!-- 会话内容 --> <!-- 会话内容 -->
<span> <span>
<span v-html="message.content"></span> <span v-html="convertStreamOutput(message.content)"></span>
<!-- loading --> <!-- loading -->
<span <span
class="loading-dots" class="loading-dots"
@ -61,6 +61,7 @@
import { onMounted, ref, watch } from 'vue' import { onMounted, ref, watch } from 'vue'
import axios from 'axios' import axios from 'axios'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { marked } from 'marked'
const messaggListRef = ref() const messaggListRef = ref()
const isSending = ref(false) const isSending = ref(false)
@ -100,12 +101,11 @@ const sendRequest = (message) => {
isTyping: false, isTyping: false,
isThinking: false, isThinking: false,
} }
// //""
if(messages.value.length > 0){ if(messages.value.length > 0){
messages.value.push(userMsg) messages.value.push(userMsg)
} }
// //
const botMsg = { const botMsg = {
isUser: false, isUser: false,
@ -127,7 +127,6 @@ const sendRequest = (message) => {
const fullText = e.event.target.responseText // const fullText = e.event.target.responseText //
let newText = fullText.substring(lastMsg.content.length) let newText = fullText.substring(lastMsg.content.length)
lastMsg.content += newText // lastMsg.content += newText //
console.log(lastMsg)
scrollToBottom() // scrollToBottom() //
}, },
} }
@ -166,12 +165,12 @@ const uuidToNumber = (uuid) => {
// //
const convertStreamOutput = (output) => { const convertStreamOutput = (output) => {
return output // 使 marked Markdown
.replace(/\n/g, '<br>') return marked(output, {
.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;') breaks: true, //
.replace(/&/g, '&amp;') // HTML gfm: true, // GitHub Markdown
.replace(/</g, '&lt;') sanitize: true // XSS
.replace(/>/g, '&gt;') })
} }
const newChat = () => { const newChat = () => {
@ -378,4 +377,70 @@ const newChat = () => {
margin-top: 20px; margin-top: 20px;
} }
} }
/* Markdown 样式 */
:deep(p) {
margin: 0.5em 0;
}
:deep(pre) {
background-color: #f6f8fa;
border-radius: 6px;
padding: 16px;
overflow: auto;
margin: 0.5em 0;
}
:deep(code) {
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
background-color: rgba(175, 184, 193, 0.2);
padding: 0.2em 0.4em;
border-radius: 6px;
font-size: 85%;
}
:deep(ul), :deep(ol) {
padding-left: 2em;
margin: 0.5em 0;
}
:deep(li) {
margin: 0.25em 0;
}
:deep(blockquote) {
margin: 0.5em 0;
padding: 0 1em;
color: #57606a;
border-left: 0.25em solid #d0d7de;
}
:deep(table) {
border-collapse: collapse;
width: 100%;
margin: 0.5em 0;
}
:deep(th), :deep(td) {
border: 1px solid #d0d7de;
padding: 6px 13px;
}
:deep(th) {
background-color: #f6f8fa;
}
:deep(img) {
max-width: 100%;
height: auto;
}
:deep(a) {
color: #0969da;
text-decoration: none;
}
:deep(a:hover) {
text-decoration: underline;
}
</style> </style>

Loading…
Cancel
Save