diff --git a/apps/common/chunk/impl/mark_chunk_handle.py b/apps/common/chunk/impl/mark_chunk_handle.py index 4f8623c9ca2..5bca2f4450b 100644 --- a/apps/common/chunk/impl/mark_chunk_handle.py +++ b/apps/common/chunk/impl/mark_chunk_handle.py @@ -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 diff --git a/apps/setting/models_provider/impl/tencent_model_provider/model/embedding.py b/apps/setting/models_provider/impl/tencent_model_provider/model/embedding.py index c9ad57e26ca..659a5ac12b4 100644 --- a/apps/setting/models_provider/impl/tencent_model_provider/model/embedding.py +++ b/apps/setting/models_provider/impl/tencent_model_provider/model/embedding.py @@ -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 diff --git a/ui/src/components/markdown/MdRenderer.vue b/ui/src/components/markdown/MdRenderer.vue index 76ab43fa43b..84861afe35f 100644 --- a/ui/src/components/markdown/MdRenderer.vue +++ b/ui/src/components/markdown/MdRenderer.vue @@ -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) => { + 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) => { return result .map((item) => split_quick_question_(item))