Control the max token length
控制最大令牌长度
要控制生成式大语言模型( LLM)响应的长度,您可以在配置中设置最大令牌限制,或在提示中明确指定所需长度。例如:
"Explain quantum physics in a tweet length message."
在提示中使用变量
为了实现提示的重用并使其更具动态性,可在提示中使用变量,这些变量可根据不同输入进行替换。如表 20 所示,一个提供城市相关信息的提示案例。无需在提示中硬编码城市名称,改用变量即可。变量能节省时间和精力,避免重复劳动。若需在多条提示中使用相同信息,可将其存储于变量中,并在各提示中引用该变量。这在将提示集成到自有应用程序时尤为实用。
提示VARIABLES {city} = "Amsterdam"
PROMPT You are a travel guide. Tell me a fact about the city: {city}
输出阿姆斯特丹是一座美丽的城市,遍布运河、桥梁和狭窄的街道。这是一个因其丰富的历史、文化和夜生活而值得一游的好地方。
表 20. 在提示中使用变量
全站分卷索引 · 34 卷
- 1Introduction
- 2Prompt engineering
- 3LLM output configuration
- 4Sampling controls
- 5Top-K and top-P
- 6Putting it all together
- 7Prompting techniques
- 8One-shot & few-shot
- 9System, contextual and role prompting
- 10System prompting
- 11Role prompting
- 12Contextual prompting
- 13Step-back prompting
- 14Chain of Thought (CoT)
- 15Self-consistency
- 16Tree of Thoughts (ToT)
- 17ReAct (reason & act)
- 18Automatic Prompt Engineering
- 19Code prompting
- 20Prompts for explaining code
- 21Prompts for translating code
- 22Prompts for debugging and reviewing code
- 23What about multimodal prompting?
- 24Design with simplicity
- 25Be specific about the output
- 26Control the max token length
- 27Experiment with input formats and writing styles
- 28Adapt to model updates
- 29JSON Repair
- 30Working with Schemas
- 31Experiment together with other prompt engineers
- 32CoT Best practices
- 33Summary
- 34Endnotes