fix: 修复知识库文档中若图片不存在,前端对话闪烁问题 (#1483)
This commit is contained in:
parent
ce3976f8db
commit
80415c9372
@ -22,14 +22,19 @@ class MarkChunkHandle(IChunkHandle):
|
|||||||
for chunk in chunk_list:
|
for chunk in chunk_list:
|
||||||
chunk_result = re.findall(split_chunk_pattern, chunk, flags=re.DOTALL)
|
chunk_result = re.findall(split_chunk_pattern, chunk, flags=re.DOTALL)
|
||||||
for c_r in chunk_result:
|
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)
|
other_chunk_list = re.split(split_chunk_pattern, chunk, flags=re.DOTALL)
|
||||||
for other_chunk in other_chunk_list:
|
for other_chunk in other_chunk_list:
|
||||||
if len(other_chunk) > 0:
|
if len(other_chunk) > 0:
|
||||||
if len(other_chunk) < max_chunk_len:
|
if len(other_chunk) < max_chunk_len:
|
||||||
result.append(other_chunk)
|
if len(other_chunk.strip()) > 0:
|
||||||
|
result.append(other_chunk.strip())
|
||||||
else:
|
else:
|
||||||
max_chunk_list = re.findall(max_chunk_pattern, other_chunk, flags=re.DOTALL)
|
max_chunk_list = re.findall(max_chunk_pattern, other_chunk, flags=re.DOTALL)
|
||||||
for m_c in max_chunk_list:
|
for m_c in max_chunk_list:
|
||||||
result.append(m_c)
|
if len(m_c.strip()) > 0:
|
||||||
|
result.append(m_c.strip())
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class TencentEmbeddingModel(MaxKBBaseModel, Embeddings):
|
|||||||
request = GetEmbeddingRequest()
|
request = GetEmbeddingRequest()
|
||||||
request.Input = text
|
request.Input = text
|
||||||
res = self.client.GetEmbedding(request)
|
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):
|
def __init__(self, secret_id: str, secret_key: str, model_name: str):
|
||||||
self.secret_id = secret_id
|
self.secret_id = secret_id
|
||||||
|
|||||||
@ -68,9 +68,37 @@ const md_view_list = computed(() => {
|
|||||||
return md_img_list[Math.floor(index / 2)]
|
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>) => {
|
const split_quick_question = (result: Array<string>) => {
|
||||||
return result
|
return result
|
||||||
.map((item) => split_quick_question_(item))
|
.map((item) => split_quick_question_(item))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user