или « ». Такое поведение затрудняет программную обработку выходных данных LLM.
Я использовал следующие MODEL_SETTINGS, чтобы гарантировать, что LLM генерирует детерминированные и целенаправленные выходные данные:
Код: Выделить всё
MODEL_SETTINGS = {
"temp": 0.0, # Ensures deterministic outputs
"top_p": 0.5, # Focuses on the highest probability tokens
"top_k": 1, # Chooses the top token every time
"repeat_penalty": 2.5, # Penalizes repetitive sequences
}
prompt = (
f"\n"
f"You are an AI system that only outputs JSON objects. Your task is to classify the following email into a predefined JSON format.\n\n"
f"Email details:\n"
f"Subject: \"{subject}\"\n"
f"Sender: \"{sender}\"\n\n"
f"### Output Format\n"
f"Respond only in this JSON format:\n"
f"{{\n"
f" \"Category\": \"\",\n"
f" \"Priority\": \"\",\n"
f" \"RequiresResponse\": \"\"\n"
f"}}\n\n"
f"### Example Response\n"
f"{{\n"
f" \"Category\": \"Work\",\n"
f" \"Priority\": \"Normal\",\n"
f" \"RequiresResponse\": \"No\"\n"
f"}}\n\n"
f"### Important Instructions\n"
f"1. Output *only* a single JSON object in the exact format provided above.\n"
f"2. *Do not include any additional text, comments, explanations, or blank lines.*\n"
f"3. Your response *must* be a valid JSON object with proper capitalization, syntax (double quotes, etc.), and no trailing commas.\n"
f"4. If you cannot classify the email, leave the values blank (e.g., \"Category\": \"\") but maintain the JSON structure.\n\n"
f"Now classify the email:\n"
f"%1\n"
f"\n"
f"%2\n"
)
Код: Выделить всё
{
"Category": "Work",
"Priority": "Normal",
"RequiresResponse": "No"
}
LLM часто выдает ответы с такими вопросами, как:
• Дополнительный текст, пояснения или комментарии.
• Недопустимая структура JSON с отсутствующими кавычками или ключами.
• Ненужные заполнители, такие как
, " " или %1.
Подробнее здесь: https://stackoverflow.com/questions/792 ... prompt-and