Skip to content

Commit

Permalink
fix: 修复知识库文档中若图片不存,前端对话闪烁问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Oct 28, 2024
1 parent 83d9743 commit b0a8cf1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
11 changes: 8 additions & 3 deletions apps/common/chunk/impl/mark_chunk_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ def handle(self, chunk_list: List[str]):
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def embed_query(self, text: str) -> List[float]:
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
Expand Down
30 changes: 29 additions & 1 deletion ui/src/components/markdown/MdRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b0a8cf1

Please sign in to comment.