mirror of https://github.com/langgenius/dify.git
question classifier
This commit is contained in:
parent
f803fb5855
commit
a0b16e541c
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -46,5 +46,5 @@ class QuestionClassifierNodeData(BaseNodeData):
|
|||
type: str = 'question-classifier'
|
||||
model: ModelConfig
|
||||
classes: list[ClassConfig]
|
||||
instruction: str
|
||||
memory: MemoryConfig
|
||||
instruction: Optional[str]
|
||||
memory: Optional[MemoryConfig]
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class QuestionClassifierNode(BaseNode):
|
|||
stop=stop
|
||||
)
|
||||
try:
|
||||
result_text_json = json.loads(result_text)
|
||||
result_text_json = json.loads(result_text.strip('```JSON\n'))
|
||||
categories = result_text_json.get('categories', [])
|
||||
process_data = {
|
||||
'model_mode': model_config.mode,
|
||||
|
|
|
|||
|
|
@ -1,43 +1,43 @@
|
|||
|
||||
|
||||
QUESTION_CLASSIFIER_SYSTEM_PROMPT = (
|
||||
'### Job Description',
|
||||
'You are a text classification engine that analyzes text data and assigns categories based on user input or automatically determined categories.',
|
||||
'### 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.',
|
||||
'### Format',
|
||||
'The input text is in the variable text_field.Categories are specified as a comma-separated list in the variable categories or left empty for automatic determination.Classification instructions may be included to improve the classification accuracy.',
|
||||
'### Constraint',
|
||||
'DO NOT include anything other than the JSON array in your response.'
|
||||
)
|
||||
QUESTION_CLASSIFIER_SYSTEM_PROMPT = """
|
||||
### Job Description',
|
||||
You are a text classification engine that analyzes text data and assigns categories based on user input or automatically determined categories.
|
||||
### 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.
|
||||
### Format
|
||||
The input text is in the variable text_field.Categories are specified as a comma-separated list in the variable categories or left empty for automatic determination.Classification instructions may be included to improve the classification accuracy.
|
||||
### Constraint
|
||||
DO NOT include anything other than the JSON array in your response.
|
||||
"""
|
||||
|
||||
QUESTION_CLASSIFIER_USER_PROMPT_1 = (
|
||||
'{ "input_text": ["I recently had a great experience with your company. The service was prompt and the staff was very friendly."],',
|
||||
'"categories": ["Customer Service, Satisfaction, Sales, Product"],',
|
||||
'"classification_instructions": ["classify the text based on the feedback provided by customer"]}```JSON'
|
||||
)
|
||||
QUESTION_CLASSIFIER_USER_PROMPT_1 = """
|
||||
{ "input_text": ["I recently had a great experience with your company. The service was prompt and the staff was very friendly."],
|
||||
"categories": ["Customer Service, Satisfaction, Sales, Product"],
|
||||
"classification_instructions": ["classify the text based on the feedback provided by customer"]}```JSON
|
||||
"""
|
||||
|
||||
QUESTION_CLASSIFIER_ASSISTANT_PROMPT_1 = (
|
||||
'{"keywords": ["recently", "great experience", "company", "service", "prompt", "staff", "friendly"],',
|
||||
'"categories": ["Customer Service"]}```'
|
||||
)
|
||||
QUESTION_CLASSIFIER_ASSISTANT_PROMPT_1 = """
|
||||
{"keywords": ["recently", "great experience", "company", "service", "prompt", "staff", "friendly"],
|
||||
"categories": ["Customer Service"]}```
|
||||
"""
|
||||
|
||||
QUESTION_CLASSIFIER_USER_PROMPT_2 = (
|
||||
'{"input_text": ["bad service, slow to bring the food"],',
|
||||
'"categories": ["Food Quality, Experience, Price" ], ',
|
||||
'"classification_instructions": []}```JSON'
|
||||
)
|
||||
QUESTION_CLASSIFIER_USER_PROMPT_2 = """
|
||||
{"input_text": ["bad service, slow to bring the food"],
|
||||
"categories": ["Food Quality, Experience, Price" ],
|
||||
"classification_instructions": []}```JSON
|
||||
"""
|
||||
|
||||
QUESTION_CLASSIFIER_ASSISTANT_PROMPT_2 = (
|
||||
'{"keywords": ["bad service", "slow", "food", "tip", "terrible", "waitresses"],',
|
||||
'"categories": ["Experience""]}```'
|
||||
)
|
||||
QUESTION_CLASSIFIER_ASSISTANT_PROMPT_2 = """
|
||||
{"keywords": ["bad service", "slow", "food", "tip", "terrible", "waitresses"],
|
||||
"categories": ["Experience""]}```
|
||||
"""
|
||||
|
||||
QUESTION_CLASSIFIER_USER_PROMPT_3 = (
|
||||
'{"input_text": ["{input_text}"],',
|
||||
QUESTION_CLASSIFIER_USER_PROMPT_3 = """
|
||||
'{{"input_text": ["{input_text}"],',
|
||||
'"categories": ["{categories}" ], ',
|
||||
'"classification_instructions": ["{classification_instructions}"]}```JSON'
|
||||
)
|
||||
'"classification_instructions": ["{classification_instructions}"]}}```JSON'
|
||||
"""
|
||||
|
||||
QUESTION_CLASSIFIER_COMPLETION_PROMPT = """
|
||||
### Job Description
|
||||
|
|
@ -58,5 +58,5 @@ Output:
|
|||
### Memory
|
||||
Here is the chat histories between human and assistant, inside <histories></histories> XML tags.
|
||||
### User Input
|
||||
{"input_text" : [{{input_text}}], "class" : [{{class}}],"classification_instruction" : [{{classification_instructions}}]}
|
||||
{{"input_text" : ["{input_text}"], "class" : ["{class}"],"classification_instruction" : ["{classification_instructions}"]}}
|
||||
"""
|
||||
Loading…
Reference in New Issue