Skip to content

Commit ebbd111

Browse files
committed
update the chat prompt part and refine according to comments
1 parent ded82d9 commit ebbd111

File tree

3 files changed

+127
-7
lines changed

3 files changed

+127
-7
lines changed

articles/ai-studio/how-to/prompt-flow-tools/llm-tool.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ The output varies depending on the API you selected for inputs.
127127

128128
Prepare a prompt as described in the [Prompt tool](prompt-tool.md#prerequisites) documentation. The LLM tool and Prompt tool both support [Jinja](https://jinja.palletsprojects.com/en/3.1.x/) templates. For more information and best practices, see [Prompt engineering techniques](../../../ai-services/openai/concepts/advanced-prompt-engineering.md).
129129

130-
For example, for a chat prompt we offer a method to distinguish between different roles, such as "system," "user," "assistant." Each role can have "name" and "content" properties.
130+
For example, for a chat prompt we offer a method to distinguish between different roles in a chat prompt, such as "system", "user", "assistant" and "tool". The "system", "user", "assistant" roles can have "name" and "content" properties. The "tool" role, however, should have "tool_call_id" and "content" properties. For an example of a tool chat prompt, please refer to [Sample 3](#sample-3).
131131

132132
### Sample 1
133133
```jinja
@@ -191,6 +191,67 @@ In LLM tool, the prompt is transformed to match the [openai messages](https://pl
191191
]
192192
```
193193

194+
### Sample 3
195+
This sample illustrates how to write a tool chat prompt.
196+
```jinja
197+
# system:
198+
You are a helpful assistant.
199+
# user:
200+
What is the current weather like in Boston?
201+
# assistant:
202+
{# The assistant message with 'tool_calls' must be followed by messages with role 'tool'. #}
203+
## tool_calls:
204+
{{llm_output.tool_calls}}
205+
# tool:
206+
{#
207+
Messages with role 'tool' must be a response to a preceding message with 'tool_calls'.
208+
Additionally, 'tool_call_id's should match ids of assistant message 'tool_calls'.
209+
#}
210+
## tool_call_id:
211+
{{llm_output.tool_calls[0].id}}
212+
## content:
213+
{{tool-answer-of-last-question}}
214+
# user:
215+
{{question}}
216+
```
217+
218+
In LLM tool, the prompt is transformed to match the [openai messages](https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages) structure before sending to openai chat API.
219+
220+
```
221+
[
222+
{
223+
"role": "system",
224+
"content": "You are a helpful assistant."
225+
},
226+
{
227+
"role": "user",
228+
"content": "What is the current weather like in Boston?"
229+
},
230+
{
231+
"role": "assistant",
232+
"content": null,
233+
"function_call": null,
234+
"tool_calls": [
235+
{
236+
"id": "<tool-call-id-of-last-question>",
237+
"type": "function",
238+
"function": "<function-to-call-of-last-question>"
239+
}
240+
]
241+
},
242+
{
243+
"role": "tool",
244+
"tool_call_id": "<tool-call-id-of-last-question>",
245+
"content": "<tool-answer-of-last-question>"
246+
}
247+
...
248+
{
249+
"role": "user",
250+
"content": "<question>"
251+
}
252+
]
253+
```
254+
194255
## Next steps
195256

196257
- [Learn more about how to create a flow](../flow-develop.md)

articles/machine-learning/prompt-flow/tools-reference/llm-tool.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ The following sections show various inputs.
117117

118118
_To grasp the fundamentals of creating a chat prompt, begin with the [Write a prompt section](prompt-tool.md#write-a-prompt) for an introductory understanding of Jinja._
119119

120-
We offer a method to distinguish between different roles in a chat prompt, such as "system," "user," "assistant." Each role can have "name" and "content" properties.
120+
We offer a method to distinguish between different roles in a chat prompt, such as "system", "user", "assistant" and "tool". The "system", "user", "assistant" roles can have "name" and "content" properties. The "tool" role, however, should have "tool_call_id" and "content" properties. For an example of a tool chat prompt, please refer to [Sample 3](#sample-3).
121121

122122
### Sample 1
123123
```jinja
@@ -180,3 +180,64 @@ In LLM tool, the prompt is transformed to match the [openai messages](https://pl
180180
}
181181
]
182182
```
183+
184+
### Sample 3
185+
This sample illustrates how to write a tool chat prompt.
186+
```jinja
187+
# system:
188+
You are a helpful assistant.
189+
# user:
190+
What is the current weather like in Boston?
191+
# assistant:
192+
{# The assistant message with 'tool_calls' must be followed by messages with role 'tool'. #}
193+
## tool_calls:
194+
{{llm_output.tool_calls}}
195+
# tool:
196+
{#
197+
Messages with role 'tool' must be a response to a preceding message with 'tool_calls'.
198+
Additionally, 'tool_call_id's should match ids of assistant message 'tool_calls'.
199+
#}
200+
## tool_call_id:
201+
{{llm_output.tool_calls[0].id}}
202+
## content:
203+
{{tool-answer-of-last-question}}
204+
# user:
205+
{{question}}
206+
```
207+
208+
In LLM tool, the prompt is transformed to match the [openai messages](https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages) structure before sending to openai chat API.
209+
210+
```
211+
[
212+
{
213+
"role": "system",
214+
"content": "You are a helpful assistant."
215+
},
216+
{
217+
"role": "user",
218+
"content": "What is the current weather like in Boston?"
219+
},
220+
{
221+
"role": "assistant",
222+
"content": null,
223+
"function_call": null,
224+
"tool_calls": [
225+
{
226+
"id": "<tool-call-id-of-last-question>",
227+
"type": "function",
228+
"function": "<function-to-call-of-last-question>"
229+
}
230+
]
231+
},
232+
{
233+
"role": "tool",
234+
"tool_call_id": "<tool-call-id-of-last-question>",
235+
"content": "<tool-answer-of-last-question>"
236+
}
237+
...
238+
{
239+
"role": "user",
240+
"content": "<question>"
241+
}
242+
]
243+
```

articles/machine-learning/prompt-flow/tools-reference/overview.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ The following table shows an index of tools in prompt flow.
3333
| [Azure OpenAI GPT-4 Turbo with Vision](./azure-open-ai-gpt-4v-tool.md) | Use AzureOpenAI GPT-4 Turbo with Vision model deployment to analyze images and provide textual responses to questions about them. | Default | [promptflow-tools](https://pypi.org/project/promptflow-tools/) |
3434
| [OpenAI GPT-4V](./openai-gpt-4v-tool.md) | Use OpenAI GPT-4V to leverage vision ability. | Default | [promptflow-tools](https://pypi.org/project/promptflow-tools/) |
3535
| [Index Lookup](./index-lookup-tool.md)* | Search an Azure Machine Learning Vector Index for relevant results using one or more text queries. | Default | [promptflow-vectordb](https://pypi.org/project/promptflow-vectordb/) |
36-
| [Faiss Index Lookup](./faiss-index-lookup-tool.md)*<sup>1</sup> | Searches a vector-based query from the Faiss index file. | Default | [promptflow-vectordb](https://pypi.org/project/promptflow-vectordb/) |
37-
| [Vector DB Lookup](./vector-db-lookup-tool.md)*<sup>1</sup>| Searches a vector-based query from existing vector database. | Default | [promptflow-vectordb](https://pypi.org/project/promptflow-vectordb/) |
38-
| [Vector Index Lookup](./vector-index-lookup-tool.md)*<sup>1</sup> | Searches text or a vector-based query from Azure Machine Learning vector index. | Default | [promptflow-vectordb](https://pypi.org/project/promptflow-vectordb/) |
36+
| [Faiss Index Lookup](./faiss-index-lookup-tool.md)* | Searches a vector-based query from the Faiss index file. | Default | [promptflow-vectordb](https://pypi.org/project/promptflow-vectordb/) |
37+
| [Vector DB Lookup](./vector-db-lookup-tool.md)* | Searches a vector-based query from existing vector database. | Default | [promptflow-vectordb](https://pypi.org/project/promptflow-vectordb/) |
38+
| [Vector Index Lookup](./vector-index-lookup-tool.md)* | Searches text or a vector-based query from Azure Machine Learning vector index. | Default | [promptflow-vectordb](https://pypi.org/project/promptflow-vectordb/) |
3939
| [Azure AI Language tools](https://microsoft.github.io/promptflow/integrations/tools/azure-ai-language-tool.html)* | This collection of tools is a wrapper for various Azure AI Language APIs, which can help effectively understand and analyze documents and conversations. The capabilities currently supported include: Abstractive Summarization, Extractive Summarization, Conversation Summarization, Entity Recognition, Key Phrase Extraction, Language Detection, PII Entity Recognition, Conversational PII, Sentiment Analysis, Conversational Language Understanding, Translator. You can learn how to use them by the [Sample flows](https://github.com/microsoft/promptflow/tree/e4542f6ff5d223d9800a3687a7cfd62531a9607c/examples/flows/integrations/azure-ai-language). Support contact: [email protected] | Custom | [promptflow-azure-ai-language](https://pypi.org/project/promptflow-azure-ai-language/) |
4040

41-
_<sup>1</sup> The Index Lookup tool replaces the three deprecated legacy index tools: Vector Index Lookup, Vector DB Lookup, and Faiss Index Lookup. If you have a flow that contains one of those tools, follow the [migration steps](./index-lookup-tool.md#how-to-migrate-from-legacy-tools-to-the-index-lookup-tool) to upgrade your flow._
42-
4341
_*The asterisk marks indicate custom tools, which are created by the community that extend prompt flow's capabilities for specific use cases. They aren't officially maintained or endorsed by prompt flow team. When you encounter questions or issues for these tools, prioritize using the support contact if it's provided in the description._
4442

4543
To discover more custom tools developed by the open-source community, see [More custom tools](https://microsoft.github.io/promptflow/integrations/tools/index.html).

0 commit comments

Comments
 (0)