Как отформатировать краткое приглашение для API завершения чата GPT4?

Я пытаюсь использовать API завершения чата GPT4 для следующего запроса:

      For each situation, describe the intent. Examples:


Situation 1: Devin gets the newspaper.

The intent of Situation 1: Devin intends to read the newspaper.

Situation 2: Jamie works all night.

The intent of Situation 2: Jamie intends to meet a deadline.

Situation 3: Sydney destroys Ryan.

The intent of Situation 3: Sydney intends to punish Ryan.

Situation 4: Lindsay clears her mind.

The intent of Situation 4: Lindsay intends to be ready for a new task.

Situation 5: Rowan wants to start a business.

The intent of Situation 5: Rowan intends to be self sufficient.

Situation 6: Lee ensures Ali’s safety.

The intent of Situation 6: Lee intends to be helpful.

Situation 7: Riley buys lottery tickets.

The intent of Situation 7: Riley intends to become rich.

Situation 8: Alex makes Chris wait.

The intent of Situation 8: Alex intends

Как видите, я хочу завершить предложение, в котором говорится: «Алекс намеревается». Это приглашение интуитивно понятно для API завершения GPT3, где вам нужно было разместить только одно приглашение, содержащее все примеры из нескольких снимков.

Однако я не знаю, как лучше всего выполнять те же запросы с помощью API ChatCompletion GPT4. Я проверил https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb , где они предоставили пример того, как выполнять подсказки с несколькими выстрелами, но мое приглашение не является «разговорным». как вы видете.

Я даже не уверен, влияет ли параметр «имя» на качество результата. Есть ли у кого-нибудь ответ на этот вопрос?

До сих пор я думал о том, чтобы отформатировать мое приглашение следующим образом, как указано в содержимом приведенной выше ссылки:

      messages=[
        {"role": "system", "content": "For each situation, describe the intent. Examples:"},
        {"role": "system", "name":"Situation 1", "content": "Devin gets the newspaper."},
        {"role": "system", "name": "The intent of Situation 1", "content": "Devin intends to read the newspaper."},
        {"role": "system", "name":"Situation 2", "content": "Jamie works all night."},
        {"role": "system", "name": "The intent of Situation 2", "content": "Jamie intends to meet a deadline."},

...
        {"role": "system", "name":"Situation 8", "content": "Alex makes Chris wait."},
        {"role": "user", "name": "The intent of Situation 8", "content": ""},
    ]

Это правильный способ сделать несколько шоу с помощью GPT4 ChatCompletion API? Пожалуйста, дайте мне знать, если у вас есть лучшее решение или объяснение того, почему определенные части моего запроса должны работать.

До сих пор я просто помещал исходное приглашение в один пользовательский контент, как это происходит с API завершения GPT3:

      messages=[
    {"role": "user", "content": "For each situation, describe the intent. Examples:


Situation 1: Devin gets the newspaper.

The intent of Situation 1: Devin intends to read the newspaper.

Situation 2: Jamie works all night.

The intent of Situation 2: Jamie intends to meet a deadline.

Situation 3: Sydney destroys Ryan.

The intent of Situation 3: Sydney intends to punish Ryan.

Situation 4: Lindsay clears her mind.

The intent of Situation 4: Lindsay intends to be ready for a new task.

Situation 5: Rowan wants to start a business.

The intent of Situation 5: Rowan intends to be self sufficient.

Situation 6: Lee ensures Ali’s safety.

The intent of Situation 6: Lee intends to be helpful.

Situation 7: Riley buys lottery tickets.

The intent of Situation 7: Riley intends to become rich.

Situation 8: Alex makes Chris wait.

The intent of Situation 8: Alex intends"}
]

Это действительно работает, но мне было интересно, смогу ли я повысить производительность API, если буду следовать определенной практике.

1 ответ

Я не уверен насчет API ChatCompletions, но знаю, как мало снимков обычно делается для API GPT-4 и GPT4-32K.

На самом деле вы были довольно близки к лучшим практикам для нескольких ударов в своей попытке.

Насколько я знаю, шаблон для лучших практик для нескольких снимков:

      messages=[

{"role":"system","content":"The_Prompt_You_Want_To_Give"},

#Few Shot starts here:

{"role":"user","content":"First_Example_Data_That_We_Send_To_GPT"},
{"role":"assistant","content":"First_Example_Answer_We_Expect"},

{"role":"user","content":"Second_Example_Data_That_We_Send_To_GPT"},
{"role":"assistant","content":"Second_Example_Answer_We_Expect"},

{"role":"user","content":"Third_Example_Data_That_We_Send_To_GPT"},
{"role":"assistant","content":"Third_Example_Answer_We_Expect"},

{"role":"user","content":"Fourth_Example_Data_That_We_Send_To_GPT"},
{"role":"assistant","content":"Fourth_Example_Answer_We_Expect"},
.....


#Finally send the data for which we want GPT to run the prompt and find solution

{"role":"user","content":"Content_We_Want_GPT_To_Process_Based_On_Prompt"}

]

Итак, выше приведен шаблон для Few-Shot с использованием openAI.

Часть, которую вы упустили в своей попытке, — это роль помощника .

Таким образом, решение будет

      messages=[
        {"role": "system", "content": "For each situation, describe the intent. Examples:"},
        {"role": "user", "content": "Devin gets the newspaper."},
        {"role": "assistant", "content": "Devin intends to read the newspaper."},
        {"role": "user",  "content": "Jamie works all night."},
        {"role": "assistant",  "content": "Jamie intends to meet a deadline."},

...
        {"role": "user", "content": "Alex makes Chris wait."},
         ]

Я не совсем уверен в используемом вами параметре «имя», он для меня новый, поэтому я его удалил. Если вы уверены в параметре имени, сохраните его также в теле (сообщениях).

Спасибо

Другие вопросы по тегам