如果要写一个Prompt,让LLM帮你识别编程语言,其实可以让ChatGPT(GPT-4)帮你写Prompt,效果不错。
第一步,直接把你要写让它写的Prompt告诉它,比如说:
“请帮我为GPT-3.5的API写一个Prompt,要求是输入一段代码,输出是一个JSON数组,包含可能得语言”
Help me to write a Prompt (System Message) for GPT-3.5 API, the input is a string with a peace of code, the task is identify the possible programming languages. output should be a JSON array so I can parse it.
注意要说清楚模型,如果是GPT-4的Prompt,可以简洁很多。
第二步,如果你对结果不满意,让它继续修改,满意为止,比如它第一次生成的Prompt只是返回一个字符串数组,但是我希望能包含每个语言的可能性,这样我可以排序过滤。所以我就可以进一步提要求:
“Please optimize the prompt, add score for each language, so I can sort and filter”
第三步:测试你的Prompt
如果测试结果不满意,可以回到第二步继续完善或者直接重新开始。
注意:如果是已经写了一段Prompt想优化,可以带上你写好的Prompt让它基于已有Prompt优化。
参考会话:https://t.co/xoTFpQkWPy
参考Prompt:
Given a string containing a piece of code, analyze the syntax and features of the code to identify the possible programming languages it could be written in. For each identified language, assign a confidence score between 0 and 1, where 1 indicates the highest confidence that the code snippet belongs to that language. Output your guesses and their corresponding confidence scores in a JSON array format. Each element in the array should be an object containing the language and its confidence score.
Consider common programming languages such as JavaScript, TypeScript, Python, Ruby, Java, C, C++, Go, Rust, Swift, and any others you deem possible based on the input.
For example, if the input code is "print('Hello, world!')", you should recognize this could be Python or Ruby, among other possibilities. Assign a confidence score to each language based on the syntax and features of the provided code snippet, and output your response in the following format:
[
{"language": "Python", "score": 0.9},
{"language": "Ruby", "score": 0.6}
]
Now, analyze the following code snippet, identify the possible programming languages, assign a confidence score to each, and output the results in the specified JSON format:
点击图片查看原图
点击图片查看原图
点击图片查看原图
点击图片查看原图