流程节点完善
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from functools import lru_cache
|
||||
from typing import Dict, List, Sequence, Set
|
||||
from typing import Any, Dict, List, Sequence, Set
|
||||
|
||||
from .manifest_loader import ManifestPromptLoader
|
||||
|
||||
@@ -23,13 +23,14 @@ class PromptComposer:
|
||||
self._simple_prompt = self.loader.load_text_file("simple_mode_prompt.txt")
|
||||
|
||||
@lru_cache(maxsize=64)
|
||||
def _cached_scene_parts(self, scene_mode: str) -> tuple[str, str, str, str]:
|
||||
# 固定骨架
|
||||
header = self._load_partial("header.txt")
|
||||
required_fields = self._load_partial("required_fields.txt")
|
||||
standard_template = self._load_partial("standard_template.txt")
|
||||
examples = self._load_partial("scene1_examples.txt" if scene_mode == "scene1" else "scene4_examples.txt")
|
||||
return header, required_fields, standard_template, examples
|
||||
def _cached_macro_scene_parts(self, drone_state: str) -> tuple[str, str]:
|
||||
header = self._load_partial("macro_header.txt")
|
||||
template = self._load_partial("template_ground.txt" if drone_state == "on_ground" else "template_air.txt")
|
||||
return header, template
|
||||
|
||||
@lru_cache(maxsize=64)
|
||||
def _cached_micro_scene_parts(self) -> str:
|
||||
return self._load_partial("micro_header.txt")
|
||||
|
||||
def _load_partial(self, file_name: str) -> str:
|
||||
path = os.path.join(self.prompts_dir, "partials", file_name)
|
||||
@@ -87,9 +88,10 @@ class PromptComposer:
|
||||
]
|
||||
)
|
||||
|
||||
def compose(
|
||||
def compose_macro(
|
||||
self,
|
||||
scene_mode: str,
|
||||
drone_state: str,
|
||||
intent_type: str,
|
||||
required_actions: Sequence[str],
|
||||
risk_flags: Sequence[str],
|
||||
@@ -100,11 +102,11 @@ class PromptComposer:
|
||||
user_aug = self._build_user_augmentation(context_blocks)
|
||||
return PromptPackage(system_prompt=self._simple_prompt, user_augmentation=user_aug, allowed_nodes={})
|
||||
|
||||
header, required_fields, standard_template, examples = self._cached_scene_parts(scene_mode)
|
||||
header, template = self._cached_macro_scene_parts(drone_state)
|
||||
selected_nodes = self._slice_nodes(required_actions, risk_flags, scene_mode)
|
||||
node_snippet = self._build_nodes_snippet(selected_nodes)
|
||||
|
||||
parts: List[str] = [header, node_snippet, required_fields, standard_template, examples]
|
||||
parts: List[str] = [header, node_snippet, template]
|
||||
common_rules = self._load_partial("common_rules.txt")
|
||||
if common_rules:
|
||||
parts.append(common_rules)
|
||||
@@ -116,6 +118,19 @@ class PromptComposer:
|
||||
system_prompt = "\n\n".join(p for p in parts if p).strip()
|
||||
return PromptPackage(system_prompt=system_prompt, user_augmentation=self._build_user_augmentation(context_blocks), allowed_nodes=selected_nodes)
|
||||
|
||||
def compose_micro(self, macro_tree: Dict[str, Any], resolved_data: Dict[str, Any], atomic_schema: Dict[str, Any]) -> str:
|
||||
header = self._cached_micro_scene_parts()
|
||||
parts = [
|
||||
header,
|
||||
"## 1. 原宏观骨架树 (macro_tree)",
|
||||
"```json\n" + json.dumps(macro_tree, ensure_ascii=False, indent=2) + "\n```",
|
||||
"## 2. 确切数据字典 (resolved_data)",
|
||||
"```json\n" + json.dumps(resolved_data, ensure_ascii=False, indent=2) + "\n```",
|
||||
"## 3. 原子节点规范 (atomic_schema)",
|
||||
"```json\n" + json.dumps(atomic_schema, ensure_ascii=False, indent=2) + "\n```",
|
||||
]
|
||||
return "\n\n".join(parts)
|
||||
|
||||
def _build_user_augmentation(self, context_blocks: Dict[str, str]) -> str:
|
||||
ordered = [("地点知识", "location"), ("任务模式", "pattern"), ("规则知识", "rules")]
|
||||
chunks: List[str] = []
|
||||
|
||||
Reference in New Issue
Block a user