Prompt engineering: Difference between revisions

Line 7: Line 7:
Genearte [[code]] using [[models]] like the [[OpenAI Codex]].
Genearte [[code]] using [[models]] like the [[OpenAI Codex]].


#Describe the task - tell the model what you want it to do at a high level.
#Describe the task - tell the [[coding model]] what you want it to do at a high level.
#Describe the context - describe background information like API hints and database schema to help the model understand the task.
#Describe the context - describe background information like API hints and database schema to help the model understand the task.
#Show examples - show the model examples of what you want.
#Show examples - show the model examples of what you want.


===Task===
===Task===
Give the model a high level task description. To improve the quality of the generated code, it's recommended to start the prompt with a broad description of the task at hand. For example, if you want to generate Python code to plot data from a standard dataset, you can provide a prompt like this: "# Load iris data from scikit-learn datasets and plot the training data." However, sometimes the generated code may not be optimal, in which case you can provide more specific instructions such as importing libraries before using them. By combining a high-level task description with detailed user instructions, you can create a more effective prompt for Codex to generate code.
Give the coding model a high-level task description. To improve the quality of the generated code, it's recommended to start the prompt with a broad description of the task at hand. For example, if you want to generate Python code to plot data from a standard [[dataset]], you can provide a prompt like this:  
 
<code># Load iris data from scikit-learn datasets and plot the training data.</div>
 
However, sometimes the generated code may not be optimal, in which case you can provide more specific instructions such as importing libraries before using them. By combining a high-level task description with detailed user instructions, you can create a more effective prompt for coding model to generate code.


===Examples===
===Examples===
Gives the model examples. Imagine you prefer a unique style of writing Python code that differs from what model produces. Take, for instance, when adding two numbers, you prefer to label the arguments differently. The key to working with models like Codex is to clearly communicate what you want it to do. One effective way to do this is to provide examples for Codex to learn from and strive to match its output to your preferred style. If you give Codex a longer prompt that includes the example mentioned, it will then name the arguments in the same manner as in the example.
Gives the coding model examples. Imagine you prefer a unique style of writing Python code that differs from what model produces. Take, for instance, when adding two numbers, you prefer to label the arguments differently. The key to working with models like Codex is to clearly communicate what you want it to do. One effective way to do this is to provide examples for Codex to learn from and strive to match its output to your preferred style. If you give the model a longer prompt that includes the example mentioned, it will then name the arguments in the same manner as in the example.


See also [[zero shot, one shot and few shot learning]]
See also [[zero shot, one shot and few shot learning]]
Line 22: Line 26:
If you want to use a library that the coding model is not familiar with, you can guide it by describing the API library beforehand.
If you want to use a library that the coding model is not familiar with, you can guide it by describing the API library beforehand.


For instance, the Minecraft Codex sample uses the Simulated Player API in TypeScript to control a character in the game. Since this is a newer API that Codex does not know about yet, let's see how it generates code for it. When given the prompt, Codex attempts to make an educated guess based on the terms "bot" and "Simulated Player". However, the resulting code is not correct.
For instance, the Minecraft Codex sample uses the Simulated Player API in TypeScript to control a character in the game. Since this is a newer API that the model does not know about yet, When given the prompt, the model attempts to make an educated guess based on the terms "bot" and "Simulated Player". However, the resulting code is not correct.


To correct this, you can show Codex the API definition, including function signatures and examples, so that it can generate code that follows the API correctly. As demonstrated in the example, by providing high-level context in the form of the API definition and examples, Codex can understand what you want it to do and generate more accurate code.
To correct this, you can show the model model the API definition, including function signatures and examples, so that it can generate code that follows the API correctly. As demonstrated in the example, by providing high-level context in the form of the API definition and examples, the model can understand what you want it to do and generate more accurate code.


==How to Create Descriptive, Poetic Text==
==How to Create Descriptive, Poetic Text==
370

edits