You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Prompt-Engineering-Guide/pages/introduction/tips.it.mdx

109 lines
6.4 KiB
Plaintext

1 year ago
# Suggermenti generali per la progettazione di Prompt
Ecco alcuni suggerimenti da tenere a mente durante la progettazione dei tuoi prompt:
### Inizio semplice
Quando si inizia a progettare i prompt, bisogna tenere presente che si tratta di un processo iterativo che richiede molta sperimentazione per ottenere risultati ottimali. L'utilizzo di una semplice strumento come OpenAI o Cohere è un buon punto di partenza.
Si può iniziare con prompt semplici e aggiungere altri elementi e contesti man mano che si punta a ottenere risultati migliori. Per questo motivo è fondamentale modificare i suggerimenti durante il percorso. Leggendo la guida, vedrete molti esempi in cui la specificità, la semplicità e la concisione vi daranno spesso risultati migliori.
Quando si ha un compito importante che coinvolge molte sottoattività diverse, si può cercare di suddividere il compito in sottoattività più semplici e continuare ad aumentare man mano che si ottengono risultati migliori. In questo modo si evita di aggiungere troppa complessità al processo di progettazione del prompt all'inizio.
### Le istruzioni
È possibile progettare prompt efficaci per vari compiti semplici, utilizzando comandi per indicare al modello ciò che si desidera ottenere, come "Scrivi", "Classifica", "Riassumi", "Traduci", "Ordina", ecc.
Tenete presente che dovete anche sperimentare molto per capire cosa funziona meglio. Provate diverse istruzioni con parole chiave, contesti e dati diversi e vedete cosa funziona meglio per il vostro caso d'uso e la vostra attività. Di solito, più il contesto è specifico e rilevante per l'attività che si sta cercando di svolgere, meglio è. Nelle prossime guide parleremo dell'importanza del campionamento e dell'aggiunta di ulteriore contesto.
Altri raccomandano di collocare le istruzioni all'inizio del prompt. Si raccomanda anche di usare un separatore chiaro, come "###", per separare l'istruzione dal contesto.
Per esempio:
*Prompt:*
```
### Istruzione ###
Traduci il seguente testo in spagnolo
Testo: "ciao!"
```
*Output:*
```
¡Hola!
```
### Specificity
Be very specific about the instruction and task you want the model to perform. The more descriptive and detailed the prompt is, the better the results. This is particularly important when you have a desired outcome or style of generation you are seeking. There aren't specific tokens or keywords that lead to better results. It's more important to have a good format and descriptive prompt. In fact, providing examples in the prompt is very effective to get desired output in specific formats.
When designing prompts you should also keep in mind the length of the prompt as there are limitations regarding how long this can be. Thinking about how specific and detailed you should be is something to consider. Including too many unnecessary details is not necessarily a good approach. The details should be relevant and contribute to the task at hand. This is something you will need to experiment with a lot. We encourage a lot of experimentation and iteration to optimize prompts for your applications.
As an example, let's try a simple prompt to extract specific information from a piece of text.
*Prompt:*
```
Extract the name of places in the following text.
Desired format:
Place: <comma_separated_list_of_company_names>
Input: "Although these developments are encouraging to researchers, much is still a mystery. “We often have a black box between the brain and the effect we see in the periphery,” says Henrique Veiga-Fernandes, a neuroimmunologist at the Champalimaud Centre for the Unknown in Lisbon. “If we want to use it in the therapeutic context, we actually need to understand the mechanism.""
```
*Output:*
```
Place: Champalimaud Centre for the Unknown, Lisbon
```
Input text is obtained from [this Nature article](https://www.nature.com/articles/d41586-023-00509-z).
### Avoid Impreciseness
Given the tips above about being detailed and improving format, it's easy to fall into the trap of wanting to be too clever about prompts and potentially creating imprecise descriptions. It's often better to be specific and direct. The analogy here is very similar to effective communication -- the more direct, the more effective the message gets across.
For example, you might be interested in learning the concept of prompt engineering. You might try something like:
```
Explain the concept prompt engineering. Keep the explanation short, only a few sentences, and don't be too descriptive.
```
It's not clear from the prompt above how many sentences to use and what style. You might still somewhat get good responses with the above prompts but the better prompt would be one that is very specific, concise, and to the point. Something like:
```
Use 2-3 sentences to explain the concept of prompt engineering to a high school student.
```
### To do or not to do?
Another common tip when designing prompts is to avoid saying what not to do but say what to do instead. This encourages more specificity and focuses on the details that lead to good responses from the model.
Here is an example of a movie recommendation chatbot failing at exactly what I don't want it to do because of how I wrote the instruction -- focusing on what not to do.
*Prompt:*
```
The following is an agent that recommends movies to a customer. DO NOT ASK FOR INTERESTS. DO NOT ASK FOR PERSONAL INFORMATION.
Customer: Please recommend a movie based on my interests.
Agent:
```
*Output:*
```
Sure, I can recommend a movie based on your interests. What kind of movie would you like to watch? Do you prefer action, comedy, romance, or something else?
```
Here is a better prompt:
*Prompt:*
```
The following is an agent that recommends movies to a customer. The agent is responsible to recommend a movie from the top global trending movies. It should refrain from asking users for their preferences and avoid asking for personal information. If the agent doesn't have a movie to recommend, it should respond "Sorry, couldn't find a movie to recommend today.".
Customer: Please recommend a movie based on my interests.
Agent:
```
*Output:*
```
Sorry, I don't have any information about your interests. However, here's a list of the top global trending movies right now: [list of movies]. I hope you find something you like!
```
Some of the examples above were adopted from the ["Best practices for prompt engineering with OpenAI API" article.](https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api)