Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload with prompt action #1180

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kairon/importer/validator/file_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,10 +720,10 @@ def __validate_llm_prompts(llm_prompts: dict):
for key, value in hyperparameters.items():
if key == 'similarity_threshold':
if not (0.3 <= value <= 1.0) or not (
isinstance(key, float) or isinstance(key, int)):
isinstance(value, float) or isinstance(value, int)):
error_list.append(
f"similarity_threshold should be within 0.3 and 1.0 and of type int or float!")
if key == 'top_results' and (value > 30 or not isinstance(key, int)):
if key == 'top_results' and (value > 30 or not isinstance(value, int)):
error_list.append("top_results should not be greater than 30 and of type int!")

if prompt.get('type') == 'system':
Expand Down Expand Up @@ -754,7 +754,7 @@ def __validate_llm_prompts(llm_prompts: dict):
error_list.append('data field in prompts should of type string.')
if not prompt.get('data') and prompt.get('source') == 'static':
error_list.append('data is required for static prompts')
if Utility.check_empty_string(prompt.get('collection')) and prompt.get('source') == 'bot_content':
if prompt.get('source') == 'bot_content' and Utility.check_empty_string(prompt.get('data')):
error_list.append("Collection is required for bot content prompts!")
if system_prompt_count > 1:
error_list.append('Only one system prompt can be present')
Expand Down
2 changes: 1 addition & 1 deletion kairon/shared/actions/data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def validate(self, clean=True):
class LlmPrompt(EmbeddedDocument):
name = StringField(required=True)
hyperparameters = EmbeddedDocumentField(PromptHyperparameter)
data = StringField()
data = StringField(default="default")
instructions = StringField()
type = StringField(
required=True,
Expand Down
13 changes: 7 additions & 6 deletions tests/unit_test/action/action_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2650,10 +2650,11 @@ def test_get_prompt_action_config(self):
'hyperparameters': {'temperature': 0.0, 'max_tokens': 300, 'model': 'gpt-3.5-turbo',
'top_p': 0.0, 'n': 1, 'stream': False, 'stop': None,
'presence_penalty': 0.0, 'frequency_penalty': 0.0,
'logit_bias': {}}, 'llm_prompts': [
{'name': 'System Prompt', 'data': 'You are a personal assistant.', 'type': 'system', 'source': 'static',
'is_enabled': True},
{'name': 'History Prompt', 'type': 'user', 'source': 'history', 'is_enabled': True}],
'logit_bias': {}},
'llm_prompts': [{'name': 'System Prompt', 'data': 'You are a personal assistant.',
'type': 'system', 'source': 'static', 'is_enabled': True},
{'name': 'History Prompt', 'type': 'user', 'data': 'default',
'source': 'history', 'is_enabled': True}],
'instructions': [], 'set_slots': [], 'dispatch_response': True}
bot_settings.pop("_id")
bot_settings.pop("timestamp")
Expand Down Expand Up @@ -3928,8 +3929,8 @@ def test_get_prompt_action_config_2(self):
'logit_bias': {}}, 'dispatch_response': True, 'set_slots': [],
'llm_prompts': [{'name': 'System Prompt', 'data': 'You are a personal assistant.',
'type': 'system', 'source': 'static', 'is_enabled': True},
{'name': 'History Prompt', 'type': 'user', 'source': 'history',
'is_enabled': True}], 'instructions': [],
{'name': 'History Prompt', 'data': 'default','type': 'user',
'source': 'history', 'is_enabled': True}], 'instructions': [],
'status': True}

def test_retrieve_config_two_stage_fallback_not_found(self):
Expand Down
6 changes: 4 additions & 2 deletions tests/unit_test/data_processor/data_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def test_add_prompt_action_with_empty_collection_for_bot_content_prompt(self):
'llm_prompts': [{'name': 'System Prompt', 'data': 'You are a personal assistant.', 'type': 'system',
'source': 'static', 'is_enabled': True},
{'name': 'Similarity Prompt',
'data': '',
'instructions': 'Answer question based on the context above, if answer is not in the context go check previous logs.',
'type': 'user', 'source': 'bot_content', 'is_enabled': True},
{'name': 'Query Prompt',
Expand Down Expand Up @@ -517,7 +518,8 @@ def test_add_prompt_action_faq_action_with_default_values_and_instructions(self)
'llm_prompts': [
{'name': 'System Prompt', 'data': 'You are a personal assistant.', 'type': 'system',
'source': 'static', 'is_enabled': True},
{'name': 'History Prompt', 'type': 'user', 'source': 'history', 'is_enabled': True}],
{'name': 'History Prompt', 'data': 'default',
'type': 'user', 'source': 'history', 'is_enabled': True}],
'instructions': ['Answer in a short manner.', 'Keep it simple.'],
'set_slots': [{'name': 'gpt_result', 'value': '${data}', 'evaluation_type': 'expression'},
{'name': 'gpt_result_type', 'value': '${data.type}',
Expand Down Expand Up @@ -2890,7 +2892,7 @@ def _mock_bot_info(*args, **kwargs):
assert zip_file.getinfo('actions.yml')
file_info_actions = zip_file.getinfo('actions.yml')
file_content_actions = zip_file.read(file_info_actions)
expected_content = b"name: System Prompt\n source: static\n type: system\n - is_enabled: true"
expected_content = b"name: System Prompt\n source: static\n type: system\n - data: default\n is_enabled: true"
assert file_content_actions.__contains__(expected_content)
zip_file.close()

Expand Down