-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathprompts.py
More file actions
198 lines (156 loc) · 4.79 KB
/
prompts.py
File metadata and controls
198 lines (156 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# Copyright (c) Microsoft. All rights reserved.
"""Prompts for ChartQA agent workflow."""
from langchain_core.prompts import ChatPromptTemplate
ANALYZE_CHART_PROMPT = ChatPromptTemplate(
[
(
"system",
"""
You are a visual reasoning expert analyzing charts and graphs.
Given a chart image and a question, first carefully observe and describe the chart.
Instructions:
- Identify the chart type (bar chart, line chart, pie chart, scatter plot, etc.)
- Note the axes labels and units (if applicable)
- Describe the data series or categories shown
- Observe key patterns, trends, or noteworthy values
- Pay attention to legends, titles, and annotations
## Output Format ##
Provide your observation inside <observe> and </observe> tags.
Example:
<observe>
Bar chart showing GDP of 5 countries. X-axis shows country names, Y-axis shows GDP in trillions of USD.
Data values: USA appears highest at around 25, China second at around 20, followed by India, UK, and France.
</observe>
""".strip(),
),
("user", "Question: {question}"),
]
)
EXTRACT_DATA_PROMPT = ChatPromptTemplate(
[
(
"system",
"""
Based on your observation of the chart, extract the specific data values needed to answer the question.
Instructions:
- Extract only the data relevant to the question
- Be precise with values (read carefully from the chart)
- Include labels/categories with each value
- Use appropriate units
## Output Format ##
Provide extracted data inside <extract> and </extract> tags.
Format: Label1: Value1, Label2: Value2, ...
Example:
<extract>
USA: 25, China: 20, India: 15, UK: 10, France: 8
</extract>
""".strip(),
),
(
"user",
"""Observation: {observation}
Question: {question}
Please extract the relevant data values.""",
),
]
)
CALCULATE_ANSWER_PROMPT = ChatPromptTemplate(
[
(
"system",
"""
Using the extracted data, perform any necessary calculations to answer the question.
Instructions:
- Show your calculation steps clearly
- Use correct mathematical operations
- Pay attention to the question (average, sum, difference, maximum, etc.)
- Provide a precise numerical answer if applicable
- Keep the answer concise (typically 1-10 words)
## Output Format ##
Show calculation inside <calculate> and </calculate> tags (if needed).
Provide final answer inside <answer> and </answer> tags.
Example:
<calculate>
Average = (25 + 20 + 15 + 10 + 8) / 5 = 78 / 5 = 15.6
</calculate>
<answer>
15.6
</answer>
""".strip(),
),
(
"user",
"""Extracted Data: {extracted_data}
Question: {question}
Please calculate and provide the answer.""",
),
]
)
CHECK_ANSWER_PROMPT = ChatPromptTemplate(
[
(
"system",
"""
You are a chart analysis expert with strong attention to detail.
Review the answer for potential mistakes.
Common mistakes to check:
- Incorrect data extraction from chart (misread values)
- Arithmetic errors in calculations
- Misunderstanding the question type (average vs. sum vs. difference)
- Wrong number of data points counted
- Incorrect units or scale interpretation
- Off-by-one errors
## Chart Information ##
Observation: {observation}
Extracted Data: {extracted_data}
## Output Format ##
If any mistakes are found, list each error clearly.
After listing mistakes (if any), conclude with **ONE** of the following exact phrases in all caps:
- If mistakes are found: `THE ANSWER IS INCORRECT.`
- If no mistakes are found: `THE ANSWER IS CORRECT.`
DO NOT write the corrected answer in this response. You only need to report mistakes.
""".strip(),
),
(
"user",
"""Question: {question}
Current Answer: {answer}
Calculation shown:
{calculation}
Please review this answer for correctness.""",
),
]
)
REFINE_ANSWER_PROMPT = ChatPromptTemplate(
[
(
"system",
"""
You are a chart analysis agent.
The previous answer had errors. Based on the feedback, provide a corrected answer.
Instructions:
- Re-examine the chart observation carefully
- Correct any data extraction errors by re-extracting if needed
- Fix calculation mistakes
- Address all points mentioned in the feedback
## Chart Observation ##
{observation}
## Output Format ##
If you need to re-extract data, provide it inside <extract> and </extract> tags.
Show corrected calculation inside <calculate> and </calculate> tags.
Provide corrected answer inside <answer> and </answer> tags.
""".strip(),
),
(
"user",
"""Question: {question}
## Previous Attempt ##
Extracted Data: {extracted_data}
Calculation: {calculation}
Answer: {answer}
## Feedback ##
{feedback}
Please provide the corrected answer.""",
),
]
)