question classifier prompt optimize (#4262)

This commit is contained in:
Jyong 2024-05-10 17:22:46 +08:00 committed by GitHub
parent 875249eb00
commit 897e07f639
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -259,7 +259,7 @@ class QuestionClassifierNode(LLMNode):
user_prompt_message_3 = ChatModelMessage( user_prompt_message_3 = ChatModelMessage(
role=PromptMessageRole.USER, role=PromptMessageRole.USER,
text=QUESTION_CLASSIFIER_USER_PROMPT_3.format(input_text=input_text, text=QUESTION_CLASSIFIER_USER_PROMPT_3.format(input_text=input_text,
categories=json.dumps(categories), categories=json.dumps(categories, ensure_ascii=False),
classification_instructions=instruction) classification_instructions=instruction)
) )
prompt_messages.append(user_prompt_message_3) prompt_messages.append(user_prompt_message_3)
@ -269,7 +269,7 @@ class QuestionClassifierNode(LLMNode):
text=QUESTION_CLASSIFIER_COMPLETION_PROMPT.format(histories=memory_str, text=QUESTION_CLASSIFIER_COMPLETION_PROMPT.format(histories=memory_str,
input_text=input_text, input_text=input_text,
categories=json.dumps(categories), categories=json.dumps(categories),
classification_instructions=instruction) classification_instructions=instruction, ensure_ascii=False)
) )
else: else:

View File

@ -6,7 +6,7 @@ QUESTION_CLASSIFIER_SYSTEM_PROMPT = """
### Task ### Task
Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output.Additionally, you need to extract the key words from the text that are related to the classification. Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output.Additionally, you need to extract the key words from the text that are related to the classification.
### Format ### Format
The input text is in the variable text_field.Categories are specified as a category list in the variable categories or left empty for automatic determination.Classification instructions may be included to improve the classification accuracy. The input text is in the variable text_field.Categories are specified as a category list with two filed category_id and category_name in the variable categories .Classification instructions may be included to improve the classification accuracy.
### Constraint ### Constraint
DO NOT include anything other than the JSON array in your response. DO NOT include anything other than the JSON array in your response.
### Memory ### Memory
@ -24,7 +24,8 @@ QUESTION_CLASSIFIER_USER_PROMPT_1 = """
QUESTION_CLASSIFIER_ASSISTANT_PROMPT_1 = """ QUESTION_CLASSIFIER_ASSISTANT_PROMPT_1 = """
```json ```json
{"category_id": "f5660049-284f-41a7-b301-fd24176a711c", {"keywords": ["recently", "great experience", "company", "service", "prompt", "staff", "friendly"],
"category_id": "f5660049-284f-41a7-b301-fd24176a711c",
"category_name": "Customer Service"} "category_name": "Customer Service"}
``` ```
""" """
@ -37,7 +38,8 @@ QUESTION_CLASSIFIER_USER_PROMPT_2 = """
QUESTION_CLASSIFIER_ASSISTANT_PROMPT_2 = """ QUESTION_CLASSIFIER_ASSISTANT_PROMPT_2 = """
```json ```json
{"category_id": "f6ff5bc3-aca0-4e4a-8627-e760d0aca78f", {"keywords": ["bad service", "slow", "food", "tip", "terrible", "waitresses"],
"category_id": "f6ff5bc3-aca0-4e4a-8627-e760d0aca78f",
"category_name": "Experience"} "category_name": "Experience"}
``` ```
""" """
@ -54,16 +56,16 @@ You are a text classification engine that analyzes text data and assigns categor
### Task ### Task
Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output. Additionally, you need to extract the key words from the text that are related to the classification. Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output. Additionally, you need to extract the key words from the text that are related to the classification.
### Format ### Format
The input text is in the variable text_field. Categories are specified as a category list in the variable categories or left empty for automatic determination. Classification instructions may be included to improve the classification accuracy. The input text is in the variable text_field. Categories are specified as a category list with two filed category_id and category_name in the variable categories. Classification instructions may be included to improve the classification accuracy.
### Constraint ### Constraint
DO NOT include anything other than the JSON array in your response. DO NOT include anything other than the JSON array in your response.
### Example ### Example
Here is the chat example between human and assistant, inside <example></example> XML tags. Here is the chat example between human and assistant, inside <example></example> XML tags.
<example> <example>
User:{{"input_text": ["I recently had a great experience with your company. The service was prompt and the staff was very friendly."], "categories": [{{"category_id":"f5660049-284f-41a7-b301-fd24176a711c","category_name":"Customer Service"}},{{"category_id":"8d007d06-f2c9-4be5-8ff6-cd4381c13c60","category_name":"Satisfaction"}},{{"category_id":"5fbbbb18-9843-466d-9b8e-b9bfbb9482c8","category_name":"Sales"}},{{"category_id":"23623c75-7184-4a2e-8226-466c2e4631e4","category_name":"Product"}}], "classification_instructions": ["classify the text based on the feedback provided by customer"]}} User:{{"input_text": ["I recently had a great experience with your company. The service was prompt and the staff was very friendly."], "categories": [{{"category_id":"f5660049-284f-41a7-b301-fd24176a711c","category_name":"Customer Service"}},{{"category_id":"8d007d06-f2c9-4be5-8ff6-cd4381c13c60","category_name":"Satisfaction"}},{{"category_id":"5fbbbb18-9843-466d-9b8e-b9bfbb9482c8","category_name":"Sales"}},{{"category_id":"23623c75-7184-4a2e-8226-466c2e4631e4","category_name":"Product"}}], "classification_instructions": ["classify the text based on the feedback provided by customer"]}}
Assistant:{{"category_id": "f5660049-284f-41a7-b301-fd24176a711c","category_name": "Customer Service"}} Assistant:{{"keywords": ["recently", "great experience", "company", "service", "prompt", "staff", "friendly"],"category_id": "f5660049-284f-41a7-b301-fd24176a711c","category_name": "Customer Service"}}
User:{{"input_text": ["bad service, slow to bring the food"], "categories": [{{"category_id":"80fb86a0-4454-4bf5-924c-f253fdd83c02","category_name":"Food Quality"}},{{"category_id":"f6ff5bc3-aca0-4e4a-8627-e760d0aca78f","category_name":"Experience"}},{{"category_id":"cc771f63-74e7-4c61-882e-3eda9d8ba5d7","category_name":"Price"}}], "classification_instructions": []}} User:{{"input_text": ["bad service, slow to bring the food"], "categories": [{{"category_id":"80fb86a0-4454-4bf5-924c-f253fdd83c02","category_name":"Food Quality"}},{{"category_id":"f6ff5bc3-aca0-4e4a-8627-e760d0aca78f","category_name":"Experience"}},{{"category_id":"cc771f63-74e7-4c61-882e-3eda9d8ba5d7","category_name":"Price"}}], "classification_instructions": []}}
Assistant:{{"category_id": "f6ff5bc3-aca0-4e4a-8627-e760d0aca78f","category_name": "Customer Service"}} Assistant:{{"keywords": ["bad service", "slow", "food", "tip", "terrible", "waitresses"],"category_id": "f6ff5bc3-aca0-4e4a-8627-e760d0aca78f","category_name": "Customer Service"}}
</example> </example>
### Memory ### Memory
Here is the chat histories between human and assistant, inside <histories></histories> XML tags. Here is the chat histories between human and assistant, inside <histories></histories> XML tags.