Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ from langchain_core.utils.utils import secret_from_env
|
|
| 22 |
from io import BytesIO
|
| 23 |
from pathlib import Path
|
| 24 |
import os
|
| 25 |
-
from utils.block_relation_builder import block_builder, separate_scripts, transform_logic_to_action_flow#, variable_adder_main
|
| 26 |
from langchain.chat_models import ChatOpenAI
|
| 27 |
from langchain_openai import ChatOpenAI
|
| 28 |
from pydantic import Field, SecretStr
|
|
@@ -1017,6 +1017,12 @@ def node_optimizer(state: GameState):
|
|
| 1017 |
refined_logic_data = raw.get("refined_logic", {})
|
| 1018 |
sprite_name = refined_logic_data.get("name_variable", "<unknown>")
|
| 1019 |
pseudo = refined_logic_data.get("pseudocode", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1020 |
try:
|
| 1021 |
refined_logic_data["pseudocode"] = separate_scripts(str(pseudo))
|
| 1022 |
# Step 4: If you want to update the `state` dictionary with the new refined_logic_data
|
|
@@ -1024,6 +1030,28 @@ def node_optimizer(state: GameState):
|
|
| 1024 |
print(f"[The pseudo_code generated here]: { state['pseudo_code']}")
|
| 1025 |
state["action_plan"] = transform_logic_to_action_flow(state["pseudo_code"])
|
| 1026 |
print(f"[The action plan generated here]: { state['action_plan']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1027 |
return state
|
| 1028 |
except Exception as e:
|
| 1029 |
logger.error(f"Error in Node Optimizer Node: {e}")
|
|
|
|
| 22 |
from io import BytesIO
|
| 23 |
from pathlib import Path
|
| 24 |
import os
|
| 25 |
+
from utils.block_relation_builder import block_builder, separate_scripts, transform_logic_to_action_flow, analyze_opcode_counts#, variable_adder_main
|
| 26 |
from langchain.chat_models import ChatOpenAI
|
| 27 |
from langchain_openai import ChatOpenAI
|
| 28 |
from pydantic import Field, SecretStr
|
|
|
|
| 1017 |
refined_logic_data = raw.get("refined_logic", {})
|
| 1018 |
sprite_name = refined_logic_data.get("name_variable", "<unknown>")
|
| 1019 |
pseudo = refined_logic_data.get("pseudocode", "")
|
| 1020 |
+
sprite_name = {}
|
| 1021 |
+
project_json_targets = state.get("project_json", {}).get("targets", [])
|
| 1022 |
+
for target in project_json_targets:
|
| 1023 |
+
sprite_name[target["name"]] = target["name"]
|
| 1024 |
+
action_flow = state.get("action_plan", {})
|
| 1025 |
+
|
| 1026 |
try:
|
| 1027 |
refined_logic_data["pseudocode"] = separate_scripts(str(pseudo))
|
| 1028 |
# Step 4: If you want to update the `state` dictionary with the new refined_logic_data
|
|
|
|
| 1030 |
print(f"[The pseudo_code generated here]: { state['pseudo_code']}")
|
| 1031 |
state["action_plan"] = transform_logic_to_action_flow(state["pseudo_code"])
|
| 1032 |
print(f"[The action plan generated here]: { state['action_plan']}")
|
| 1033 |
+
|
| 1034 |
+
action_flow = state.get("action_plan", {})
|
| 1035 |
+
if action_flow.get("action_overall_flow", {}) == {}:
|
| 1036 |
+
plan_data = action_flow.items()
|
| 1037 |
+
else:
|
| 1038 |
+
plan_data = action_flow.get("action_overall_flow", {}).items()
|
| 1039 |
+
|
| 1040 |
+
refined_flow: Dict[str, Any] = {}
|
| 1041 |
+
for sprite, sprite_data in plan_data:
|
| 1042 |
+
refined_plans = []
|
| 1043 |
+
for plan in sprite_data.get("plans", []):
|
| 1044 |
+
logic = plan.get("logic", "")
|
| 1045 |
+
plan["opcode_counts"]= analyze_opcode_counts(str(logic))
|
| 1046 |
+
refined_plans.append(plan)
|
| 1047 |
+
refined_flow[sprite] = {
|
| 1048 |
+
"description": sprite_data.get("description", ""),
|
| 1049 |
+
"plans": refined_plans
|
| 1050 |
+
}
|
| 1051 |
+
if refined_flow:
|
| 1052 |
+
state["action_plan"] = refined_flow
|
| 1053 |
+
logger.info("Node Optimization completed.")
|
| 1054 |
+
|
| 1055 |
return state
|
| 1056 |
except Exception as e:
|
| 1057 |
logger.error(f"Error in Node Optimizer Node: {e}")
|