Skip to content

Commit a65605b

Browse files
authored
Merge pull request #3089 from lgayhardt/pf0225p1
prompt flow image and trace freshness
2 parents 5fc9b70 + b7e4c6f commit a65605b

File tree

7 files changed

+60
-27
lines changed

7 files changed

+60
-27
lines changed

articles/ai-studio/how-to/develop/trace-production-sdk.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ ms.service: azure-ai-foundry
77
ms.custom:
88
- build-2024
99
ms.topic: how-to
10-
ms.date: 5/21/2024
11-
ms.reviewer: keli19
10+
ms.date: 02/14/2025
11+
ms.reviewer: none
1212
ms.author: lagayhar
1313
author: lgayhardt
1414
---
@@ -38,13 +38,13 @@ After you test your flow properly, either a flex flow or a DAG flow, you can dep
3838
You can also [deploy to other platforms, such as Docker container, Kubernetes cluster, and more](https://microsoft.github.io/promptflow/how-to-guides/deploy-a-flow/index.html).
3939

4040
> [!NOTE]
41-
> You need to use the latest prompt flow base image to deploy the flow, so that it support the tracing and feedback collection API.
41+
> You need to use the latest prompt flow base image to deploy the flow, so that it supports the tracing and feedback collection API.
4242
4343
## Enable trace and collect system metrics for your deployment
4444

45-
If you're using Azure AI Foundry portal to deploy, then you can turn-on **Application Insights diagnostics** in **Advanced settings** > **Deployment** step in the deployment wizard, in which way the tracing data and system metrics are collected to the project linked to Application Insights.
45+
If you're using Azure AI Foundry portal to deploy, you can turn on **Application Insights diagnostics** in the **Advanced settings** > **Deployment** step in the deployment wizard, in which way the tracing data and system metrics are collected to the project linked to Application Insights.
4646

47-
If you're using SDK or CLI, you can by adding a property `app_insights_enabled: true` in the deployment yaml file that collects data to the project linked to application insights.
47+
If you're using the SDK or CLI, you can add a property `app_insights_enabled: true` in the deployment yaml file that collects data to the project linked to application insights.
4848

4949
```yaml
5050
app_insights_enabled: true
@@ -58,30 +58,31 @@ environment_variables:
5858
```
5959

6060
> [!NOTE]
61-
> If you only set `app_insights_enabled: true` but your project doesn't have a linked Application Insights resource, your deployment will not fail but there will be no data collected.
61+
> If you only set `app_insights_enabled: true` but your project doesn't have a linked Application Insights resource, your deployment won't fail but there will be no data collected.
6262
>
63-
> If you specify both `app_insights_enabled: true` and the above environment variable at the same time, the tracing data and metrics will be sent to the project linked to application insights. Hence, if you want to specify a different Application Insights, you only need to keep the environment variable.
63+
> If you specify both `app_insights_enabled: true` and the previous environment variable at the same time, the tracing data and metrics will be sent to the project linked to application insights. Hence, if you want to specify a different Application Insights, you only need to keep the environment variable.
6464
>
65-
> If you deploy to other platforms, you can also use the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING: <connection_string>` to collect trace data and metrics to speicifed Application Insights.
65+
> If you deploy to other platforms, you can also use the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING: <connection_string>` to collect trace data and metrics to specified Application Insights.
66+
6667
## View tracing data in Application Insights
6768

6869
Traces record specific events or the state of an application during execution. It can include data about function calls, variable values, system events and more. Traces help breakdown an application's components into discrete inputs and outputs, which is crucial for debugging and understanding an application. You can learn more from [here](https://opentelemetry.io/docs/concepts/signals/traces/) on traces. The trace data follows [OpenTelemetry specification](https://opentelemetry.io/docs/specs/otel/).
6970

7071
You can view the detailed trace in the specified Application Insights. The following screenshot shows an example of an event of a deployed flow containing multiple nodes. In Application Insights -> Investigate -> Transaction search, and you can select each node to view its detailed trace.
7172

72-
The **Dependency** type events record calls from your deployments. The name of that event is the name of flow folder. Learn more about [Transaction search and diagnostics in Application Insights](/azure/azure-monitor/app/transaction-search-and-diagnostics).
73+
The **Dependency** type events record calls from your deployments. The name of that event is the name of the flow folder. Learn more about [Transaction search and diagnostics in Application Insights](/azure/azure-monitor/app/transaction-search-and-diagnostics).
7374

7475
## View system metrics in Application Insights
7576

7677
| Metrics Name | Type | Dimensions | Description |
7778
|--------------------------------------|-----------|-------------------------------------------|---------------------------------------------------------------------------------|
78-
| token_consumption | counter | - flow <br> - node<br> - llm_engine<br> - token_type: `prompt_tokens`: LLM API input tokens; `completion_tokens`: LLM API response tokens ; `total_tokens` = `prompt_tokens + completion tokens` | OpenAI token consumption metrics |
79-
| flow_latency | histogram | flow,response_code,streaming,response_type| request execution cost, response_type means whether it's full/firstbyte/lastbyte|
80-
| flow_request | counter | flow,response_code,exception,streaming | flow request count |
81-
| node_latency | histogram | flow,node,run_status | node execution cost |
82-
| node_request | counter | flow,node,exception,run_status | node execution count |
83-
| rpc_latency | histogram | flow,node,api_call | rpc cost |
84-
| rpc_request | counter | flow,node,api_call,exception | rpc count |
79+
| token_consumption | counter | - flow <br> - node<br> - llm_engine<br> - token_type: `prompt_tokens`: LLM API input tokens; `completion_tokens`: LLM API response tokens; `total_tokens` = `prompt_tokens + completion tokens` | OpenAI token consumption metrics |
80+
| flow_latency | histogram | flow, response_code, streaming, response_type | request execution cost, response_type means whether it's full/firstbyte/lastbyte|
81+
| flow_request | counter | flow, response_code, exception, streaming | flow request count |
82+
| node_latency | histogram | flow, node, run_status | node execution cost |
83+
| node_request | counter | flow, node, exception, run_status | node execution count |
84+
| rpc_latency | histogram | flow, node, api_call | rpc cost |
85+
| rpc_request | counter | flow, node, api_call, exception | rpc count |
8586
| flow_streaming_response_duration | histogram | flow | streaming response sending cost, from sending first byte to sending last byte |
8687

8788
You can find the workspace default Application Insights in your workspace overview page in Azure portal.

articles/ai-studio/how-to/flow-process-image.md

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ ms.service: azure-ai-foundry
77
ms.custom:
88
- build-2024
99
ms.topic: how-to
10-
ms.date: 5/21/2024
11-
ms.reviewer: jinzhong
10+
ms.date: 02/14/2025
11+
ms.reviewer: none
1212
ms.author: lagayhar
1313
author: lgayhardt
1414
---
@@ -39,14 +39,44 @@ To use image data in prompt flow authoring page:
3939
:::image type="content" source="../media/prompt-flow/how-to-process-image/flow-input-image-preview.png" alt-text="Screenshot of flow authoring page showing image preview flow input." lightbox = "../media/prompt-flow/how-to-process-image/flow-input-image-preview.png":::
4040
3. You might want to preprocess the image using the [Python tool](./prompt-flow-tools/python-tool.md) before feeding it to the LLM. For example, you can resize or crop the image to a smaller size.
4141
:::image type="content" source="../media/prompt-flow/how-to-process-image/process-image-using-python.png" alt-text="Screenshot of using python tool to do image preprocessing." lightbox = "../media/prompt-flow/how-to-process-image/process-image-using-python.png":::
42+
43+
```python
44+
from promptflow import tool
45+
from promptflow.contracts.multimedia import Image as PFImage
46+
from PIL import Image as Image
47+
import io
48+
49+
@tool
50+
def process_image(input_image: PFImage) -> PFImage:
51+
# convert the input image data to a BytesIO object
52+
data_byteIO = io.BytesIO(input_image)
53+
54+
# Open the image data as a PIL Image object
55+
image = Image.open(data_byteIO)
56+
57+
# crop image
58+
cropped_image = image.crop((100, 100, 900, 900))
59+
60+
# Convert the cropped image back to BytesIO
61+
byte_arr = io.BytesIO()
62+
cropped_image.save(byte_arr, format = 'JPEG')
63+
64+
# Create a new prompt flow Image object with the cropped image data
65+
# This image is now ready to be returned
66+
cropped_PF_image = PFImage(byte_arr.getvalue(), mime_type = "image/jpeg")
67+
68+
return cropped_PF_image
69+
```
70+
4271
> [!IMPORTANT]
4372
> To process images using a Python function, you need to use the `Image` class that you import from the `promptflow.contracts.multimedia` package. The `Image` class is used to represent an `Image` type within prompt flow. It is designed to work with image data in byte format, which is convenient when you need to handle or manipulate the image data directly.
4473
>
4574
> To return the processed image data, you need to use the `Image` class to wrap the image data. Create an `Image` object by providing the image data in bytes and the [MIME type](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) `mime_type`. The MIME type lets the system understand the format of the image data, or it can be `*` for unknown type.
4675

4776
4. Run the Python node and check the output. In this example, the Python function returns the processed Image object. Select the image output to preview the image.
4877
:::image type="content" source="../media/prompt-flow/how-to-process-image/python-node-image-output.png" alt-text="Screenshot of Python node's image output." lightbox = "../media/prompt-flow/how-to-process-image/python-node-image-output.png":::
49-
If the Image object from Python node is set as the flow output, you can preview the image in the flow output page as well.
78+
79+
If the Image object from Python node is set as the flow output, you can preview the image in the flow output page as well.
5080

5181
## Use GPT-4V tool
5282

@@ -56,32 +86,34 @@ Add the [Azure OpenAI GPT-4 Turbo with Vision tool](./prompt-flow-tools/azure-op
5686

5787
:::image type="content" source="../media/prompt-flow/how-to-process-image/gpt-4v-tool.png" alt-text="Screenshot of GPT-4V tool." lightbox = "../media/prompt-flow/how-to-process-image/gpt-4v-tool.png":::
5888

59-
The Jinja template for composing prompts in the GPT-4V tool follows a similar structure to the chat API in the LLM tool. To represent an image input within your prompt, you can use the syntax `![image]({{INPUT NAME}})`. Image input can be passed in the `user`, `system` and `assistant` messages.
89+
The Jinja template for composing prompts in the GPT-4V tool follows a similar structure to the chat API in the LLM tool. To represent an image input within your prompt, you can use the syntax `![image]({{INPUT NAME}})`. Image input can be passed in the `user`, `system`, and `assistant` messages.
6090

6191
Once you've composed the prompt, select the **Validate and parse input** button to parse the input placeholders. The image input represented by `![image]({{INPUT NAME}})` will be parsed as image type with the input name as INPUT NAME.
6292

6393
You can assign a value to the image input through the following ways:
6494

6595
- Reference from the flow input of Image type.
6696
- Reference from other node's output of Image type.
67-
- Upload, drag, or paste an image, or specify an image URL or the relative image path.
97+
- Upload, drag, paste an image, or specify an image URL or the relative image path.
6898

6999
## Build a chatbot to process images
70100

71101
In this section, you learn how to build a chatbot that can process image and text inputs.
72102

73-
Assume you want to build a chatbot that can answer any questions about the image and text together. You can achieve this by following the steps below:
103+
Assume you want to build a chatbot that can answer any questions about the image and text together. You can achieve this by following the steps in this section.
74104

75105
1. Create a **chat flow**.
76-
1. Add a **chat input**, select the data type as **"list"**. In the chat box, user can input a mixed sequence of texts and images, and prompt flow service will transform that into a list.
106+
1. In *Inputs*, select the data type as **"list"**. In the chat box, user can input a mixed sequence of texts and images, and prompt flow service will transform that into a list.
77107
:::image type="content" source="../media/prompt-flow/how-to-process-image/chat-input-definition.png" alt-text="Screenshot of chat input type configuration." lightbox = "../media/prompt-flow/how-to-process-image/chat-input-definition.png":::
78-
1. Add **GPT-4V** tool to the flow.
108+
1. Add **GPT-4V** tool to the flow. You can copy the prompt from the default LLM tool chat and paste it into the GPT 4V tool. Then you delete the default LLM tool chat from the flow.
79109
:::image type="content" source="../media/prompt-flow/how-to-process-image/gpt-4v-tool-in-chatflow.png" alt-text=" Screenshot of GPT-4V tool in chat flow." lightbox = "../media/prompt-flow/how-to-process-image/gpt-4v-tool-in-chatflow.png":::
80110

81111
In this example, `{{question}}` refers to the chat input, which is a list of texts and images.
112+
1. In *Outputs*, change the value of "answer" to the name of your vision tool's output, for example, `${gpt_vision.output}`.
113+
:::image type="content" source="../media/prompt-flow/how-to-process-image/chat-output-definition.png" alt-text="Screenshot of chat output type configuration." lightbox = "../media/prompt-flow/how-to-process-image/chat-output-definition.png":::
82114
1. (Optional) You can add any custom logic to the flow to process the GPT-4V output. For example, you can add content safety tool to detect if the answer contains any inappropriate content, and return a final answer to the user.
83115
:::image type="content" source="../media/prompt-flow/how-to-process-image/chat-flow-postprocess.png" alt-text="Screenshot of processing gpt-4v output with content safety tool." lightbox = "../media/prompt-flow/how-to-process-image/chat-flow-postprocess.png":::
84-
1. Now you can **test the chatbot**. Open the chat window, and input any questions with images. The chatbot will answer the questions based on the image and text inputs. The chat input value is automatically backfilled from the input in the chat window. You can find the texts with images in the chat box which is translated into a list of texts and images.
116+
1. Now you can **test the chatbot**. Open the chat window, and input any questions with images. The chatbot will answer the questions based on the image and text inputs. The chat input value is automatically backfilled from the input in the chat window. You can find the texts with images in the chat box which is translated into a list of texts and images.
85117
:::image type="content" source="../media/prompt-flow/how-to-process-image/chatbot-test.png" alt-text="Screenshot of chatbot interaction with images." lightbox = "../media/prompt-flow/how-to-process-image/chatbot-test.png":::
86118

87119
> [!NOTE]
@@ -98,7 +130,7 @@ A batch run allows you to test the flow with an extensive dataset. There are thr
98130
- **Public image URL:** You can also reference the image URL in the entry file using this format: `{"data:<mime type>;url": "<image URL>"}`. For example, `{"data:image/png;url": "https://www.example.com/images/1.png"}`.
99131
- **Base64 string:** A Base64 string can be referenced in the entry file using this format: `{"data:<mime type>;base64": "<base64 string>"}`. For example, `{"data:image/png;base64": "iVBORw0KGgoAAAANSUhEUgAAAGQAAABLAQMAAAC81rD0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEUAAP7////DYP5JAAAAAWJLR0QB/wIt3gAAAAlwSFlzAAALEgAACxIB0t1+/AAAAAd0SU1FB+QIGBcKN7/nP/UAAAASSURBVDjLY2AYBaNgFIwCdAAABBoAAaNglfsAAAAZdEVYdGNvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVDnr0DLAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIwLTA4LTI0VDIzOjEwOjU1KzAzOjAwkHdeuQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMC0wOC0yNFQyMzoxMDo1NSswMzowMOEq5gUAAAAASUVORK5CYII="}`.
100132

101-
In summary, prompt flow uses a unique dictionary format to represent an image, which is `{"data:<mime type>;<representation>": "<value>"}`. Here, `<mime type>` refers to HTML standard [MIME](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) image types, and `<representation>` refers to the supported image representations: `path`,`url` and `base64`.
133+
In summary, prompt flow uses a unique dictionary format to represent an image, which is `{"data:<mime type>;<representation>": "<value>"}`. Here, `<mime type>` refers to HTML standard [MIME](https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) image types, and `<representation>` refers to the supported image representations: `path`,`url`, and `base64`.
102134

103135
### Create a batch run
104136

@@ -125,7 +157,7 @@ For now, you can test the endpoint by sending request including image inputs.
125157

126158
To consume the online endpoint with image input, you should represent the image by using the format `{"data:<mime type>;<representation>": "<value>"}`. In this case, `<representation>` can either be `url` or `base64`.
127159

128-
If the flow generates image output, it is returned with `base64` format, for example, `{"data:<mime type>;base64": "<base64 string>"}`.
160+
If the flow generates image output, it's returned with `base64` format, for example, `{"data:<mime type>;base64": "<base64 string>"}`.
129161

130162
## Next steps
131163

-47.9 KB
Loading
-33.1 KB
Loading
14.8 KB
Loading
-125 KB
Loading
-129 KB
Loading

0 commit comments

Comments
 (0)