Редактировать plan_generation.py

This commit is contained in:
Markov Andrey
2026-06-30 21:01:57 +00:00
parent 6353a9421e
commit bf35299f27

View File

@@ -35,19 +35,17 @@ async def generate_plan(
step_description: str, step_description: str,
required_data: str (опционально), required_data: str (опционально),
expected_output: str (опционально). expected_output: str (опционально).
В случае ошибки возвращает пустой список или базовый план. В случае ошибки возвращает пустой список.
""" """
prompt_template = prompts.get("planning") prompt_template = prompts.get("planning")
if not prompt_template: if not prompt_template:
logger.error("Промпт для генерации плана не найден") logger.error("Промпт для генерации плана не найден")
return [] return []
# Формируем полный промпт
# Можно использовать историю для контекста, но для простоты берём только последнее сообщение
context = "" context = ""
if history: if history:
# Берём последние 3 сообщения для контекста
context = "\n".join([f"{msg['role']}: {msg['content']}" for msg in history[-3:]]) context = "\n".join([f"{msg['role']}: {msg['content']}" for msg in history[-3:]])
full_prompt = prompt_template.format(query=query, context=context) full_prompt = prompt_template.format(query=query, context=context)
try: try:
@@ -58,14 +56,10 @@ async def generate_plan(
file_id=None, file_id=None,
temperature=getattr(config, 'planning_temperature', 0.2), temperature=getattr(config, 'planning_temperature', 0.2),
) )
# Ожидаем JSON-список
data = json.loads(response.strip()) data = json.loads(response.strip())
if isinstance(data, list): if isinstance(data, list):
# Проверяем, что каждый элемент содержит step_description
for item in data: for item in data:
if "step_description" not in item: if "step_description" not in item:
logger.warning("План содержит шаг без step_description, игнорируем")
# Можно добавить базовые поля
item["step_description"] = item.get("description", "Неизвестный шаг") item["step_description"] = item.get("description", "Неизвестный шаг")
return data return data
else: else: