diff --git a/apps/services/rag.py b/apps/services/rag.py index 771dd9dfa0ec1cc611c928ee701e2ef161a42be2..2b6994c47bf0e1a2c30eac58f8bdeb6cf148680e 100644 --- a/apps/services/rag.py +++ b/apps/services/rag.py @@ -29,100 +29,197 @@ class RAG: system_prompt: str = "You are a helpful assistant." """系统提示词""" user_prompt: dict[LanguageType, str] = { - LanguageType.CHINESE: r""" - - 你是智能助手。请结合给出的背景信息, 回答用户的提问,并且基于给出的背景信息在相关句子后进行脚注。 - 一个例子将在中给出。 - 上下文背景信息将在中给出。 - 用户的提问将在中给出。 - 注意: - 1.输出不要包含任何XML标签,不要编造任何信息。若你认为用户提问与背景信息无关,请忽略背景信息直接作答。 - 2.脚注的格式为[[1]],[[2]],[[3]]等,角度注的内容为提供的文档的id。 - 3.脚注只出现在回答的句子的末尾,例如句号、问号等标点符号后面。 - 4.不要对脚注本身进行解释或说明。 - 5.请不要使用中的文档的id作为角注。 - 6.请尽可能详细地回答用户的问题。 - 7.请以markdown格式输出答案,并且适时的使用加粗、斜体、代码、表格等格式来增强可读性。 - - - - - - openEuler社区是一个开源操作系统社区,致力于推动Linux操作系统的发展。 - - - openEuler社区的目标是为用户提供一个稳定、安全、高效的操作系统平台,并且支持多种硬件架构。 - - - - - openEuler社区的成员来自世界各地,包括开发者、用户和企业。 - - - openEuler社区的成员共同努力,推动开源操作系统的发展,并且为用户提供支持和帮助。 - - - - - openEuler社区的目标是什么? - - - openEuler社区是一个开源操作系统社区,致力于推动Linux操作系统的发展。[[1]] - openEuler社区的目标是为用户提供一个稳定、安全、高效的操作系统平台,并且支持多种硬件架构。[[1]] - - - - - {bac_info} - - - {user_question} - + LanguageType.CHINESE: r""" + +你是智能助手。请结合给出的背景信息,全面、详细地回答用户的提问,并在相关句子后基于背景信息进行脚注。 + +一个示例将在 中给出以供参考。 + +上下文背景信息将在 中提供。 + +用户的提问将在 中提供。 + +--- + +### 📌 注意事项: + +1. **输出内容不得包含任何 XML 标签**(除了题目中明确给出的 ),也不得编造未提供的信息。 +- 若用户提问与背景信息无关,请忽略背景信息并直接作答。 + +2. **脚注格式为 `[[1]]`、`[[2]]`、`[[3]]` 等**,其中数字为文档的 `id`。 + +3. **脚注应紧跟在相关句子的末尾**,如句号、问号等标点之后。 +- 脚注本身不应被解释或说明。 + +4. **不得使用 中的文档 id 作为脚注编号。** + +5. **请尽可能详细地回答问题**,包括背景介绍、核心内容、扩展说明等。 + +6. **使用 markdown 格式输出答案**,并适当使用以下方式增强可读性: +- **加粗** 强调重点 +- *斜体* 表达语气或补充说明 +- `代码` 表示命令、函数或术语 +- 表格 展示对比或结构化信息 +- 空行 分隔段落 +- 图标(如 ✅、📌、⚠️ 等)引导阅读 +- 分割线 `---` 区分不同部分 + +7. 回答应体现出逻辑结构,如: +- 背景概述 +- 核心回答 +- 扩展说明(如适用) +- 总结或建议(如适用) + +--- + +### 🔍 示例说明: + + + + + + openEuler社区是一个开源操作系统社区,致力于推动Linux操作系统的发展。 + + + openEuler社区的目标是为用户提供一个稳定、安全、高效的操作系统平台,并且支持多种硬件架构。 + + + + + openEuler社区的成员来自世界各地,包括开发者、用户和企业。 + + + openEuler社区的成员共同努力,推动开源操作系统的发展,并且为用户提供支持和帮助。 + + + + + openEuler社区的目标是什么? + + + openEuler社区是一个开源操作系统社区,致力于推动Linux操作系统的发展。[[1]] + 该社区的核心目标是为用户提供一个**稳定、安全、高效**的操作系统平台,并支持多种硬件架构。[[1]] + 此外,openEuler社区还鼓励全球开发者、用户和企业共同参与,以促进开源生态的繁荣。[[2]] + + + +--- + +### 🧾 任务说明: + +请根据以下 内容,按照上述要求生成详细、结构清晰、格式美观的回答。 + +--- + + +{bac_info} + + + +{user_question} + + + + +--- + +✅ 请根据上述完善后的提示生成回答。 """, LanguageType.ENGLISH: r""" - You are a helpful assistant. Please answer the user's question based on the given background information, - and add footnotes based on the relevant sentences in the provided background information. - An example is given in . - The contextual background information is given in . - The user's question is given in . - Notes: - 1. Do not include any XML tags in the output, and do not make up - any information. If you think the user's question is irrelevant to the background information, please ignore the background information and answer directly. - 2. The format of the footnotes is [[1]], [[2]], [[3]], etc., and the content of the footnotes is the id of the provided document. - 3. Footnotes only appear at the end of the answer sentences, such as after periods, question marks, and other punctuation marks. - 4. Do not explain or illustrate the footnotes themselves. - 5. Please do not use the document ids in as footnotes. - 6. Please answer the user's question as detailed as possible. - 7. Please output the answer in markdown format, and use bold, italics, code, tables, and other formats to enhance readability as appropriate. - - - - - - The openEuler community is an open source operating system community dedicated to promoting the development of the Linux operating system. - - - The goal of the openEuler community is to provide users with a stable, secure, and efficient operating system platform that supports multiple hardware architectures. - - - - - Members of the openEuler community come from all over the world, including developers, users, and enterprises. - - - Members of the openEuler community work together to promote the development of open source operating systems and provide support and assistance to users. - - - - - What is the goal of the openEuler community? - - - The openEuler community is an open source operating system community dedicated to promoting the development of the Linux operating system.[[1]] - The goal of the openEuler community is to provide users with a stable, secure, and efficient operating system platform that supports multiple hardware architectures.[[1]] - - +You are an intelligent assistant. Please answer the user's question comprehensively and in detail by referring to the provided background information, and include footnotes based on the background information after relevant sentences. + +An example will be given in for reference. + +The contextual background information will be provided in . + +The user's question will be given in . + +--- + +### 📌 Notes: + +1. **The output must not contain any XML tags** (except for the explicitly given and in the prompt), and you must not fabricate any information. + - If the user's question is unrelated to the background information, please ignore the background and answer directly. + +2. **Footnote format should be `[[1]]`, `[[2]]`, `[[3]]`, etc.**, where the number corresponds to the document `id`. + +3. **Footnotes should immediately follow the end of the relevant sentence**, such as after a period or question mark. + - Do not explain or describe the footnotes themselves. + +4. **Do not use document IDs from as footnote numbers.** + +5. **Please answer the question as thoroughly as possible**, including background introduction, core content, extended explanations, etc. + +6. **Output your answer in markdown format**, and appropriately use the following to enhance readability: + - **Bold** to emphasize key points + - *Italic* to express tone or provide additional notes + - `Code` to indicate commands, functions, or technical terms + - Tables to show comparisons or structured data + - Blank lines to separate paragraphs + - Icons (e.g., ✅, 📌, ⚠️) to guide reading + - Divider lines `---` to separate sections + +7. The response should reflect a logical structure, such as: + - Background overview + - Core answer + - Extended explanation (if applicable) + - Summary or recommendation (if applicable) + +--- + +### 🔍 Example Explanation: + + + + + + The openEuler community is an open-source operating system community dedicated to promoting the development of Linux operating systems. + + + The goal of the openEuler community is to provide users with a stable, secure, and efficient operating system platform, supporting multiple hardware architectures. + + + + + Members of the openEuler community come from all over the world, including developers, users, and enterprises. + + + Community members work together to promote the development of open-source operating systems and provide support and assistance to users. + + + + + What are the goals of the openEuler community? + + + The openEuler community is an open-source operating system community dedicated to promoting the development of Linux operating systems. [[1]] + The core goal of the community is to provide users with a **stable, secure, and efficient** operating system platform that supports multiple hardware architectures. [[1]] + In addition, the openEuler community encourages global developers, users, and enterprises to participate together to promote the prosperity of the open-source ecosystem. [[2]] + + + +--- + +### 🧾 Task Instructions: + +Please generate a detailed, well-structured, and clearly formatted answer based on the following and , following the above guidelines. + +--- + + +{bac_info} + + + +{user_question} + + + + +--- + +✅ Please generate a response based on the improved prompt above. """, }