Prompts for explaining code
我们先用一个只包含少量文件的测试文件夹试运行,需要将文件名从 filename.txt 重命名为 dra_filename.txt。
- 复制表 16 的输出内容(不含 ```bash ``` text 包裹符号),粘贴到新建文件 “rename_files.sh” 中。
- 打开终端窗口输入:./rename_files.sh。程序会提示输入文件夹名称,例如输入 test 后按回车键。
- 脚本似乎运行正常。您将看到消息:文件重命名成功。当您查看测试文件夹时,会发现
所有文件都被完美重命名为 dra_ 文件名 .txt。
成功了!
代码解释提示
作为开发者,在团队协作时需要阅读他人代码。Gemini 同样能协助这一过程。我们以表 16 的代码输出为例,移除注释后让大语言模型解释其逻辑,参见表 17:
Name1_bash_ 代码解释 Goal编写一个解释 Bash 代码的提示模型gemini-pro 温度n`x0np令牌限制1024
Top‑K 算法Top‑P 采样
N/A1 提示词Explain to me the below Bash code:
``` #!/bin/bash
echo "Enter the folder name: "
read folder_name
if [ ! -d "$folder_name" ]; then echo "Folder does not exist."
exit 1 fi
files=( "$folder_name"/* )
for file in "${files[@]}"; do new_file_name="draft_$(basename "$file")"
mv "$file" "$new_file_name"
done
echo "Files renamed successfully."
``` 输出该 Bash 脚本执行以下任务:
- ** 用户输入 **:
- 使用 `echo` 和 `read` 命令提示用户输入文件夹名称。
输入的文件夹名称将存储在 ŠÀ folder_nameŠÀ ~ 变量中。
- ** 文件夹存在性检查 **:
- 使用 ŠÀ zÐ~ ! ‑d 命令检查指定名称的文件夹是否存在。
“$folder_name”zàŠÀ ~ 条件。若文件夹不存在,则显示错误信息( “ 文件夹不存在。”)并以退出码 1 终止脚本。
Continues next page...
全站分卷索引 · 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