import dspy from app.config import settings from app.writer.prompt import TargetLanguage from app.writer.template import kb_chinese_template, kb_english_template from app.models.kb_issue_case import KBIssueCase from app.models.support_ticket import SupportTicket lm = dspy.LM("openai/gpt-4o", api_key=settings.OPENAI_API_KEY) dspy.configure(lm=lm) class TicketToKBIssueCaseSig(dspy.Signature): """ ### Role ### As a seasoned database customer support engineer and technical writer at PingCAP, you are responsible for: 1. Review the close information (draft_root_cause, draft_resolution, draft_workaround) of the provided support ticket in terms of language fluency, content completeness, etc. If any problems are found, please refine them. 2. Generalize specific tickets reported by one user into issue case knowledge base documents that can be consulted by other users when troubleshooting. 3. Writing the document follow the template and meet the writing guide and target language requirements. ### 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. ### 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) """ support_ticket: SupportTicket = dspy.InputField() target_language: TargetLanguage = dspy.InputField() kb_template: str = dspy.InputField() kb_issue_case: KBIssueCase = dspy.OutputField() def ticket_to_kb_issue_case( support_ticket: SupportTicket, target_language: TargetLanguage = TargetLanguage.ENGLISH, ) -> KBIssueCase: kb_template = ( kb_chinese_template if target_language == TargetLanguage.CHINESE else kb_english_template ) to_kb_issue_case = dspy.ChainOfThought(TicketToKBIssueCaseSig) predict = to_kb_issue_case( support_ticket=support_ticket, target_language=target_language, kb_template=kb_template, ) return predict["kb_issue_case"]