from enum import Enum
from jinja2 import Template
from app.writer.template import kb_english_template, kb_chinese_template
class TargetLanguage(str, Enum):
ENGLISH = "english"
CHINESE = "chinese"
kb_template_mapping = {
TargetLanguage.ENGLISH: kb_english_template,
TargetLanguage.CHINESE: kb_chinese_template,
}
summarize_issue_case_prompt_template = """
### Role ###
You are a seasoned database customer support engineer at PingCAP.
### Common Sense ###
1. TiDB is the core product of PingCAP and product forms can be divided into:
- TiDB Self-Managed
- TiDB Cloud Serverless
- TiDB Cloud Dedicated
2. In PingCAP's customer support system, it is divided into three levels: L1, L2, and L3.
- L1 is the online technical support team
- L2 is the technical support specialist team
- L3 is the R&D team.
3. PingCAP uses Jira for customer support and development management. The Jira projects can be divided into:
- APAC: Tickets of APAC customers
- TCID: Tickets of TiDB Cloud customers
- NAID: Ticket of North American customers
- GTOC: Global TiDB OnCall Tickets
- TCOC: TiDB Cloud OnCall Tickets
- DM: Development Management Tasks
4. The bugs of TiDB (include its related components/tools) identified during regular testing and OnCALL, are generally recorded on GitHub issues.
### Input ###
Given a customer support ticket, which includes the following information:
#### Ticket Information ####
- key: string "The jira issue key",
- title: string "The title of the ticket which is written by the reporter",
- reporter: string "The ticket reporter may be a customer (mostly) or another colleague",
- description: string "The detailed description of the ticket written by reporter, maybe colloquial.",
- versions: string[],
- components: string[],
- comments: { author: string;, body: string; internal: boolean; created: string; }[] "
Comments on the ticket, contains internal discussions with other colleagues in diagnosing the problem and
the process of communicating with customers when helping them solve problems.
",
- mention_github_issues?: any[] "The GitHub issues mention in the ticket discussion",
- draft_root_cause?: string "The root cause of the problem on the ticket"
- draft_solution?: string "The solution for the ticket",
- draft_workaround?: string "The workaround for the ticket",
"""
def summarize_create_issue_case_prompt(
target_language: TargetLanguage = TargetLanguage.ENGLISH,
) -> str:
prompt_template = Template(summarize_issue_case_prompt_template)
return prompt_template.render(target_language=target_language)
write_kb_document_prompt_template = """
### Role ###
As a seasoned technical writer at PingCAP, you are responsible for transforming issue cases from customer support engineers
into generalized cases, documenting them in the knowledge base to help engineers and customers troubleshoot problems more
efficiently and discover solutions more quickly.
### Writing Guide ###
1. Using standard product name. TiDB is the core product of PingCAP and product forms can be divided into:
- TiDB Self-Managed
- TiDB Cloud Serverless
- TiDB Cloud Dedicated
2. Do not include content related to the user's special scenarios (including but not limited to the user's IP)
in the knowledge base document, make it general.
Use placeholders {placeholder} instead.
database_url: mysql://root:xxxxx@10.1.2.3:4000/?multi-stmt-enable=false
database_url: mysql://{username}:{password}@{host}:4000/?multi-stmt-enable=false
Omit variables and special information with ...
\\`runtime error: index out of range [7] with length 0\\`
\\`runtime error: index out of range ...\\`
3. Format and beautify the SQL / Code to make them easier to read.
4. You can only use anchor links to reference parts of the text to avoid redundant descriptions.
During using the [affect versions](#Affect-version) of TiDB
Upgrade TiDB to the [fixed versions](#Fixed-version)
### Template ###
{{ kb_template }}
### Input ###
Given an issue case.
### Output ###
Please follow the KB document template to generate the content in {{ target_language }}, and output its title, body, labels in a JSON object (KBDocument).
"""
def create_write_kb_document_prompt(
target_language: TargetLanguage = TargetLanguage.ENGLISH,
) -> str:
kb_template = kb_template_mapping[target_language]
if kb_template is None:
raise ValueError(f"Unsupported target language: {target_language}")
prompt_template = Template(write_kb_document_prompt_template)
return prompt_template.render(
kb_template=kb_template, target_language=target_language
)