mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 12:32:30 +08:00
Refa: refactor prompts into markdown-style structure using Jinja2 (#8667)
### What problem does this PR solve? Refactor prompts into markdown-style structure using Jinja2. ### Type of change - [x] Refactoring
This commit is contained in:
21
rag/prompt_template.py
Normal file
21
rag/prompt_template.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
BASE_DIR = os.path.dirname(__file__)
|
||||
|
||||
PROMPT_DIR = os.path.join(BASE_DIR, "prompts")
|
||||
|
||||
_loaded_prompts = {}
|
||||
|
||||
|
||||
def load_prompt(name: str) -> str:
|
||||
if name in _loaded_prompts:
|
||||
return _loaded_prompts[name]
|
||||
|
||||
path = os.path.join(PROMPT_DIR, f"{name}.md")
|
||||
if not os.path.isfile(path):
|
||||
raise FileNotFoundError(f"Prompt file '{name}.md' not found in prompts/ directory.")
|
||||
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
content = f.read().strip()
|
||||
_loaded_prompts[name] = content
|
||||
return content
|
||||
316
rag/prompts.py
316
rag/prompts.py
@ -19,10 +19,11 @@ import logging
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
import jinja2
|
||||
import json_repair
|
||||
|
||||
from api import settings
|
||||
from api.db import LLMType
|
||||
from rag.prompt_template import load_prompt
|
||||
from rag.settings import TAG_FLD
|
||||
from rag.utils import encoder, num_tokens_from_string
|
||||
|
||||
@ -135,70 +136,31 @@ def kb_prompt(kbinfos, max_tokens):
|
||||
return knowledges
|
||||
|
||||
|
||||
def citation_prompt():
|
||||
print("USE PROMPT", flush=True)
|
||||
return """
|
||||
CITATION_PROMPT_TEMPLATE = load_prompt("citation_prompt")
|
||||
CONTENT_TAGGING_PROMPT_TEMPLATE = load_prompt("content_tagging_prompt")
|
||||
CROSS_LANGUAGES_SYS_PROMPT_TEMPLATE = load_prompt("cross_languages_sys_prompt")
|
||||
CROSS_LANGUAGES_USER_PROMPT_TEMPLATE = load_prompt("cross_languages_user_prompt")
|
||||
FULL_QUESTION_PROMPT_TEMPLATE = load_prompt("full_question_prompt")
|
||||
KEYWORD_PROMPT_TEMPLATE = load_prompt("keyword_prompt")
|
||||
QUESTION_PROMPT_TEMPLATE = load_prompt("question_prompt")
|
||||
VISION_LLM_DESCRIBE_PROMPT = load_prompt("vision_llm_describe_prompt")
|
||||
VISION_LLM_FIGURE_DESCRIBE_PROMPT = load_prompt("vision_llm_figure_describe_prompt")
|
||||
|
||||
# Citation requirements:
|
||||
PROMPT_JINJA_ENV = jinja2.Environment(autoescape=False, trim_blocks=True, lstrip_blocks=True)
|
||||
|
||||
- Use a uniform citation format such as [ID:i] [ID:j], where "i" and "j" are document IDs enclosed in square brackets. Separate multiple IDs with spaces (e.g., [ID:0] [ID:1]).
|
||||
- Citation markers must be placed at the end of a sentence, separated by a space from the final punctuation (e.g., period, question mark). A maximum of 4 citations are allowed per sentence.
|
||||
- DO NOT insert CITATION in the answer if the content is not from retrieved chunks.
|
||||
- DO NOT use standalone Document IDs (e.g., '#ID#').
|
||||
- Citations ALWAYS in the "[ID:i]" format.
|
||||
- STRICTLY prohibit the use of strikethrough symbols (e.g., ~~) or any other non-standard formatting syntax.
|
||||
- Any failure to adhere to the above rules, including but not limited to incorrect formatting, use of prohibited styles, or unsupported citations, will be considered an error, and no citation will be added for that sentence.
|
||||
|
||||
--- Example START ---
|
||||
<SYSTEM>: Here is the knowledge base:
|
||||
|
||||
Document: Elon Musk Breaks Silence on Crypto, Warns Against Dogecoin ...
|
||||
URL: https://blockworks.co/news/elon-musk-crypto-dogecoin
|
||||
ID: 0
|
||||
The Tesla co-founder advised against going all-in on dogecoin, but Elon Musk said it’s still his favorite crypto...
|
||||
|
||||
Document: Elon Musk's Dogecoin tweet sparks social media frenzy
|
||||
ID: 1
|
||||
Musk said he is 'willing to serve' D.O.G.E. – shorthand for Dogecoin.
|
||||
|
||||
Document: Causal effect of Elon Musk tweets on Dogecoin price
|
||||
ID: 2
|
||||
If you think of Dogecoin — the cryptocurrency based on a meme — you can’t help but also think of Elon Musk...
|
||||
|
||||
Document: Elon Musk's Tweet Ignites Dogecoin's Future In Public Services
|
||||
ID: 3
|
||||
The market is heating up after Elon Musk's announcement about Dogecoin. Is this a new era for crypto?...
|
||||
|
||||
The above is the knowledge base.
|
||||
|
||||
<USER>: What's the Elon's view on dogecoin?
|
||||
|
||||
<ASSISTANT>: Musk has consistently expressed his fondness for Dogecoin, often citing its humor and the inclusion of dogs in its branding. He has referred to it as his favorite cryptocurrency [ID:0] [ID:1].
|
||||
Recently, Musk has hinted at potential future roles for Dogecoin. His tweets have sparked speculation about Dogecoin's potential integration into public services [ID:3].
|
||||
Overall, while Musk enjoys Dogecoin and often promotes it, he also warns against over-investing in it, reflecting both his personal amusement and caution regarding its speculative nature.
|
||||
|
||||
--- Example END ---
|
||||
|
||||
"""
|
||||
def citation_prompt() -> str:
|
||||
template = PROMPT_JINJA_ENV.from_string(CITATION_PROMPT_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
|
||||
def keyword_extraction(chat_mdl, content, topn=3):
|
||||
prompt = f"""
|
||||
Role: You are a text analyzer.
|
||||
Task: Extract the most important keywords/phrases of a given piece of text content.
|
||||
Requirements:
|
||||
- Summarize the text content, and give the top {topn} important keywords/phrases.
|
||||
- The keywords MUST be in the same language as the given piece of text content.
|
||||
- The keywords are delimited by ENGLISH COMMA.
|
||||
- Output keywords ONLY.
|
||||
template = PROMPT_JINJA_ENV.from_string(KEYWORD_PROMPT_TEMPLATE)
|
||||
rendered_prompt = template.render(content=content, topn=topn)
|
||||
|
||||
### Text Content
|
||||
{content}
|
||||
|
||||
"""
|
||||
msg = [{"role": "system", "content": prompt}, {"role": "user", "content": "Output: "}]
|
||||
msg = [{"role": "system", "content": rendered_prompt}, {"role": "user", "content": "Output: "}]
|
||||
_, msg = message_fit_in(msg, chat_mdl.max_length)
|
||||
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.2})
|
||||
kwd = chat_mdl.chat(rendered_prompt, msg[1:], {"temperature": 0.2})
|
||||
if isinstance(kwd, tuple):
|
||||
kwd = kwd[0]
|
||||
kwd = re.sub(r"^.*</think>", "", kwd, flags=re.DOTALL)
|
||||
@ -208,24 +170,12 @@ Requirements:
|
||||
|
||||
|
||||
def question_proposal(chat_mdl, content, topn=3):
|
||||
prompt = f"""
|
||||
Role: You are a text analyzer.
|
||||
Task: Propose {topn} questions about a given piece of text content.
|
||||
Requirements:
|
||||
- Understand and summarize the text content, and propose the top {topn} important questions.
|
||||
- The questions SHOULD NOT have overlapping meanings.
|
||||
- The questions SHOULD cover the main content of the text as much as possible.
|
||||
- The questions MUST be in the same language as the given piece of text content.
|
||||
- One question per line.
|
||||
- Output questions ONLY.
|
||||
template = PROMPT_JINJA_ENV.from_string(QUESTION_PROMPT_TEMPLATE)
|
||||
rendered_prompt = template.render(content=content, topn=topn)
|
||||
|
||||
### Text Content
|
||||
{content}
|
||||
|
||||
"""
|
||||
msg = [{"role": "system", "content": prompt}, {"role": "user", "content": "Output: "}]
|
||||
msg = [{"role": "system", "content": rendered_prompt}, {"role": "user", "content": "Output: "}]
|
||||
_, msg = message_fit_in(msg, chat_mdl.max_length)
|
||||
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.2})
|
||||
kwd = chat_mdl.chat(rendered_prompt, msg[1:], {"temperature": 0.2})
|
||||
if isinstance(kwd, tuple):
|
||||
kwd = kwd[0]
|
||||
kwd = re.sub(r"^.*</think>", "", kwd, flags=re.DOTALL)
|
||||
@ -235,6 +185,7 @@ Requirements:
|
||||
|
||||
|
||||
def full_question(tenant_id, llm_id, messages, language=None):
|
||||
from api.db import LLMType
|
||||
from api.db.services.llm_service import LLMBundle
|
||||
|
||||
if llm_id2llm_type(llm_id) == "image2text":
|
||||
@ -246,73 +197,27 @@ def full_question(tenant_id, llm_id, messages, language=None):
|
||||
if m["role"] not in ["user", "assistant"]:
|
||||
continue
|
||||
conv.append("{}: {}".format(m["role"].upper(), m["content"]))
|
||||
conv = "\n".join(conv)
|
||||
conversation = "\n".join(conv)
|
||||
today = datetime.date.today().isoformat()
|
||||
yesterday = (datetime.date.today() - datetime.timedelta(days=1)).isoformat()
|
||||
tomorrow = (datetime.date.today() + datetime.timedelta(days=1)).isoformat()
|
||||
prompt = f"""
|
||||
Role: A helpful assistant
|
||||
|
||||
Task and steps:
|
||||
1. Generate a full user question that would follow the conversation.
|
||||
2. If the user's question involves relative date, you need to convert it into absolute date based on the current date, which is {today}. For example: 'yesterday' would be converted to {yesterday}.
|
||||
template = PROMPT_JINJA_ENV.from_string(FULL_QUESTION_PROMPT_TEMPLATE)
|
||||
rendered_prompt = template.render(
|
||||
today=today,
|
||||
yesterday=yesterday,
|
||||
tomorrow=tomorrow,
|
||||
conversation=conversation,
|
||||
language=language,
|
||||
)
|
||||
|
||||
Requirements & Restrictions:
|
||||
- If the user's latest question is already complete, don't do anything, just return the original question.
|
||||
- DON'T generate anything except a refined question."""
|
||||
if language:
|
||||
prompt += f"""
|
||||
- Text generated MUST be in {language}."""
|
||||
else:
|
||||
prompt += """
|
||||
- Text generated MUST be in the same language as the original user's question.
|
||||
"""
|
||||
prompt += f"""
|
||||
|
||||
######################
|
||||
-Examples-
|
||||
######################
|
||||
|
||||
# Example 1
|
||||
## Conversation
|
||||
USER: What is the name of Donald Trump's father?
|
||||
ASSISTANT: Fred Trump.
|
||||
USER: And his mother?
|
||||
###############
|
||||
Output: What's the name of Donald Trump's mother?
|
||||
|
||||
------------
|
||||
# Example 2
|
||||
## Conversation
|
||||
USER: What is the name of Donald Trump's father?
|
||||
ASSISTANT: Fred Trump.
|
||||
USER: And his mother?
|
||||
ASSISTANT: Mary Trump.
|
||||
User: What's her full name?
|
||||
###############
|
||||
Output: What's the full name of Donald Trump's mother Mary Trump?
|
||||
|
||||
------------
|
||||
# Example 3
|
||||
## Conversation
|
||||
USER: What's the weather today in London?
|
||||
ASSISTANT: Cloudy.
|
||||
USER: What's about tomorrow in Rochester?
|
||||
###############
|
||||
Output: What's the weather in Rochester on {tomorrow}?
|
||||
|
||||
######################
|
||||
# Real Data
|
||||
## Conversation
|
||||
{conv}
|
||||
###############
|
||||
"""
|
||||
ans = chat_mdl.chat(prompt, [{"role": "user", "content": "Output: "}], {"temperature": 0.2})
|
||||
ans = chat_mdl.chat(rendered_prompt, [{"role": "user", "content": "Output: "}], {"temperature": 0.2})
|
||||
ans = re.sub(r"^.*</think>", "", ans, flags=re.DOTALL)
|
||||
return ans if ans.find("**ERROR**") < 0 else messages[-1]["content"]
|
||||
|
||||
|
||||
def cross_languages(tenant_id, llm_id, query, languages=[]):
|
||||
from api.db import LLMType
|
||||
from api.db.services.llm_service import LLMBundle
|
||||
|
||||
if llm_id and llm_id2llm_type(llm_id) == "image2text":
|
||||
@ -320,47 +225,10 @@ def cross_languages(tenant_id, llm_id, query, languages=[]):
|
||||
else:
|
||||
chat_mdl = LLMBundle(tenant_id, LLMType.CHAT, llm_id)
|
||||
|
||||
sys_prompt = """
|
||||
Act as a streamlined multilingual translator. Strictly output translations separated by ### without any explanations or formatting. Follow these rules:
|
||||
rendered_sys_prompt = PROMPT_JINJA_ENV.from_string(CROSS_LANGUAGES_SYS_PROMPT_TEMPLATE).render()
|
||||
rendered_user_prompt = PROMPT_JINJA_ENV.from_string(CROSS_LANGUAGES_USER_PROMPT_TEMPLATE).render(query=query, languages=languages)
|
||||
|
||||
1. Accept batch translation requests in format:
|
||||
[source text]
|
||||
===
|
||||
[target languages separated by commas]
|
||||
|
||||
2. Always maintain:
|
||||
- Original formatting (tables/lists/spacing)
|
||||
- Technical terminology accuracy
|
||||
- Cultural context appropriateness
|
||||
|
||||
3. Output format:
|
||||
[language1 translation]
|
||||
###
|
||||
[language1 translation]
|
||||
|
||||
**Examples:**
|
||||
Input:
|
||||
Hello World! Let's discuss AI safety.
|
||||
===
|
||||
Chinese, French, Japanese
|
||||
|
||||
Output:
|
||||
你好世界!让我们讨论人工智能安全问题。
|
||||
###
|
||||
Bonjour le monde ! Parlons de la sécurité de l'IA.
|
||||
###
|
||||
こんにちは世界!AIの安全性について話し合いましょう。
|
||||
"""
|
||||
user_prompt = f"""
|
||||
Input:
|
||||
{query}
|
||||
===
|
||||
{", ".join(languages)}
|
||||
|
||||
Output:
|
||||
"""
|
||||
|
||||
ans = chat_mdl.chat(sys_prompt, [{"role": "user", "content": user_prompt}], {"temperature": 0.2})
|
||||
ans = chat_mdl.chat(rendered_sys_prompt, [{"role": "user", "content": rendered_user_prompt}], {"temperature": 0.2})
|
||||
ans = re.sub(r"^.*</think>", "", ans, flags=re.DOTALL)
|
||||
if ans.find("**ERROR**") >= 0:
|
||||
return query
|
||||
@ -368,46 +236,21 @@ Output:
|
||||
|
||||
|
||||
def content_tagging(chat_mdl, content, all_tags, examples, topn=3):
|
||||
prompt = f"""
|
||||
Role: You are a text analyzer.
|
||||
template = PROMPT_JINJA_ENV.from_string(CONTENT_TAGGING_PROMPT_TEMPLATE)
|
||||
|
||||
Task: Add tags (labels) to a given piece of text content based on the examples and the entire tag set.
|
||||
for ex in examples:
|
||||
ex["tags_json"] = json.dumps(ex[TAG_FLD], indent=2, ensure_ascii=False)
|
||||
|
||||
Steps:
|
||||
- Review the tag/label set.
|
||||
- Review examples which all consist of both text content and assigned tags with relevance score in JSON format.
|
||||
- Summarize the text content, and tag it with the top {topn} most relevant tags from the set of tags/labels and the corresponding relevance score.
|
||||
rendered_prompt = template.render(
|
||||
topn=topn,
|
||||
all_tags=all_tags,
|
||||
examples=examples,
|
||||
content=content,
|
||||
)
|
||||
|
||||
Requirements:
|
||||
- The tags MUST be from the tag set.
|
||||
- The output MUST be in JSON format only, the key is tag and the value is its relevance score.
|
||||
- The relevance score must range from 1 to 10.
|
||||
- Output keywords ONLY.
|
||||
|
||||
# TAG SET
|
||||
{", ".join(all_tags)}
|
||||
|
||||
"""
|
||||
for i, ex in enumerate(examples):
|
||||
prompt += """
|
||||
# Examples {}
|
||||
### Text Content
|
||||
{}
|
||||
|
||||
Output:
|
||||
{}
|
||||
|
||||
""".format(i, ex["content"], json.dumps(ex[TAG_FLD], indent=2, ensure_ascii=False))
|
||||
|
||||
prompt += f"""
|
||||
# Real Data
|
||||
### Text Content
|
||||
{content}
|
||||
|
||||
"""
|
||||
msg = [{"role": "system", "content": prompt}, {"role": "user", "content": "Output: "}]
|
||||
msg = [{"role": "system", "content": rendered_prompt}, {"role": "user", "content": "Output: "}]
|
||||
_, msg = message_fit_in(msg, chat_mdl.max_length)
|
||||
kwd = chat_mdl.chat(prompt, msg[1:], {"temperature": 0.5})
|
||||
kwd = chat_mdl.chat(rendered_prompt, msg[1:], {"temperature": 0.5})
|
||||
if isinstance(kwd, tuple):
|
||||
kwd = kwd[0]
|
||||
kwd = re.sub(r"^.*</think>", "", kwd, flags=re.DOTALL)
|
||||
@ -418,7 +261,7 @@ Output:
|
||||
obj = json_repair.loads(kwd)
|
||||
except json_repair.JSONDecodeError:
|
||||
try:
|
||||
result = kwd.replace(prompt[:-1], "").replace("user", "").replace("model", "").strip()
|
||||
result = kwd.replace(rendered_prompt[:-1], "").replace("user", "").replace("model", "").strip()
|
||||
result = "{" + result.split("{")[1].split("}")[0] + "}"
|
||||
obj = json_repair.loads(result)
|
||||
except Exception as e:
|
||||
@ -435,54 +278,23 @@ Output:
|
||||
|
||||
|
||||
def vision_llm_describe_prompt(page=None) -> str:
|
||||
prompt_en = """
|
||||
INSTRUCTION:
|
||||
Transcribe the content from the provided PDF page image into clean Markdown format.
|
||||
- Only output the content transcribed from the image.
|
||||
- Do NOT output this instruction or any other explanation.
|
||||
- If the content is missing or you do not understand the input, return an empty string.
|
||||
template = PROMPT_JINJA_ENV.from_string(VISION_LLM_DESCRIBE_PROMPT)
|
||||
|
||||
RULES:
|
||||
1. Do NOT generate examples, demonstrations, or templates.
|
||||
2. Do NOT output any extra text such as 'Example', 'Example Output', or similar.
|
||||
3. Do NOT generate any tables, headings, or content that is not explicitly present in the image.
|
||||
4. Transcribe content word-for-word. Do NOT modify, translate, or omit any content.
|
||||
5. Do NOT explain Markdown or mention that you are using Markdown.
|
||||
6. Do NOT wrap the output in ```markdown or ``` blocks.
|
||||
7. Only apply Markdown structure to headings, paragraphs, lists, and tables, strictly based on the layout of the image. Do NOT create tables unless an actual table exists in the image.
|
||||
8. Preserve the original language, information, and order exactly as shown in the image.
|
||||
"""
|
||||
|
||||
if page is not None:
|
||||
prompt_en += f"\nAt the end of the transcription, add the page divider: `--- Page {page} ---`."
|
||||
|
||||
prompt_en += """
|
||||
FAILURE HANDLING:
|
||||
- If you do not detect valid content in the image, return an empty string.
|
||||
"""
|
||||
return prompt_en
|
||||
return template.render(page=page)
|
||||
|
||||
|
||||
def vision_llm_figure_describe_prompt() -> str:
|
||||
prompt = """
|
||||
You are an expert visual data analyst. Analyze the image and provide a comprehensive description of its content. Focus on identifying the type of visual data representation (e.g., bar chart, pie chart, line graph, table, flowchart), its structure, and any text captions or labels included in the image.
|
||||
template = PROMPT_JINJA_ENV.from_string(VISION_LLM_FIGURE_DESCRIBE_PROMPT)
|
||||
return template.render()
|
||||
|
||||
Tasks:
|
||||
1. Describe the overall structure of the visual representation. Specify if it is a chart, graph, table, or diagram.
|
||||
2. Identify and extract any axes, legends, titles, or labels present in the image. Provide the exact text where available.
|
||||
3. Extract the data points from the visual elements (e.g., bar heights, line graph coordinates, pie chart segments, table rows and columns).
|
||||
4. Analyze and explain any trends, comparisons, or patterns shown in the data.
|
||||
5. Capture any annotations, captions, or footnotes, and explain their relevance to the image.
|
||||
6. Only include details that are explicitly present in the image. If an element (e.g., axis, legend, or caption) does not exist or is not visible, do not mention it.
|
||||
|
||||
Output format (include only sections relevant to the image content):
|
||||
- Visual Type: [Type]
|
||||
- Title: [Title text, if available]
|
||||
- Axes / Legends / Labels: [Details, if available]
|
||||
- Data Points: [Extracted data]
|
||||
- Trends / Insights: [Analysis and interpretation]
|
||||
- Captions / Annotations: [Text and relevance, if available]
|
||||
|
||||
Ensure high accuracy, clarity, and completeness in your analysis, and include only the information present in the image. Avoid unnecessary statements about missing elements.
|
||||
"""
|
||||
return prompt
|
||||
if __name__ == "__main__":
|
||||
print(CITATION_PROMPT_TEMPLATE)
|
||||
print(CONTENT_TAGGING_PROMPT_TEMPLATE)
|
||||
print(CROSS_LANGUAGES_SYS_PROMPT_TEMPLATE)
|
||||
print(CROSS_LANGUAGES_USER_PROMPT_TEMPLATE)
|
||||
print(FULL_QUESTION_PROMPT_TEMPLATE)
|
||||
print(KEYWORD_PROMPT_TEMPLATE)
|
||||
print(QUESTION_PROMPT_TEMPLATE)
|
||||
print(VISION_LLM_DESCRIBE_PROMPT)
|
||||
print(VISION_LLM_FIGURE_DESCRIBE_PROMPT)
|
||||
|
||||
46
rag/prompts/citation_prompt.md
Normal file
46
rag/prompts/citation_prompt.md
Normal file
@ -0,0 +1,46 @@
|
||||
## Citation Requirements
|
||||
|
||||
- Use a uniform citation format such as [ID:i] [ID:j], where "i" and "j" are document IDs enclosed in square brackets. Separate multiple IDs with spaces (e.g., [ID:0] [ID:1]).
|
||||
- Citation markers must be placed at the end of a sentence, separated by a space from the final punctuation (e.g., period, question mark).
|
||||
- A maximum of 4 citations are allowed per sentence.
|
||||
- DO NOT insert citations if the content is not from retrieved chunks.
|
||||
- DO NOT use standalone Document IDs (e.g., #ID#).
|
||||
- Citations MUST always follow the [ID:i] format.
|
||||
- STRICTLY prohibit the use of strikethrough symbols (e.g., ~~) or any other non-standard formatting syntax.
|
||||
- Any violation of the above rules — including incorrect formatting, prohibited styles, or unsupported citations — will result in no citation being added for that sentence.
|
||||
|
||||
---
|
||||
|
||||
## Example START
|
||||
|
||||
<SYSTEM>: Here is the knowledge base:
|
||||
|
||||
Document: Elon Musk Breaks Silence on Crypto, Warns Against Dogecoin ...
|
||||
URL: https://blockworks.co/news/elon-musk-crypto-dogecoin
|
||||
ID: 0
|
||||
The Tesla co-founder advised against going all-in on dogecoin, but Elon Musk said it’s still his favorite crypto...
|
||||
|
||||
Document: Elon Musk's Dogecoin tweet sparks social media frenzy
|
||||
ID: 1
|
||||
Musk said he is 'willing to serve' D.O.G.E. – shorthand for Dogecoin.
|
||||
|
||||
Document: Causal effect of Elon Musk tweets on Dogecoin price
|
||||
ID: 2
|
||||
If you think of Dogecoin — the cryptocurrency based on a meme — you can’t help but also think of Elon Musk...
|
||||
|
||||
Document: Elon Musk's Tweet Ignites Dogecoin's Future In Public Services
|
||||
ID: 3
|
||||
The market is heating up after Elon Musk's announcement about Dogecoin. Is this a new era for crypto?...
|
||||
|
||||
The above is the knowledge base.
|
||||
|
||||
<USER>: What's Elon's view on dogecoin?
|
||||
|
||||
<ASSISTANT>:
|
||||
Musk has consistently expressed his fondness for Dogecoin, often citing its humor and the inclusion of dogs in its branding. He has referred to it as his favorite cryptocurrency [ID:0] [ID:1].
|
||||
|
||||
Recently, Musk has hinted at potential future roles for Dogecoin. His tweets have sparked speculation about Dogecoin's potential integration into public services [ID:3].
|
||||
|
||||
Overall, while Musk enjoys Dogecoin and often promotes it, he also warns against over-investing in it, reflecting both his personal amusement and caution regarding its speculative nature.
|
||||
|
||||
## Example END
|
||||
32
rag/prompts/content_tagging_prompt.md
Normal file
32
rag/prompts/content_tagging_prompt.md
Normal file
@ -0,0 +1,32 @@
|
||||
## Role
|
||||
You are a text analyzer.
|
||||
|
||||
## Task
|
||||
Add tags (labels) to a given piece of text content based on the examples and the entire tag set.
|
||||
|
||||
## Steps
|
||||
- Review the tag/label set.
|
||||
- Review examples which all consist of both text content and assigned tags with relevance score in JSON format.
|
||||
- Summarize the text content, and tag it with the top {{ topn }} most relevant tags from the set of tags/labels and the corresponding relevance score.
|
||||
|
||||
## Requirements
|
||||
- The tags MUST be from the tag set.
|
||||
- The output MUST be in JSON format only, the key is tag and the value is its relevance score.
|
||||
- The relevance score must range from 1 to 10.
|
||||
- Output keywords ONLY.
|
||||
|
||||
# TAG SET
|
||||
{{ all_tags | join(', ') }}
|
||||
|
||||
{% for ex in examples %}
|
||||
# Examples {{ loop.index0 }}
|
||||
### Text Content
|
||||
{{ ex.content }}
|
||||
|
||||
Output:
|
||||
{{ ex.tags_json }}
|
||||
|
||||
{% endfor %}
|
||||
# Real Data
|
||||
### Text Content
|
||||
{{ content }}
|
||||
35
rag/prompts/cross_languages_sys_prompt.md
Normal file
35
rag/prompts/cross_languages_sys_prompt.md
Normal file
@ -0,0 +1,35 @@
|
||||
## Role
|
||||
A streamlined multilingual translator.
|
||||
|
||||
## Behavior Rules
|
||||
1. Accept batch translation requests in the following format:
|
||||
**Input:** `[text]`
|
||||
**Target Languages:** comma-separated list
|
||||
|
||||
2. Maintain:
|
||||
- Original formatting (tables, lists, spacing)
|
||||
- Technical terminology accuracy
|
||||
- Cultural context appropriateness
|
||||
|
||||
3. Output translations in the following format:
|
||||
|
||||
[Translation in language1]
|
||||
###
|
||||
[Translation in language2]
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
|
||||
**Input:**
|
||||
Hello World! Let's discuss AI safety.
|
||||
===
|
||||
Chinese, French, Japanese
|
||||
|
||||
**Output:**
|
||||
你好世界!让我们讨论人工智能安全问题。
|
||||
###
|
||||
Bonjour le monde ! Parlons de la sécurité de l'IA.
|
||||
###
|
||||
こんにちは世界!AIの安全性について話し合いましょう。
|
||||
|
||||
7
rag/prompts/cross_languages_user_prompt.md
Normal file
7
rag/prompts/cross_languages_user_prompt.md
Normal file
@ -0,0 +1,7 @@
|
||||
**Input:**
|
||||
{{ query }}
|
||||
===
|
||||
{{ languages | join(', ') }}
|
||||
|
||||
**Output:**
|
||||
|
||||
62
rag/prompts/full_question_prompt.md
Normal file
62
rag/prompts/full_question_prompt.md
Normal file
@ -0,0 +1,62 @@
|
||||
## Role
|
||||
A helpful assistant.
|
||||
|
||||
## Task & Steps
|
||||
1. Generate a full user question that would follow the conversation.
|
||||
2. If the user's question involves relative dates, convert them into absolute dates based on today ({{ today }}).
|
||||
- "yesterday" = {{ yesterday }}, "tomorrow" = {{ tomorrow }}
|
||||
|
||||
## Requirements & Restrictions
|
||||
- If the user's latest question is already complete, don't do anything — just return the original question.
|
||||
- DON'T generate anything except a refined question.
|
||||
{% if language %}
|
||||
- Text generated MUST be in {{ language }}.
|
||||
{% else %}
|
||||
- Text generated MUST be in the same language as the original user's question.
|
||||
{% endif %}
|
||||
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1
|
||||
**Conversation:**
|
||||
|
||||
USER: What is the name of Donald Trump's father?
|
||||
ASSISTANT: Fred Trump.
|
||||
USER: And his mother?
|
||||
|
||||
**Output:** What's the name of Donald Trump's mother?
|
||||
|
||||
---
|
||||
|
||||
### Example 2
|
||||
**Conversation:**
|
||||
|
||||
USER: What is the name of Donald Trump's father?
|
||||
ASSISTANT: Fred Trump.
|
||||
USER: And his mother?
|
||||
ASSISTANT: Mary Trump.
|
||||
USER: What's her full name?
|
||||
|
||||
**Output:** What's the full name of Donald Trump's mother Mary Trump?
|
||||
|
||||
---
|
||||
|
||||
### Example 3
|
||||
**Conversation:**
|
||||
|
||||
USER: What's the weather today in London?
|
||||
ASSISTANT: Cloudy.
|
||||
USER: What's about tomorrow in Rochester?
|
||||
|
||||
**Output:** What's the weather in Rochester on {{ tomorrow }}?
|
||||
|
||||
---
|
||||
|
||||
## Real Data
|
||||
|
||||
**Conversation:**
|
||||
|
||||
{{ conversation }}
|
||||
|
||||
16
rag/prompts/keyword_prompt.md
Normal file
16
rag/prompts/keyword_prompt.md
Normal file
@ -0,0 +1,16 @@
|
||||
## Role
|
||||
You are a text analyzer.
|
||||
|
||||
## Task
|
||||
Extract the most important keywords/phrases of a given piece of text content.
|
||||
|
||||
## Requirements
|
||||
- Summarize the text content, and give the top {{ topn }} important keywords/phrases.
|
||||
- The keywords MUST be in the same language as the given piece of text content.
|
||||
- The keywords are delimited by ENGLISH COMMA.
|
||||
- Output keywords ONLY.
|
||||
|
||||
---
|
||||
|
||||
## Text Content
|
||||
{{ content }}
|
||||
19
rag/prompts/question_prompt.md
Normal file
19
rag/prompts/question_prompt.md
Normal file
@ -0,0 +1,19 @@
|
||||
## Role
|
||||
You are a text analyzer.
|
||||
|
||||
## Task
|
||||
Propose {{ topn }} questions about a given piece of text content.
|
||||
|
||||
## Requirements
|
||||
- Understand and summarize the text content, and propose the top {{ topn }} important questions.
|
||||
- The questions SHOULD NOT have overlapping meanings.
|
||||
- The questions SHOULD cover the main content of the text as much as possible.
|
||||
- The questions MUST be in the same language as the given piece of text content.
|
||||
- One question per line.
|
||||
- Output questions ONLY.
|
||||
|
||||
---
|
||||
|
||||
## Text Content
|
||||
{{ content }}
|
||||
|
||||
23
rag/prompts/vision_llm_describe_prompt.md
Normal file
23
rag/prompts/vision_llm_describe_prompt.md
Normal file
@ -0,0 +1,23 @@
|
||||
## INSTRUCTION
|
||||
Transcribe the content from the provided PDF page image into clean Markdown format.
|
||||
|
||||
- Only output the content transcribed from the image.
|
||||
- Do NOT output this instruction or any other explanation.
|
||||
- If the content is missing or you do not understand the input, return an empty string.
|
||||
|
||||
## RULES
|
||||
1. Do NOT generate examples, demonstrations, or templates.
|
||||
2. Do NOT output any extra text such as 'Example', 'Example Output', or similar.
|
||||
3. Do NOT generate any tables, headings, or content that is not explicitly present in the image.
|
||||
4. Transcribe content word-for-word. Do NOT modify, translate, or omit any content.
|
||||
5. Do NOT explain Markdown or mention that you are using Markdown.
|
||||
6. Do NOT wrap the output in ```markdown or ``` blocks.
|
||||
7. Only apply Markdown structure to headings, paragraphs, lists, and tables, strictly based on the layout of the image. Do NOT create tables unless an actual table exists in the image.
|
||||
8. Preserve the original language, information, and order exactly as shown in the image.
|
||||
|
||||
{% if page %}
|
||||
At the end of the transcription, add the page divider: `--- Page {{ page }} ---`.
|
||||
{% endif %}
|
||||
|
||||
> If you do not detect valid content in the image, return an empty string.
|
||||
|
||||
24
rag/prompts/vision_llm_figure_describe_prompt.md
Normal file
24
rag/prompts/vision_llm_figure_describe_prompt.md
Normal file
@ -0,0 +1,24 @@
|
||||
## ROLE
|
||||
You are an expert visual data analyst.
|
||||
|
||||
## GOAL
|
||||
Analyze the image and provide a comprehensive description of its content. Focus on identifying the type of visual data representation (e.g., bar chart, pie chart, line graph, table, flowchart), its structure, and any text captions or labels included in the image.
|
||||
|
||||
## TASKS
|
||||
1. Describe the overall structure of the visual representation. Specify if it is a chart, graph, table, or diagram.
|
||||
2. Identify and extract any axes, legends, titles, or labels present in the image. Provide the exact text where available.
|
||||
3. Extract the data points from the visual elements (e.g., bar heights, line graph coordinates, pie chart segments, table rows and columns).
|
||||
4. Analyze and explain any trends, comparisons, or patterns shown in the data.
|
||||
5. Capture any annotations, captions, or footnotes, and explain their relevance to the image.
|
||||
6. Only include details that are explicitly present in the image. If an element (e.g., axis, legend, or caption) does not exist or is not visible, do not mention it.
|
||||
|
||||
## OUTPUT FORMAT (Include only sections relevant to the image content)
|
||||
- Visual Type: [Type]
|
||||
- Title: [Title text, if available]
|
||||
- Axes / Legends / Labels: [Details, if available]
|
||||
- Data Points: [Extracted data]
|
||||
- Trends / Insights: [Analysis and interpretation]
|
||||
- Captions / Annotations: [Text and relevance, if available]
|
||||
|
||||
> Ensure high accuracy, clarity, and completeness in your analysis, and include only the information present in the image. Avoid unnecessary statements about missing elements.
|
||||
|
||||
Reference in New Issue
Block a user