Skip to content

Commit 16ab1f0

Browse files
Pr@main@fix bugs (#27)
* fix: 优化word分段规则 * fix: 去除标题特殊字符 * fix: 对话重新生成问题 --------- Co-authored-by: wangdan-fit2cloud <[email protected]>
1 parent d0e4218 commit 16ab1f0

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

apps/common/handle/impl/doc_split_handle.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,25 @@
2222

2323

2424
class DocSplitHandle(BaseSplitHandle):
25+
@staticmethod
26+
def paragraph_to_md(paragraph):
27+
psn = paragraph.style.name
28+
if psn.startswith('Heading'):
29+
try:
30+
return "".join(["#" for i in range(int(psn.replace("Heading ", '')))]) + " " + paragraph.text
31+
except Exception as e:
32+
return paragraph.text
33+
return paragraph.text
34+
35+
def to_md(self, doc):
36+
ps = doc.paragraphs
37+
return "\n".join([self.paragraph_to_md(para) for para in ps])
38+
2539
def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_buffer):
2640
try:
2741
buffer = get_buffer(file)
2842
doc = Document(io.BytesIO(buffer))
29-
content = "\n".join([para.text for para in doc.paragraphs])
43+
content = self.to_md(doc)
3044
if pattern_list is not None and len(pattern_list) > 0:
3145
split_model = SplitModel(pattern_list, with_filter, limit)
3246
else:

apps/common/util/split_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,15 @@ def sub_title(paragraph: Dict):
351351

352352
@staticmethod
353353
def filter_title_special_characters(paragraph: Dict):
354-
return {**paragraph, 'title': paragraph.get('title').replace("#", '') if 'title' in paragraph else ''}
354+
title = paragraph.get('title') if 'title' in paragraph else ''
355+
for title_special_characters in title_special_characters_list:
356+
title = title.replace(title_special_characters, '')
357+
return {**paragraph,
358+
'title': title}
355359

356360

361+
title_special_characters_list = ['#', '\n', '\r', '\\s']
362+
357363
default_split_pattern = {
358364
'md': [re.compile('(?<=^)# .*|(?<=\\n)# .*'), re.compile('(?<!#)## (?!#).*'), re.compile("(?<!#)### (?!#).*"),
359365
re.compile("(?<!#)#### (?!#).*"), re.compile("(?<!#)##### (?!#).*"),

ui/src/api/application.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,12 @@ const getChatOpen: (applicaiton_id: String) => Promise<Result<any>> = (applicait
166166
}
167167
/**
168168
* 对话
169-
* @param 参数
169+
* @param 参数
170170
* chat_id: string
171-
* {
172-
"message": "string",
173-
}
171+
* data
174172
*/
175-
const postChatMessage: (chat_id: string, message: string) => Promise<any> = (chat_id, message) => {
176-
return postStream(`/api${prefix}/chat_message/${chat_id}`, { message })
173+
const postChatMessage: (chat_id: string, data: any) => Promise<any> = (chat_id, message) => {
174+
return postStream(`/api${prefix}/chat_message/${chat_id}`, data)
177175
}
178176

179177
/**

ui/src/components/ai-chat/index.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function sendChatHandle(event: any) {
285285
if (!event.ctrlKey) {
286286
// 如果没有按下组合键ctrl,则会阻止默认事件
287287
event.preventDefault()
288-
if (!isDisabledChart.value && !loading.value&&!event.isComposing) {
288+
if (!isDisabledChart.value && !loading.value && !event.isComposing) {
289289
chatMessage()
290290
}
291291
} else {
@@ -418,7 +418,7 @@ const errorWrite = (chat: any, message?: string) => {
418418
ChatManagement.append(chat.id, message || '抱歉,当前正在维护,无法提供服务,请稍后再试!')
419419
ChatManagement.close(chat.id)
420420
}
421-
function chatMessage(chat?: any, problem?: string) {
421+
function chatMessage(chat?: any, problem?: string, re_chat?: boolean) {
422422
loading.value = true
423423
if (!chat) {
424424
chat = reactive({
@@ -443,9 +443,13 @@ function chatMessage(chat?: any, problem?: string) {
443443
errorWrite(chat)
444444
})
445445
} else {
446+
const obj = {
447+
message: chat.problem_text,
448+
re_chat: re_chat || false
449+
}
446450
// 对话
447451
applicationApi
448-
.postChatMessage(chartOpenId.value, chat.problem_text)
452+
.postChatMessage(chartOpenId.value, obj)
449453
.then((response) => {
450454
if (response.status === 401) {
451455
application
@@ -491,7 +495,7 @@ function chatMessage(chat?: any, problem?: string) {
491495
492496
function regenerationChart(item: chatType) {
493497
inputValue.value = item.problem_text
494-
chatMessage()
498+
chatMessage(null, '', true)
495499
}
496500
497501
function getSourceDetail(row: any) {

ui/src/views/applicaiton-overview/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ function getAppStatistics() {
197197
198198
function refreshAccessToken() {
199199
MsgConfirm(
200-
`是否重新生成公共访问链接?`,
201-
`重新生成公共访问链接会影响嵌入第三方脚本变更,需要将新脚本重新嵌入第三方,请谨慎操作!`,
200+
`是否重新生成公开访问链接?`,
201+
`重新生成公开访问链接会影响嵌入第三方脚本变更,需要将新脚本重新嵌入第三方,请谨慎操作!`,
202202
{
203203
confirmButtonText: '确认'
204204
}

ui/src/views/dataset/component/UploadComponent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<em> 选择文件上传 </em>
2828
</p>
2929
<div class="upload__decoration">
30-
<p>支持格式:TXT、Markdown,每次最多上传50个文件,每个文件不超过 10MB</p>
30+
<p>支持格式:TXT、Markdown、PDF、DOC、DOCX,每次最多上传50个文件,每个文件不超过 10MB</p>
3131
<p>若使用【高级分段】建议上传前规范文件的分段标识</p>
3232
</div>
3333
</div>

0 commit comments

Comments
 (0)