feat: standardize parameters for mine_resource action in AIPlanner to improve error handling and compatibility with LM Studio responses
This commit is contained in:
@@ -43,6 +43,16 @@ ACTION_ALIASES = {
|
||||
"mine": "mine_resource",
|
||||
"research": "start_research",
|
||||
}
|
||||
ORE_ALIASES = {
|
||||
"iron": "iron-ore",
|
||||
"iron ore": "iron-ore",
|
||||
"iron-ore": "iron-ore",
|
||||
"copper": "copper-ore",
|
||||
"copper ore": "copper-ore",
|
||||
"copper-ore": "copper-ore",
|
||||
"coal": "coal",
|
||||
"stone": "stone",
|
||||
}
|
||||
|
||||
|
||||
SYSTEM_PROMPT = """당신은 팩토리오 게임을 순수하게 플레이하는 AI 에이전트입니다.
|
||||
@@ -500,6 +510,7 @@ class AIPlanner:
|
||||
p["x"] = p.get("target_x")
|
||||
if "y" not in p and "target_y" in p:
|
||||
p["y"] = p.get("target_y")
|
||||
return AIPlanner._keep_allowed_keys(p, {"x", "y"})
|
||||
elif action == "place_entity":
|
||||
if "name" not in p and "item" in p:
|
||||
p["name"] = p.get("item")
|
||||
@@ -507,8 +518,50 @@ class AIPlanner:
|
||||
p["x"] = p.get("position_x")
|
||||
if "y" not in p and "position_y" in p:
|
||||
p["y"] = p.get("position_y")
|
||||
return AIPlanner._keep_allowed_keys(p, {"name", "x", "y", "direction"})
|
||||
elif action == "mine_resource":
|
||||
if "ore" not in p:
|
||||
if "resource" in p:
|
||||
p["ore"] = p.get("resource")
|
||||
elif "item" in p:
|
||||
p["ore"] = p.get("item")
|
||||
ore = AIPlanner._normalize_ore_name(p.get("ore", "iron-ore"))
|
||||
try:
|
||||
count = int(p.get("count", 35))
|
||||
except Exception:
|
||||
count = 35
|
||||
if count <= 0:
|
||||
count = 35
|
||||
return {"ore": ore, "count": count}
|
||||
elif action == "craft_item":
|
||||
return AIPlanner._keep_allowed_keys(p, {"item", "count"})
|
||||
elif action == "explore":
|
||||
return AIPlanner._keep_allowed_keys(p, {"direction", "max_steps", "wanted_ores"})
|
||||
elif action == "build_smelting_line":
|
||||
return AIPlanner._keep_allowed_keys(p, {"ore", "x", "y", "furnace_count"})
|
||||
elif action == "place_belt_line":
|
||||
return AIPlanner._keep_allowed_keys(p, {"from_x", "from_y", "to_x", "to_y"})
|
||||
elif action == "insert_to_entity":
|
||||
return AIPlanner._keep_allowed_keys(p, {"x", "y", "item", "count"})
|
||||
elif action == "set_recipe":
|
||||
return AIPlanner._keep_allowed_keys(p, {"x", "y", "recipe"})
|
||||
elif action == "start_research":
|
||||
return AIPlanner._keep_allowed_keys(p, {"tech"})
|
||||
elif action == "wait":
|
||||
return AIPlanner._keep_allowed_keys(p, {"seconds"})
|
||||
return p
|
||||
|
||||
@staticmethod
|
||||
def _keep_allowed_keys(params: dict, allowed: set[str]) -> dict:
|
||||
return {k: v for k, v in params.items() if k in allowed}
|
||||
|
||||
@staticmethod
|
||||
def _normalize_ore_name(value: object) -> str:
|
||||
if not isinstance(value, str):
|
||||
return "iron-ore"
|
||||
key = value.strip().lower()
|
||||
return ORE_ALIASES.get(key, "iron-ore")
|
||||
|
||||
@staticmethod
|
||||
def _ensure_move_before_build_actions(actions: list[dict]) -> list[dict]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user