fix: 修复知识库文档中若图片不存在,前端对话闪烁问题 (#1483)

This commit is contained in:
shaohuzhang1 2024-10-28 19:05:21 +08:00 committed by GitHub
parent ce3976f8db
commit 80415c9372
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 5 deletions

View File

@ -22,14 +22,19 @@ class MarkChunkHandle(IChunkHandle):
for chunk in chunk_list:
chunk_result = re.findall(split_chunk_pattern, chunk, flags=re.DOTALL)
for c_r in chunk_result:
result.append(c_r)
if len(c_r.strip()) > 0:
result.append(c_r.strip())
other_chunk_list = re.split(split_chunk_pattern, chunk, flags=re.DOTALL)
for other_chunk in other_chunk_list:
if len(other_chunk) > 0:
if len(other_chunk) < max_chunk_len:
result.append(other_chunk)
if len(other_chunk.strip()) > 0:
result.append(other_chunk.strip())
else:
max_chunk_list = re.findall(max_chunk_pattern, other_chunk, flags=re.DOTALL)
for m_c in max_chunk_list:
result.append(m_c)
if len(m_c.strip()) > 0:
result.append(m_c.strip())
return result

View File

@ -17,7 +17,7 @@ class TencentEmbeddingModel(MaxKBBaseModel, Embeddings):
request = GetEmbeddingRequest()
request.Input = text
res = self.client.GetEmbedding(request)
return res.Data
return res.Data[0].Embedding
def __init__(self, secret_id: str, secret_key: str, model_name: str):
self.secret_id = secret_id

View File

@ -68,9 +68,37 @@ const md_view_list = computed(() => {
return md_img_list[Math.floor(index / 2)]
}
})
return split_echarts_rander(split_html_rander(split_quick_question(result)))
return split_echarts_rander(split_html_rander(split_quick_question(split_md_img(result))))
})
const split_md_img = (result: Array<string>) => {
return result
.map((item) => split_md_img_(item))
.reduce((x: any, y: any) => {
return [...x, ...y]
}, [])
}
const split_md_img_ = (source: string) => {
const temp_md_img_list = source.match(/(!\[.*?\]\(.*?\){.*?})|(!\[.*?\]\(.*?\))/g)
console.log(temp_md_img_list)
const md_img_list = temp_md_img_list ? temp_md_img_list.filter((i) => i) : []
const split_img_value = source
.split(/(!\[.*?\]\(.*?\){.*?})|(!\[.*?\]\(.*?\))/g)
.filter((item) => item !== undefined)
.filter((item) => !md_img_list?.includes(item))
const result = Array.from(
{ length: md_img_list.length + split_img_value.length },
(v, i) => i
).map((index) => {
if (index % 2 == 0) {
return split_img_value[Math.floor(index / 2)]
} else {
return md_img_list[Math.floor(index / 2)]
}
})
console.log(result)
return result
}
const split_quick_question = (result: Array<string>) => {
return result
.map((item) => split_quick_question_(item))