Prompts for translating code
输出3. ** 文件列表 **:
- 使用 ŠÀ 文件 ‚P(“$folder_”) 列出指定文件夹内的所有文件
名称 ”/* )ŠÀ ~ 命令。这会创建一个名为 ŠÀ文件ŠÀ ~ 的数组,包含路径到文件夹中所有文件的路径。
- ** 文件重命名 **:
- 它使用 ŠÀ forŠÀ ~ 循环遍历 ŠÀ 文件ŠÀ ~ 数组中的每个文件。
- 对于每个文件,它使用 ŠÀ new_file_
名称 ‚P”dra _$(basename “$ 文件 ”)” ŠÀ ~ 命令生成一个新的文件名。这个新文件名被创建
通过在原始文件名前添加字符串 “dra_” 来实现。
- 然后使用 ŠÀ mv“$ 文件 ”“$ 新文件名 ”ŠÀ ~ 命令重命名文件,
该命令将文件移动到新的文件名下。
- ** 成功消息 **:
- 在重命名所有文件后,它会显示一条成功消息( “ 文件重命名成功 ”),
以表明重命名操作已成功完成。
表 17. 代码解释提示
代码翻译提示
表 16 中的 bash 代码似乎能正常运行。但若该脚本能提示输入文件名,将更具复用性,理想情况下应作为带界面的独立应用运行。作为起点,Python 比 Bash 更适合开发(网页)应用。大语言模型可协助实现跨语言代码转换,示例见表 18:
Name1_python_ 重命名 _ 文件
| Goal | 编写一个提示词,将Bash代码翻译为Python |
|---|---|
| 模型 | gemini-pro |
| 温度 | n`x0np 令牌限制 1024 |
| Top-K | N/A Top-P 1 |
| 提示 | TranslatethebelowBashcodetoaPythonsnippet. |
```bash #!/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."
``` 输出```python import os import shutil
# Get the folder name from the user folder_name = input("Enter the folder name: ")
# Check if the folder exists if not os.path.isdir(folder_name):
print("Folder does not exist.") exit(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