fix(asset-catalog): 修复推理管线并新增README
- 默认模型改为 glm-5.1,API地址改为 coding 套餐端点
- 默认批次大小 20→5,增加 max_tokens=4096
- 优化 prompt 模板,明确要求返回 {"results": [...]} 格式
- 修复全批失败时 ai_inference_metadata 的 KeyError
- 输出目录从 <project>/output/ 统一到 <tool>/outputs/
- 新增 README.md(Pipeline流程、环境变量、CLI参数说明)
This commit is contained in:
@@ -30,9 +30,9 @@ from _common import read_json, write_json, iso_now
|
||||
TAG = "[AIInference]"
|
||||
|
||||
# ---- 配置 ----
|
||||
DEFAULT_API_BASE = "https://open.bigmodel.cn/api/paas/v4"
|
||||
DEFAULT_MODEL = "glm-4-flash"
|
||||
DEFAULT_BATCH_SIZE = 20
|
||||
DEFAULT_API_BASE = "https://open.bigmodel.cn/api/coding/paas/v4"
|
||||
DEFAULT_MODEL = "glm-5.1"
|
||||
DEFAULT_BATCH_SIZE = 5
|
||||
|
||||
# ---- Prompt 模板 ----
|
||||
SYSTEM_PROMPT = """你是一个 UE5 游戏开发助手,专注于为 3D 模型资产提取语义信息。
|
||||
@@ -72,9 +72,9 @@ BATCH_PROMPT_TEMPLATE = """以下是 {category} 类别的 {count} 个 StaticMesh
|
||||
|
||||
{assets_json}
|
||||
|
||||
请为每个资产推断语义信息,返回 JSON 数组。每个元素包含:
|
||||
facing_direction, surface_height_cm, function_description,
|
||||
placement_notes, interaction_hints, plausible_substitutes"""
|
||||
请为每个资产推断语义信息,必须返回如下格式的 JSON 对象:
|
||||
{{"results": [{{"facing_direction": ..., "surface_height_cm": ..., "function_description": ..., "placement_notes": ..., "interaction_hints": [...], "plausible_substitutes": ...}}, ...]}}
|
||||
重要:results 数组必须恰好包含 {count} 个元素,与输入资产一一对应。"""
|
||||
|
||||
|
||||
def _get_api_config():
|
||||
@@ -175,6 +175,7 @@ def _call_glm_api(config: dict, category: str, assets_json: str) -> list:
|
||||
{"role": "user", "content": user_prompt},
|
||||
],
|
||||
temperature=0.1,
|
||||
max_tokens=4096,
|
||||
response_format={"type": "json_object"},
|
||||
)
|
||||
except Exception as e:
|
||||
@@ -321,6 +322,8 @@ def run_inference(
|
||||
if batch_idx < len(batches) - 1:
|
||||
time.sleep(1)
|
||||
|
||||
if "ai_inference_metadata" not in db["metadata"]:
|
||||
db["metadata"]["ai_inference_metadata"] = {}
|
||||
db["metadata"]["ai_inference_metadata"]["completed_at"] = iso_now()
|
||||
write_json(db, output_file)
|
||||
|
||||
@@ -337,7 +340,7 @@ def main():
|
||||
parser = argparse.ArgumentParser(description="GLM API 批量推理 — 资产语义增强")
|
||||
parser.add_argument(
|
||||
"--input", type=str,
|
||||
default=str(_SCRIPT_DIR.parent.parent / "output" / "asset-catalog" / "asset_database.json"),
|
||||
default=str(_SCRIPT_DIR / "outputs" / "asset_database.json"),
|
||||
help="输入 asset_database.json 路径",
|
||||
)
|
||||
parser.add_argument(
|
||||
|
||||
Reference in New Issue
Block a user