Spaces:
Build error
Build error
Commit ·
3eb6edd
1
Parent(s): 770c2c5
fix model_choice param
Browse files
translator/__pycache__/agent.cpython-313.pyc
ADDED
|
Binary file (1.37 kB). View file
|
|
|
translator/__pycache__/parse.cpython-313.pyc
ADDED
|
Binary file (3.4 kB). View file
|
|
|
translator/agent.py
CHANGED
|
@@ -1,19 +1,31 @@
|
|
| 1 |
from .parse import parse_csharp
|
| 2 |
from .mapper import load_mapping
|
| 3 |
from .synth import synthesize_cpp, synthesize_blueprint_python
|
|
|
|
|
|
|
| 4 |
|
| 5 |
class TranslationAgent:
|
| 6 |
def __init__(self, mapping_path="mapping_table.json"):
|
| 7 |
self.mapping = load_mapping(mapping_path)
|
| 8 |
|
| 9 |
-
def translate(self, csharp_code: str, target_format="both",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
parsed = parse_csharp(csharp_code)
|
| 11 |
results = {"cpp": "", "blueprint_py": ""}
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
|
|
|
|
|
|
| 16 |
if target_format in ("blueprint", "both"):
|
| 17 |
-
results["blueprint_py"] = synthesize_blueprint_python(parsed, self.mapping,
|
| 18 |
|
| 19 |
return results["cpp"], results["blueprint_py"]
|
|
|
|
| 1 |
from .parse import parse_csharp
|
| 2 |
from .mapper import load_mapping
|
| 3 |
from .synth import synthesize_cpp, synthesize_blueprint_python
|
| 4 |
+
from .llm_client import generate_with_hf, generate_with_openai
|
| 5 |
+
|
| 6 |
|
| 7 |
class TranslationAgent:
|
| 8 |
def __init__(self, mapping_path="mapping_table.json"):
|
| 9 |
self.mapping = load_mapping(mapping_path)
|
| 10 |
|
| 11 |
+
def translate(self, csharp_code: str, target_format="both", model_choice="hf"):
|
| 12 |
+
"""
|
| 13 |
+
Convert Unity C# code into Unreal C++ and/or Blueprint Python.
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
csharp_code: Unity source
|
| 17 |
+
target_format: "cpp", "blueprint", or "both"
|
| 18 |
+
model_choice: "hf" or "openai"
|
| 19 |
+
"""
|
| 20 |
parsed = parse_csharp(csharp_code)
|
| 21 |
results = {"cpp": "", "blueprint_py": ""}
|
| 22 |
|
| 23 |
+
# choose model backend
|
| 24 |
+
backend = "hf" if model_choice == "hf" else "openai"
|
| 25 |
|
| 26 |
+
if target_format in ("cpp", "both"):
|
| 27 |
+
results["cpp"] = synthesize_cpp(parsed, self.mapping, model_backend=backend)
|
| 28 |
if target_format in ("blueprint", "both"):
|
| 29 |
+
results["blueprint_py"] = synthesize_blueprint_python(parsed, self.mapping, model_backend=backend)
|
| 30 |
|
| 31 |
return results["cpp"], results["blueprint_py"]
|
translator/synth.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
from .llm_client import generate_with_hf, generate_with_openai
|
| 2 |
|
| 3 |
-
def synthesize_cpp(parsed: dict, mapping: dict,
|
| 4 |
"""
|
| 5 |
Converts Unity C# parsed structure into Unreal Engine C++ (header + source).
|
| 6 |
"""
|
|
@@ -19,12 +19,15 @@ def synthesize_cpp(parsed: dict, mapping: dict, backend: str = "hf", prompt_cont
|
|
| 19 |
{prompt_context}
|
| 20 |
"""
|
| 21 |
|
| 22 |
-
if
|
| 23 |
-
|
|
|
|
| 24 |
else:
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
prompt = f"""
|
| 29 |
Given this parsed Unity class and mapping rules, produce a Python Editor script using Unreal's Python API
|
| 30 |
that will create a Blueprint Actor in /Game/Blueprints named BP_<ClassName> with:
|
|
@@ -38,7 +41,9 @@ def synthesize_blueprint_python(parsed: dict, mapping: dict, backend: str = "hf"
|
|
| 38 |
Mapping: {mapping}
|
| 39 |
"""
|
| 40 |
|
| 41 |
-
if
|
| 42 |
-
|
|
|
|
| 43 |
else:
|
| 44 |
-
|
|
|
|
|
|
| 1 |
from .llm_client import generate_with_hf, generate_with_openai
|
| 2 |
|
| 3 |
+
def synthesize_cpp(parsed: dict, mapping: dict, prompt_context: str = "", model_backend="hf") -> str:
|
| 4 |
"""
|
| 5 |
Converts Unity C# parsed structure into Unreal Engine C++ (header + source).
|
| 6 |
"""
|
|
|
|
| 19 |
{prompt_context}
|
| 20 |
"""
|
| 21 |
|
| 22 |
+
if model_backend == "openai":
|
| 23 |
+
from .llm_client import generate_with_openai
|
| 24 |
+
return generate_with_openai(prompt, model="gpt-4o-mini")
|
| 25 |
else:
|
| 26 |
+
from .llm_client import generate_with_hf
|
| 27 |
+
return generate_with_hf(prompt, model="mistralai/Mixtral-8x7B-Instruct")
|
| 28 |
|
| 29 |
+
|
| 30 |
+
def synthesize_blueprint_python(parsed: dict, mapping: dict, model_backend="hf") -> str:
|
| 31 |
prompt = f"""
|
| 32 |
Given this parsed Unity class and mapping rules, produce a Python Editor script using Unreal's Python API
|
| 33 |
that will create a Blueprint Actor in /Game/Blueprints named BP_<ClassName> with:
|
|
|
|
| 41 |
Mapping: {mapping}
|
| 42 |
"""
|
| 43 |
|
| 44 |
+
if model_backend == "openai":
|
| 45 |
+
from .llm_client import generate_with_openai
|
| 46 |
+
return generate_with_openai(prompt, model="gpt-4o-mini")
|
| 47 |
else:
|
| 48 |
+
from .llm_client import generate_with_hf
|
| 49 |
+
return generate_with_hf(prompt, model="mistralai/Mixtral-8x7B-Instruct")
|