Skip to content

Commit 23ec029

Browse files
committed
Update prompt
1 parent c94ef08 commit 23ec029

File tree

1 file changed

+41
-54
lines changed

1 file changed

+41
-54
lines changed

ai_search_with_adi/adi_function_app/adi_2_ai_search.py

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def clean_adi_markdown(
6666
"""
6767

6868
output_dict = {}
69-
comment_patterns = r"<!-- PageNumber=\"\d+\" -->|<!-- PageHeader=\".*?\" -->|<!-- PageFooter=\".*?\" -->"
69+
comment_patterns = r"<!-- PageNumber=\"\d+\" -->|<!-- PageHeader=\".*?\" -->|<!-- PageFooter=\".*?\" -->|<!-- PageBreak -->"
7070
cleaned_text = re.sub(comment_patterns, "", markdown_text, flags=re.DOTALL)
7171

72-
combined_pattern = r"(.*?)\n===|\n## ?(.*?)\n|\n### ?(.*?)\n"
72+
combined_pattern = r"(.*?)\n===|\n# (.*?)\n|\n## ?(.*?)\n|\n### ?(.*?)\n|\n#### ?(.*?)\n|\n##### ?(.*?)\n|\n###### ?(.*?)\n"
7373
doc_metadata = re.findall(combined_pattern, cleaned_text, re.DOTALL)
7474
doc_metadata = [match for group in doc_metadata for match in group if match]
7575

@@ -162,6 +162,21 @@ async def understand_image_with_gptv(image_base64, caption, tries_left=3):
162162
token_provider = None
163163
api_key = os.environ.get("OpenAI__ApiKey")
164164

165+
system_prompt = """You are an expert in image analysis. Use your experience and skills to provided a detailed description of any provided images. You should FOCUS on what info can be inferred from the image and the meaning of the data inside the image. Draw actionable insights and conclusions from the image.
166+
167+
If the image is a chart for instance, you should describe the data trends, patterns, and insights that can be drawn from the chart.
168+
169+
If the image is a map, you should describe the geographical features, landmarks, and any other relevant information that can be inferred from the map.
170+
171+
If the image is a diagram, you should describe the components, relationships, and any other relevant information that can be inferred from the diagram.
172+
173+
IMPORTANT: If the provided image is a logo or photograph, simply return 'Irrelevant Image'."""
174+
175+
user_input = "Describe this image with technical analysis. Provide a well-structured, description."
176+
177+
if caption != "":
178+
user_input += f" (note: it has image caption: {caption})"
179+
165180
try:
166181
async with AsyncAzureOpenAI(
167182
api_key=api_key,
@@ -170,59 +185,31 @@ async def understand_image_with_gptv(image_base64, caption, tries_left=3):
170185
azure_endpoint=os.environ.get("OpenAI__Endpoint"),
171186
) as client:
172187
# We send both image caption and the image body to GPTv for better understanding
173-
if caption != "":
174-
response = await client.chat.completions.create(
175-
model=model,
176-
messages=[
177-
{
178-
"role": "system",
179-
"content": "You are an expert in image analysis. Use your experience and skills to provided a detailed description of any provided images. You should focus on what info can be inferred from the image and the meaning of the data inside the image.",
180-
},
181-
{
182-
"role": "user",
183-
"content": [
184-
{
185-
"type": "text",
186-
"text": f"Describe this image with technical analysis. Provide a well-structured, description. IMPORTANT: If the provided image is a logo or photograph, simply return 'Irrelevant Image'. (note: it has image caption: {caption}):",
187-
},
188-
{
189-
"type": "image_url",
190-
"image_url": {
191-
"url": f"data:image/png;base64,{image_base64}"
192-
},
193-
},
194-
],
195-
},
196-
],
197-
max_tokens=MAX_TOKENS,
198-
)
199-
200-
else:
201-
response = await client.chat.completions.create(
202-
model=model,
203-
messages=[
204-
{
205-
"role": "system",
206-
"content": "You are an expert in image analysis. Use your experience and skills to provided a detailed description of any provided images. You should focus on what info can be inferred from the image and the meaning of the data inside the image.",
207-
},
208-
{
209-
"role": "user",
210-
"content": [
211-
{
212-
"type": "text",
213-
"text": "Describe this image with technical analysis. Provide a well-structured, description. IMPORTANT: If the provided image is a logo or photograph, simply return 'Irrelevant Image'.",
214-
},
215-
{
216-
"type": "image_url",
217-
"image_url": {
218-
"url": f"data:image/png;base64,{image_base64}"
219-
},
188+
response = await client.chat.completions.create(
189+
model=model,
190+
messages=[
191+
{
192+
"role": "system",
193+
"content": system_prompt,
194+
},
195+
{
196+
"role": "user",
197+
"content": [
198+
{
199+
"type": "text",
200+
"text": user_input,
201+
},
202+
{
203+
"type": "image_url",
204+
"image_url": {
205+
"url": f"data:image/png;base64,{image_base64}"
220206
},
221-
],
222-
},
223-
],
224-
max_tokens=MAX_TOKENS,
225-
)
207+
},
208+
],
209+
},
210+
],
211+
max_tokens=MAX_TOKENS,
212+
)
226213

227214
img_description = response.choices[0].message.content
228215

0 commit comments

Comments
 (0)