Skip to content

Commit 80415c9

Browse files
authored
fix: 修复知识库文档中若图片不存在,前端对话闪烁问题 (#1483)
1 parent ce3976f commit 80415c9

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

apps/common/chunk/impl/mark_chunk_handle.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ def handle(self, chunk_list: List[str]):
2222
for chunk in chunk_list:
2323
chunk_result = re.findall(split_chunk_pattern, chunk, flags=re.DOTALL)
2424
for c_r in chunk_result:
25-
result.append(c_r)
25+
if len(c_r.strip()) > 0:
26+
result.append(c_r.strip())
27+
2628
other_chunk_list = re.split(split_chunk_pattern, chunk, flags=re.DOTALL)
2729
for other_chunk in other_chunk_list:
2830
if len(other_chunk) > 0:
2931
if len(other_chunk) < max_chunk_len:
30-
result.append(other_chunk)
32+
if len(other_chunk.strip()) > 0:
33+
result.append(other_chunk.strip())
3134
else:
3235
max_chunk_list = re.findall(max_chunk_pattern, other_chunk, flags=re.DOTALL)
3336
for m_c in max_chunk_list:
34-
result.append(m_c)
37+
if len(m_c.strip()) > 0:
38+
result.append(m_c.strip())
39+
3540
return result

apps/setting/models_provider/impl/tencent_model_provider/model/embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def embed_query(self, text: str) -> List[float]:
1717
request = GetEmbeddingRequest()
1818
request.Input = text
1919
res = self.client.GetEmbedding(request)
20-
return res.Data
20+
return res.Data[0].Embedding
2121

2222
def __init__(self, secret_id: str, secret_key: str, model_name: str):
2323
self.secret_id = secret_id

ui/src/components/markdown/MdRenderer.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,37 @@ const md_view_list = computed(() => {
6868
return md_img_list[Math.floor(index / 2)]
6969
}
7070
})
71-
return split_echarts_rander(split_html_rander(split_quick_question(result)))
71+
return split_echarts_rander(split_html_rander(split_quick_question(split_md_img(result))))
7272
})
73+
const split_md_img = (result: Array<string>) => {
74+
return result
75+
.map((item) => split_md_img_(item))
76+
.reduce((x: any, y: any) => {
77+
return [...x, ...y]
78+
}, [])
79+
}
7380
81+
const split_md_img_ = (source: string) => {
82+
const temp_md_img_list = source.match(/(!\[.*?\]\(.*?\){.*?})|(!\[.*?\]\(.*?\))/g)
83+
console.log(temp_md_img_list)
84+
const md_img_list = temp_md_img_list ? temp_md_img_list.filter((i) => i) : []
85+
const split_img_value = source
86+
.split(/(!\[.*?\]\(.*?\){.*?})|(!\[.*?\]\(.*?\))/g)
87+
.filter((item) => item !== undefined)
88+
.filter((item) => !md_img_list?.includes(item))
89+
const result = Array.from(
90+
{ length: md_img_list.length + split_img_value.length },
91+
(v, i) => i
92+
).map((index) => {
93+
if (index % 2 == 0) {
94+
return split_img_value[Math.floor(index / 2)]
95+
} else {
96+
return md_img_list[Math.floor(index / 2)]
97+
}
98+
})
99+
console.log(result)
100+
return result
101+
}
74102
const split_quick_question = (result: Array<string>) => {
75103
return result
76104
.map((item) => split_quick_question_(item))

0 commit comments

Comments
 (0)