赞
踩
基本模型支持文本补全,因此任何未完成的用户提示(没有特殊标签)都会提示模型完成它。
<s>{{ user_prompt }}
系统提示(prompt)是可选的。可有可无。
单个消息的具有可选的 system prompt。
- <s>[INST] <<SYS>>
- {your_system_message}
- <</SYS>>
- {user_message_1} [/INST]
多个user和assistant 消息示例。
- <s>[INST] <<SYS>>
- {your_system_message}
- <</SYS>>
- {user_message_1} [/INST] {model_reply_1}</s><s>[INST] {user_message_2} [/INST]
可在此处找到生成此提示格式的代码。
注意:换行符 (0x0A) 是提示格式的一部分,为了在示例中清晰起见,它们已表示为实际的新行。
<|begin_of_text|>{{ user_message }}
可在此处找到生成此提示格式的代码。
注意:
换行符 (0x0A) 是提示格式的一部分,为了在示例中清晰起见,它们已表示为实际的新行。
该模型期望提示末尾的助手标题开始完成它。
分解带有系统消息的示例 instruct 提示:
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
-
- You are a helpful AI assistant for travel tips and recommendations<|eot_id|><|start_header_id|>user<|end_header_id|>
-
- What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
-
- What is France's capital?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
系统提示以及用户和助手之间的多轮对话
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
-
- You are a helpful AI assistant for travel tips and recommendations<|eot_id|><|start_header_id|>user<|end_header_id|>
-
- What is France's capital?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
- Bonjour! The capital of France is Paris!<|eot_id|><|start_header_id|>user<|end_header_id|>
- What can I do there?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
- Paris, the City of Light, offers a romantic getaway with must-see attractions like the Eiffel Tower and Louvre Museum, romantic experiences like river cruises and charming neighborhoods, and delicious food and drink options, with helpful tips for making the most of your trip.<|eot_id|><|start_header_id|>user<|end_header_id|>
- Give me a detailed list of the attractions I should visit, and time it takes in each one, to plan my trip accordingly.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
除了llama3 prompt模板中使用的标识符, 新增了以下标识符。
<|finetune_right_pad_id|> 此标记用于将一批文本序列填充到相同长度。
<|eom_id|>: 消息结束。消息表示执行的可能停止点,模型可以在此通知执行者需要进行工具调用。这用于模型与任何可用工具之间的多步骤交互。当系统提示中使用 Environment: ipython 指令或模型调用内置工具时,模型会发出此令牌。
<|python_tag|> 是模型响应中用来表示工具调用的特殊标签。
ipython:Llama 3.1 中引入的新角色。从语义上讲,此角色表示“工具”。此角色用于在从执行器发送回模型时使用工具调用的输出来标记消息。
所以现在有以下四个角色。
[system, assistant, user, ipython]
Llama 3.1 Instruct 的版本增加了tool calling功能。
下图是调用工具的流图。
以下提示提供了一个示例,说明如何在系统提示中定义自己的格式并在与模型交互时使用它。此格式将使用新的自定义 <function> 标记将 JSON 对象与函数参数括起来。
注释
由于 Environment: ipython 指令,模型使用 eom_id 令牌。
系统提示定义了自定义格式以及模型可用的工具。
步骤 - 1 用户提示自定义工具详细信息
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
-
-
- Environment: ipython
- Tools: brave_search, wolfram_alpha
-
- Cutting Knowledge Date: December 2023
- Today Date: 23 Jul 2024
-
- # Tool Instructions
- - Always execute python code in messages that you share.
- - When looking for real time information use relevant functions if available else fallback to brave_search
-
-
-
- You have access to the following functions:
-
- Use the function 'spotify_trending_songs' to: Get top trending songs on Spotify
- {
- "name": "spotify_trending_songs",
- "description": "Get top trending songs on Spotify",
- "parameters": {
- "n": {
- "param_type": "int",
- "description": "Number of trending songs to get",
- "required": true
- }
- }
- }
-
-
- If a you choose to call a function ONLY reply in the following format:
- <{start_tag}={function_name}>{parameters}{end_tag}
- where
-
- start_tag => `<function`
- parameters => a JSON dict with the function argument name as key and function argument value as value.
- end_tag => `</function>`
-
- Here is an example,
- <function=example_function_name>{"example_name": "example_value"}</function>
-
- Reminder:
- - Function calls MUST follow the specified format
- - Required parameters MUST be specified
- - Only call one function at a time
- - Put the entire function call reply on one line"
- - Always add your sources when using search results to answer the user query
- You are a helpful Assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>
- Can you check the top 5 trending songs on spotify?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
步骤 - 2 模型确定要调用哪个工具
现在模型根据系统提示中定义的格式做出响应,函数名称位于开始标记中,参数作为 JSON 对象位于开始和结束标记之间。
注意:
由于我们在系统提示中使用 Environment: ipython 指令,模型以 eom_id 令牌结束生成。
<function=spotify_trending_songs>{"n": "5"}</function><eom_id>
步骤 - 3 调用工具的结果被传回模型
当工具调用的结果被发送回模型时,我们在标题中使用新角色 ipython。
- <|begin_of_text|><|start_header_id|>system<|end_header_id|>
-
-
- Environment: ipython
- Tools: brave_search, wolfram_alpha
-
- Cutting Knowledge Date: December 2023
- Today Date: 23 Jul 2024
-
- # Tool Instructions
- - Always execute python code in messages that you share.
- - When looking for real time information use relevant functions if available else fallback to brave_search
-
-
-
- You have access to the following functions:
-
- Use the function 'spotify_trending_songs' to: Get top trending songs on Spotify
- {"name": "spotify_trending_songs", "description": "Get top trending songs on Spotify", "parameters": {"n": {"param_type": "int", "description": "Number of trending songs to get", "required": true}}}
-
-
- If a you choose to call a function ONLY reply in the following format:
- <{start_tag}={function_name}>{parameters}{end_tag}
- where
-
- start_tag => `<function`
- parameters => a JSON dict with the function argument name as key and function argument value as value.
- end_tag => `</function>`
-
- Here is an example,
- <function=example_function_name>{"example_name": "example_value"}</function>
-
- Reminder:
- - Function calls MUST follow the specified format
- - Required parameters MUST be specified
- - Only call one function at a time
- - Put the entire function call reply on one line"
- - Always add your sources when using search results to answer the user query
- You are a helpful Assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>
- Can you check the top 5 trending songs on spotify?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
- <function=spotify_trending_songs>{"n": "5"}</function><|eom_id|><|start_header_id|>ipython<|end_header_id|>
- ["1. BIRDS OF A FEATHER by Billie Eilish", "2. Espresso by Sabrina Carpenter", "3. Please Please Please by Sabrina Carpenter", "4. Not Like Us by Kendrick Lamar", "5. Gata Only by FloyyMenor, Cris Mj"]<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
步骤 - 4 模型生成用户的最终响应
- The top 5 trending songs on Spotify are:
-
- 1. BIRDS OF A FEATHER by Billie Eilish
- 2. Espresso by Sabrina Carpenter
- 3. Please Please Please by Sabrina Carpenter
- 4. Not Like Us by Kendrick Lamar
- 5. Gata Only by FloyyMenor, Cris Mj<|eot_id|>
- System: You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
- User: {prompt}
- Assistant:
参考资料
https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。