Skip to content

Commit

Permalink
improve prompts delimiter #72
Browse files Browse the repository at this point in the history
  • Loading branch information
YY-SONG0718 committed Dec 15, 2023
1 parent c44e04a commit b7e79a5
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions biochatter/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
primary_messages = {
"message_entity": (
"You have access to a knowledge graph that contains "
"the entities after the delimiter {delimiter} in the end of this message."
"the entities which will be provided at the end of this message delimited with {delimiter} characters. "
"Your task is to select the ones that are relevant to the user's question "
"for subsequent use in a query. Only return the entities, "
"comma-separated, without any additional text. "
"{delimiter}"
"comma-separated, without any additional text.\n"
"{delimiter}\n"
"{entities}"
),
"message_relationship": (
"You have access to a knowledge graph that contains entities and relationships "
"after the delimiter {delimiter} in the end of this message."
"which will be provided at the end of this message delimited with {delimiter} characters. "
"Your task is to select the relationships that are relevant "
"to the user's question for subsequent use in a query. Only "
"return the relationships without their sources or targets, "
"comma-separated, and without any additional text. Here are the "
"possible relationships and their source and target entities: "
"{delimiter}"
"entities:{selected_entities_joined}"
"possible relationships and their source and target entities:\n"
"{delimiter}\n"
"entities:{selected_entities_joined}\n"
"relationships: {relationships}"
),
"message_property": (
"You have access to a knowledge graph that contains entities and "
"relationships. Their properties are after the delimiter {delimiter} in the end of this message."
"relationships. Their properties are after the delimiter {delimiter} in the end of this message. "
"Your task is to select the properties that are relevant to the "
"user's question for subsequent use in a query. Only return the "
"entities and relationships with their relevant properties in JSON "
"format, without any additional text. Return the "
"entities/relationships as top-level dictionary keys, and their "
"properties as dictionary values. "
"Do not return properties that are not relevant to the question."
"{delimiter}"
"entities and their properties: {entity_properties}"
"Do not return properties that are not relevant to the question.\n"
"{delimiter}\n"
"entities and their properties: {entity_properties}\n"
"relationships and their properties: {relationship_properties}"
),
"message_query": (
Expand Down Expand Up @@ -108,7 +108,7 @@ def _add_system_message_entity(self, entities):
# TODO: an option to add kg info at the beginning of this message
# TODO: other propts then primary
if self.label == "primary":
system_message_entity = primary_messages['message_entity'].format(
system_message_entity = primary_messages["message_entity"].format(
delimiter=self.delimiter, entities=entities
)
self.content = f"{self.content}\n{system_message_entity}"
Expand All @@ -120,7 +120,9 @@ def _add_system_message_relationship(
selected_entities_joined = ", ".join(selected_entities)

if self.label == "primary":
system_message_relationship = primary_messages['message_relationship'].format(
system_message_relationship = primary_messages[
"message_relationship"
].format(
delimiter=self.delimiter,
selected_entities=selected_entities_joined,
relationships=relationships,
Expand All @@ -132,7 +134,9 @@ def _add_system_message_property(
):
self.message_for = "property"
if self.label == "primary":
system_message_property = primary_messages['message_property'].format(
system_message_property = primary_messages[
"message_property"
].format(
delimiter=self.delimiter,
entity_properties=entity_properties,
relationship_properties=relationship_properties,
Expand All @@ -146,7 +150,7 @@ def _add_system_message_query(
relationships_key_list = list(relationships.keys())

if self.label == "primary":
system_message_query = primary_messages['message_query'].format(
system_message_query = primary_messages["message_query"].format(
query_language=query_language,
entities=entities,
relationships_key_list=relationships_key_list,
Expand Down

0 comments on commit b7e79a5

Please sign in to comment.