Skip to content

Commit a7ae3bc

Browse files
committed
fix: prompt engineering
1 parent 23c57e2 commit a7ae3bc

File tree

1 file changed

+131
-137
lines changed

1 file changed

+131
-137
lines changed

brickllm/helpers/prompts.py

+131-137
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,131 @@
1-
"""
2-
Module containing the prompts used for the LLM models
3-
"""
4-
5-
get_elem_instructions: str = """
6-
You are a BrickSchema ontology expert and you are provided with a user prompt which describes a building or facility.\n
7-
You are provided with a list of common elements that can be used to describe a building or facility.\n
8-
You are also provided with the elements description to understand what each element represents.\n
9-
You are now asked to identify the elements presents in the user prompt, even if not explicitly mentioned.\n
10-
USER PROMPT: {prompt} \n
11-
ELEMENTS: {elements_dict} \n
12-
""" # noqa
13-
14-
get_elem_children_instructions: str = """
15-
You are a BrickSchema ontology expert and you are provided with a user prompt which describes a building or facility.\n
16-
You are provided with a list of common elements that can be used to describe a building or facility.\n
17-
You are now asked to identify the elements presents in the user prompt.\n
18-
The elements provided are in the format of a hierarchy,
19-
eg: `Sensor -> Position_Sensor, Sensor -> Energy_Sensor`\n
20-
You must include only the elements in the list of common elements provided.\n
21-
DO NOT repeat any elements and DO NOT include "->" in your response.\n
22-
23-
USER PROMPT: {prompt} \n
24-
ELEMENTS HIERARCHY: {elements_list} \n
25-
""" # noqa
26-
27-
get_relationships_instructions: str = """
28-
You are a BrickSchema ontology expert and are provided with a detailed description of a building or facility.\n
29-
You are also provided with a hierarchical structure of identified building components.\n
30-
Your task is to determine the relationships between these components based on the context within the building description and the provided hierarchical structure.\n
31-
The relationships should reflect direct connections or associations as described or implied in the prompt.\n
32-
Each element must be followed by a dot symbol (.) and a number to differentiate between elements of the same type (e.g., Room.1, Room.2).\n
33-
An example of output is the following: [('Building.1', 'Floor.1'), ('Floor.1', 'Room.1'), ('Building.1','Floor.2'), ...]\n
34-
DO NOT add relationships on the output but only the components names, always add first the parent and then the child.\n
35-
If an element has no relationships, add an empty string in place of the missing component ("Room.1","").\n
36-
Hierarchical structure: {building_structure}\n
37-
USER PROMPT: {prompt}
38-
""" # noqa
39-
40-
ttl_example: str = """
41-
@prefix bldg: <urn:Building#> .
42-
@prefix brick: <https://brickschema.org/schema/Brick#> .
43-
@prefix prj: <http://example.com/Project#> .
44-
45-
bldg:CO_sensor a brick:CO ;
46-
brick:hasTag bldg:hour ;
47-
brick:hasUnit bldg:PPM ;
48-
brick:isPointOf bldg: ;
49-
brick:timeseries [ brick:hasTimeseriesId bldg:jkj4432uz43 ;
50-
brick:storedAt bldg:example_DB ] .
51-
52-
bldg:Indoor_humidity a brick:Relative_Humidity_Sensor ;
53-
brick:hasTag bldg:hour ;
54-
brick:hasUnit bldg:PERCENT ;
55-
brick:isPointOf bldg:livingroom ;
56-
brick:timeseries [ brick:hasTimeseriesId bldg:hfrt56478 ;
57-
brick:storedAt bldg:example_DB ] .
58-
59-
bldg:Indoor_temperature a brick:Air_Temperature_Sensor ;
60-
brick:hasTag bldg:hour ;
61-
brick:hasUnit bldg:DEG_C ;
62-
brick:isPointOf bldg:livingroom ;
63-
brick:timeseries [ brick:hasTimeseriesId bldg:rtg456789 ;
64-
brick:storedAt bldg:example_DB ] .
65-
66-
bldg:external_temperature a brick:Air_Temperature_Sensor ;
67-
brick:hasTag bldg:hour ;
68-
brick:hasUnit bldg:DEG_C ;
69-
brick:isPointOf bldg:livingroom ;
70-
brick:timeseries [ brick:hasTimeseriesId bldg:art53678 ;
71-
brick:storedAt bldg:example_DB ] .
72-
73-
bldg:example_db a brick:Database .
74-
75-
prj:ThermoIot a brick:Site .
76-
77-
bldg:Milano_Residence_1 a brick:Building ;
78-
brick:buildingPrimaryFunction [ brick:value "Residential" ] ;
79-
brick:hasLocation [ brick:value "Milano" ] ;
80-
brick:isPartOf prj:ThermoIot .
81-
82-
bldg: a brick:Room ;
83-
brick:isPartOf bldg:Milano_Residence_1 .
84-
85-
bldg:livingroom a brick:Room ;
86-
brick:isPartOf bldg:Milano_Residence_1 .
87-
""" # noqa
88-
89-
schema_to_ttl_instructions: str = """
90-
You are a BrickSchema ontology expert and you are provided with a user prompt which describes a building or facility.\n
91-
You are provided with a dictionary containing the detected components in the building description.\n
92-
You are also provided with the hierarchical structure of the building components with their constraints BrickSchema compliant.\n
93-
Your task is to generate a valid TTL (turtle) script that captures the hierarchy and relationships described in the input.\n
94-
DO NOT add information that are not present in the input.\n
95-
DO NOT add uuids or database id in the TTL if not specified in the prompt.\n
96-
You must keep the enumeration with the hashtag for each component otherwise it will not be possible to recognize the components.\n
97-
The TTL SCRIPT EXAMPLE is useful to understand the overall structure of the output, not the actual content.\n
98-
TTL SCRIPT EXAMPLE: {ttl_example}\n
99-
100-
COMPONENTS HIERARCHY: {elem_hierarchy}\n
101-
102-
USER DESCRIPTION: {prompt}\n
103-
104-
COMPONENTS DICT: {sensors_dict}\n
105-
""" # noqa
106-
107-
ttl_to_user_prompt: str = """
108-
You are a BrickSchema ontology expert tasked with generating a clear and concise description of a building or facility from a TTL script.
109-
110-
Your output must follow these guidelines:
111-
- Focus on the key building characteristics, components and relationships present in the TTL
112-
- Maintain technical accuracy and use proper Brick terminology
113-
- Keep descriptions clear and well-structured
114-
- Only include information explicitly stated in the TTL script
115-
- If no TTL content is provided, return an empty string
116-
117-
Eventually, the user can provide additional instructions to help you generate the building description.
118-
<additional_instructions>
119-
{additional_instructions}
120-
</additional_instructions>
121-
122-
TTL script to analyze:
123-
<ttl_script>
124-
{ttl_script}
125-
</ttl_script>
126-
""" # noqa
127-
128-
prompt_template_local: str = """
129-
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
130-
131-
{instructions}
132-
133-
### Input:
134-
{user_prompt}
135-
136-
### Response:
137-
""" # noqa
1+
"""
2+
Module containing the prompts used for the LLM models
3+
"""
4+
5+
get_elem_instructions: str = """
6+
You are an expert in indentifying semantic elements in a natural language prompt hich describes a building and/or energy systems.\n
7+
You are provided with a dictionary containing the entities of an ontology (ELEMENTS) in a hierarchical way, which can be used to describe the building and/or the energy systems.
8+
You are also provided with the elements description to understand what each element represents.\n
9+
You are now asked to identify the entities of the ENTITIES dictionary presented in the user prompt (USER PROMPT), choosing the most specific one if it is possible among the ones provided. Do not invent any entity!\n
10+
USER PROMPT: {prompt} \n
11+
ENTITIES: {elements_dict} \n
12+
""" # noqa
13+
14+
get_elem_children_instructions: str = """
15+
You are a semantic ontology expert and you are provided with a user prompt (USER PROMPT) which describes a building and/or energy systems.\n
16+
You are provided with a list of common elements organized in a hierarchy (ELEMENTS HIERARCHY).\n
17+
You are now asked to identify the elements in the hierarchy presents in the user prompt.\n
18+
The elements provided are in the format of a hierarchy,
19+
eg: `Sensor -> Position_Sensor, Sensor -> Energy_Sensor`\n
20+
You must include only the elements in the list of common elements provided.\n
21+
DO NOT repeat any elements and DO NOT include "->" in your response.\n
22+
23+
USER PROMPT: {prompt} \n
24+
ELEMENTS HIERARCHY: {elements_list} \n
25+
""" # noqa
26+
27+
get_relationships_instructions: str = """
28+
You are a semantic ontology expert and you are provided with a user prompt (USER PROMPT) that describes a building and/or energy systems.\n
29+
You are also provided with a hierarchical structure (HIERARCHICAL STRUCTURE) of the identified building or energy systems components in the prompt.\n
30+
Your task is to determine the relationships between these components based on the context within the building description and the provided hierarchical structure.\n
31+
The relationships should reflect direct connections or associations as described or implied in the prompt.\n
32+
Each element must be followed by a dot symbol (.) and a number to differentiate between elements of the same type (e.g., Room.1, Room.2).\n
33+
An example of output is the following: [('Building.1', 'Floor.1'), ('Floor.1', 'Room.1'), ('Building.1','Floor.2'), ...]\n
34+
DO NOT add relationships on the output but only the components names, always add first the parent and then the child.\n
35+
If an element has no relationships, add an empty string in place of the missing component ("Room.1","").\n
36+
HIERARCHICAL STRUCTURE: {building_structure}\n
37+
USER PROMPT: {prompt}
38+
""" # noqa
39+
40+
ttl_example: str = """
41+
@prefix bldg: <urn:Building#> .
42+
@prefix brick: <https://brickschema.org/schema/Brick#> .
43+
@prefix unit: <https://qudt.org/vocab/unit/> .
44+
@prefix ref: <https://brickschema.org/schema/Brick/ref#> .
45+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
46+
47+
bldg:CO_sensor a brick:CO ;
48+
brick:hasUnit unit:PPM ;
49+
brick:isPointOf bldg:Milano_Residence_1 ;
50+
ref:hasExternalReference [ a ref:TimeseriesReference ; ref:hasTimeseriesId 'dvfs-dfwde-gaw'^^xsd:string ; ref:storedAt bldg:example_db ]
51+
52+
bldg:Indoor_humidity a brick:Relative_Humidity_Sensor ;
53+
brick:hasUnit unit:PERCENT ;
54+
brick:isPointOf bldg:livingroom ;
55+
ref:hasExternalReference [ a ref:TimeseriesReference ; ref:hasTimeseriesId '23rs-432a-63cv'^^xsd:string ;
56+
ref:storedAt bldg:example_db ] .
57+
58+
bldg:Indoor_temperature a brick:Air_Temperature_Sensor ;
59+
brick:hasUnit unit:DEG_C ;
60+
brick:isPointOf bldg:livingroom ;
61+
ref:hasExternalReference [ a ref:TimeseriesReference ; ref:hasTimeseriesId 'rtg456789'^^xsd:string ;
62+
ref:storedAt bldg:example_db ] .
63+
64+
bldg:external_temperature a brick:Air_Temperature_Sensor ;
65+
brick:hasUnit unit:DEG_C ;
66+
brick:isPointOf bldg:livingroom ;
67+
ref:hasExternalReference [ a ref:TimeseriesReference ; ref:hasTimeseriesId 'art53678^^xsd:string' ;
68+
ref:storedAt bldg:example_db ] .
69+
70+
bldg:example_db a brick:Database .
71+
72+
bldg:Milano_Residence_1 a brick:Building ;
73+
brick:hasLocation [ brick:value "Milano"^^xsd:string ] .
74+
75+
bldg: a brick:Room ;
76+
brick:isPartOf bldg:Milano_Residence_1 .
77+
78+
bldg:livingroom a brick:Room ;
79+
brick:isPartOf bldg:Milano_Residence_1 .
80+
""" # noqa
81+
82+
schema_to_ttl_instructions: str = """
83+
You are an expert in generating ontology-based RDF graph from a user prompt, which describes a building or energy systems.\n
84+
You are provided with a dictionary containing the hierarchy of the building/energy systems components (COMPONENTS HIERARCHY) detected in the user prompt (USER PROMP).\n
85+
You are also provided with the list of the sensors (SENSOR LIST) identified in the user prompts, with additional information about uuid and unit of measures, if avaiable.
86+
Your task is to generate a RDF graph in Turtle format that is compliant with the hierarchy and relationships described in the input. Use only the elements identified in the COMPONENTS HIERARCHY and SENSOR LIST, connecting each entities with the appropriate properties (presented in each element of the hierarchy).\n
87+
DO NOT add information that are not present in the input.\n
88+
To encode the uuid of the sensors, use the following schema: 'sensor' ref:hasEternalReference [ a ref:TimeseriesReference ; ref:hasTimeseriesId 'uuid'^^xsd:string .].\n
89+
To encode the unit of measure of the sensor, use the following schema: 'sensor' brick:hasUnit unit:'UNIT'.\n
90+
Include all the @prefix declarations at the beginning of the output Turtle file.\n
91+
I provide you an example of the output Turtle: the TTL SCRIPT EXAMPLE is useful to understand the overall structure of the output, not the actual content.\n
92+
TTL SCRIPT EXAMPLE: {ttl_example}\n
93+
94+
COMPONENTS HIERARCHY: {elem_hierarchy}\n
95+
96+
USER PROMPT: {prompt}\n
97+
98+
SENSOR LIST: {uuid_list}\n
99+
""" # noqa
100+
101+
ttl_to_user_prompt: str = """
102+
You are a BrickSchema ontology expert tasked with generating a clear and concise description of a building or facility from a TTL script.
103+
104+
Your output must follow these guidelines:
105+
- Focus on the key building characteristics, components and relationships present in the TTL
106+
- Maintain technical accuracy and use proper Brick terminology
107+
- Keep descriptions clear and well-structured
108+
- Only include information explicitly stated in the TTL script
109+
- If no TTL content is provided, return an empty string
110+
111+
Eventually, the user can provide additional instructions to help you generate the building description.
112+
<additional_instructions>
113+
{additional_instructions}
114+
</additional_instructions>
115+
116+
TTL script to analyze:
117+
<ttl_script>
118+
{ttl_script}
119+
</ttl_script>
120+
""" # noqa
121+
122+
prompt_template_local: str = """
123+
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
124+
125+
{instructions}
126+
127+
### Input:
128+
{user_prompt}
129+
130+
### Response:
131+
""" # noqa

0 commit comments

Comments
 (0)