gourisankar85 commited on
Commit
5bb7dc0
Β·
verified Β·
1 Parent(s): 8e4faf7

Update generator/create_prompt.py

Browse files
Files changed (1) hide show
  1. generator/create_prompt.py +103 -103
generator/create_prompt.py CHANGED
@@ -1,104 +1,104 @@
1
- from langchain.docstore.document import Document
2
-
3
- def create_prompt(documents, question, response):
4
- prompt = f""" I asked someone to answer a question based on one or more documents. Your task is to review their response and assess whether or not each sentence in that response is supported by text in the documents. If supported, identify which sentences in the documents provide that support. Additionally, identify which documents contain useful information for answering the question, and which documents the answer was sourced from.
5
-
6
- Here are the documents, each of which is split into sentences. Alongside each sentence is associated key, such as '0a.' or '0b.' that you can use to refer to it:
7
- {documents}
8
-
9
- The question was:
10
- {question}
11
-
12
- Here is their response, split into sentences with associated keys:
13
- {response}
14
-
15
- Provide a JSON response with an answer , relevance_explanation, all_relevant_sentence_keys, overall_supported_explanation, overall_supported, sentence_support_information(this can be a json inside a json and with these fields response_sentence_key, explanation, supporting_sentence_keys, fully_supported) and all_utilized_sentence_keys below are the definitions
16
-
17
- You must respond with a JSON object matching this schema:
18
-
19
- {{
20
- "answer": "string",
21
- "relevance_explanation": "string",
22
- "all_relevant_sentence_keys": ["string"],
23
- "overall_supported_explanation": "string",
24
- "overall_supported": "boolean",
25
- "sentence_support_information": [
26
- {{
27
- "response_sentence_key": "string",
28
- "explanation": "string",
29
- "supporting_sentence_keys": ["string"],
30
- "fully_supported": "boolean"
31
- }},
32
- ],
33
- "all_utilized_sentence_keys": ["string"]
34
- }}
35
-
36
- The relevance_explanation field is a string explaining which documents
37
- contain useful information for answering the question. Provide a step-by-step
38
- breakdown of information provided in the documents and how it is useful for
39
- answering the question.
40
-
41
- The all_relevant_sentence_keys field is a list of all document sentences keys
42
- (e.g. '0a') that are relevant to the question. Include every sentence that is
43
- useful and relevant to the question, even if it was not used in the response,
44
- or if only parts of the sentence are useful. Ignore the provided response when
45
- making this judgement and base your judgement solely on the provided documents
46
- and question. Omit sentences that, if removed from the document, would not
47
- impact someone's ability to answer the question.
48
-
49
- The overall_supported_explanation field is a string explaining why the response
50
- *as a whole* is or is not supported by the documents. In this field, provide a
51
- step-by-step breakdown of the claims made in the response and the support (or
52
- lack thereof) for those claims in the documents. Begin by assessing each claim
53
- separately, one by one; don’t make any remarks about the response as a whole
54
- until you have assessed all the claims in isolation.
55
-
56
- The overall_supported field is a boolean indicating whether the response as a
57
- whole is supported by the documents. This value should reflect the conclusion
58
- you drew at the end of your step-by-step breakdown in overall_supported_explanation.
59
- In the sentence_support_information field, provide information about the support
60
- *for each sentence* in the response.
61
- The sentence_support_information field is a list of objects, one for each sentence
62
- in the response. Each object MUST have the following fields:
63
- - response_sentence_key: a string identifying the sentence in the response.
64
- This key is the same as the one used in the response above.
65
- 16
66
- - explanation: a string explaining why the sentence is or is not supported by the
67
- documents.
68
- - supporting_sentence_keys: keys (e.g. '0a') of sentences from the documents that
69
- support the response sentence. If the sentence is not supported, this list MUST
70
- be empty. If the sentence is supported, this list MUST contain one or more keys.
71
- In special cases where the sentence is supported, but not by any specific sentence,
72
- you can use the string "supported_without_sentence" to indicate that the sentence
73
- is generally supported by the documents. Consider cases where the sentence is
74
- expressing inability to answer the question due to lack of relevant information in
75
- the provided contex as "supported_without_sentence". In cases where the sentence
76
- is making a general statement (e.g. outlining the steps to produce an answer, or
77
- summarizing previously stated sentences, or a transition sentence), use the
78
- sting "general".In cases where the sentence is correctly stating a well-known fact,
79
- like a mathematical formula, use the string "well_known_fact". In cases where the
80
- sentence is performing numerical reasoning (e.g. addition, multiplication), use
81
- the string "numerical_reasoning".
82
- - fully_supported: a boolean indicating whether the sentence is fully supported by
83
- the documents.
84
- - This value should reflect the conclusion you drew at the end of your step-by-step
85
- breakdown in explanation.
86
- - If supporting_sentence_keys is an empty list, then fully_supported must be false.
87
- - Otherwise, use fully_supported to clarify whether everything in the response
88
- sentence is fully supported by the document text indicated in supporting_sentence_keys
89
- (fully_supported = true), or whether the sentence is only partially or incompletely
90
- supported by that document text (fully_supported = false).
91
- The all_utilized_sentence_keys field is a list of all sentences keys (e.g. ’0a’) that
92
- were used to construct the answer. Include every sentence that either directly supported
93
- the answer, or was implicitly used to construct the answer, even if it was not used
94
- in its entirety. Omit sentences that were not used, and could have been removed from
95
- the documents without affecting the answer.
96
- You must respond with a valid JSON string. Use escapes for quotes, e.g. β€˜\\"β€˜, and
97
- newlines, e.g. β€˜\\nβ€˜. Do not write anything before or after the JSON string. Do not
98
- wrap the JSON string in backticks like β€˜β€˜β€˜ or β€˜β€˜β€˜json.
99
- As a reminder: your task is to review the response and assess which documents contain
100
- useful information pertaining to the question, and how each sentence in the response
101
- is supported by the text in the documents.
102
-
103
- """
104
  return prompt
 
1
+ from langchain.docstore.document import Document
2
+
3
+ def create_prompt(documents, question, response):
4
+ prompt = f""" I asked someone to answer a question based on one or more documents. Your task is to review their response and assess whether or not each sentence in that response is supported by text in the documents. If supported, identify which sentences in the documents provide that support. Additionally, identify which documents contain useful information for answering the question, and which documents the answer was sourced from.
5
+
6
+ Here are the documents, each of which is split into sentences.Alongside each sentence is associated key, such as '0a.' or '0b.' that you can use to refer to it:
7
+ {documents}
8
+
9
+ The question was:
10
+ {question}
11
+
12
+ Here is their response, split into sentences with associated keys:
13
+ {response}
14
+
15
+ Provide a JSON response with an answer , relevance_explanation, all_relevant_sentence_keys, overall_supported_explanation, overall_supported, sentence_support_information(this can be a json inside a json and with these fields response_sentence_key, explanation, supporting_sentence_keys, fully_supported) and all_utilized_sentence_keys below are the definitions
16
+
17
+ You must respond with a JSON object matching this schema:
18
+
19
+ {{
20
+ "answer": "string",
21
+ "relevance_explanation": "string",
22
+ "all_relevant_sentence_keys": ["string"],
23
+ "overall_supported_explanation": "string",
24
+ "overall_supported": "boolean",
25
+ "sentence_support_information": [
26
+ {{
27
+ "response_sentence_key": "string",
28
+ "explanation": "string",
29
+ "supporting_sentence_keys": ["string"],
30
+ "fully_supported": "boolean"
31
+ }},
32
+ ],
33
+ "all_utilized_sentence_keys": ["string"]
34
+ }}
35
+
36
+ The relevance_explanation field is a string explaining which documents
37
+ contain useful information for answering the question. Provide a step-by-step
38
+ breakdown of information provided in the documents and how it is useful for
39
+ answering the question.
40
+
41
+ The all_relevant_sentence_keys field is a list of all document sentences keys
42
+ (e.g. '0a') that are relevant to the question. Include every sentence that is
43
+ useful and relevant to the question, even if it was not used in the response,
44
+ or if only parts of the sentence are useful. Ignore the provided response when
45
+ making this judgement and base your judgement solely on the provided documents
46
+ and question. Omit sentences that, if removed from the document, would not
47
+ impact someone's ability to answer the question.
48
+
49
+ The overall_supported_explanation field is a string explaining why the response
50
+ *as a whole* is or is not supported by the documents. In this field, provide a
51
+ step-by-step breakdown of the claims made in the response and the support (or
52
+ lack thereof) for those claims in the documents. Begin by assessing each claim
53
+ separately, one by one; don’t make any remarks about the response as a whole
54
+ until you have assessed all the claims in isolation.
55
+
56
+ The overall_supported field is a boolean indicating whether the response as a
57
+ whole is supported by the documents. This value should reflect the conclusion
58
+ you drew at the end of your step-by-step breakdown in overall_supported_explanation.
59
+ In the sentence_support_information field, provide information about the support
60
+ *for each sentence* in the response.
61
+ The sentence_support_information field is a list of objects, one for each sentence
62
+ in the response. Each object MUST have the following fields:
63
+ - response_sentence_key: a string identifying the sentence in the response.
64
+ This key is the same as the one used in the response above.
65
+ 16
66
+ - explanation: a string explaining why the sentence is or is not supported by the
67
+ documents.
68
+ - supporting_sentence_keys: keys (e.g. '0a') of sentences from the documents that
69
+ support the response sentence. If the sentence is not supported, this list MUST
70
+ be empty. If the sentence is supported, this list MUST contain one or more keys.
71
+ In special cases where the sentence is supported, but not by any specific sentence,
72
+ you can use the string "supported_without_sentence" to indicate that the sentence
73
+ is generally supported by the documents. Consider cases where the sentence is
74
+ expressing inability to answer the question due to lack of relevant information in
75
+ the provided contex as "supported_without_sentence". In cases where the sentence
76
+ is making a general statement (e.g. outlining the steps to produce an answer, or
77
+ summarizing previously stated sentences, or a transition sentence), use the
78
+ sting "general".In cases where the sentence is correctly stating a well-known fact,
79
+ like a mathematical formula, use the string "well_known_fact". In cases where the
80
+ sentence is performing numerical reasoning (e.g. addition, multiplication), use
81
+ the string "numerical_reasoning".
82
+ - fully_supported: a boolean indicating whether the sentence is fully supported by
83
+ the documents.
84
+ - This value should reflect the conclusion you drew at the end of your step-by-step
85
+ breakdown in explanation.
86
+ - If supporting_sentence_keys is an empty list, then fully_supported must be false.
87
+ - Otherwise, use fully_supported to clarify whether everything in the response
88
+ sentence is fully supported by the document text indicated in supporting_sentence_keys
89
+ (fully_supported = true), or whether the sentence is only partially or incompletely
90
+ supported by that document text (fully_supported = false).
91
+ The all_utilized_sentence_keys field is a list of all sentences keys (e.g. ’0a’) that
92
+ were used to construct the answer. Include every sentence that either directly supported
93
+ the answer, or was implicitly used to construct the answer, even if it was not used
94
+ in its entirety. Omit sentences that were not used, and could have been removed from
95
+ the documents without affecting the answer.
96
+ You must respond with a valid JSON string. Use escapes for quotes, e.g. β€˜\\"β€˜, and
97
+ newlines, e.g. β€˜\\nβ€˜. Do not write anything before or after the JSON string. Do not
98
+ wrap the JSON string in backticks like β€˜β€˜β€˜ or β€˜β€˜β€˜json.
99
+ As a reminder: your task is to review the response and assess which documents contain
100
+ useful information pertaining to the question, and how each sentence in the response
101
+ is supported by the text in the documents.
102
+
103
+ """
104
  return prompt