新增画布对话助手
This commit is contained in:
0
src/server/canvas_assistant/__init__.py
Executable file
0
src/server/canvas_assistant/__init__.py
Executable file
74
src/server/canvas_assistant/graph.py
Executable file
74
src/server/canvas_assistant/graph.py
Executable file
@@ -0,0 +1,74 @@
|
||||
from langgraph.graph import StateGraph, START, END
|
||||
from langgraph.graph.message import MessagesState
|
||||
from langchain_core.messages import AIMessage
|
||||
|
||||
# ====================== 中英文固定文案 ======================
|
||||
PROMPTS = {
|
||||
# 中文
|
||||
"welcome_zh": "Hi,我是你的设计助手 Fiphant 👋 我来帮你快速上手这个画布。我给你准备了两个起点——你可以用 To Real Style 直接把草图变成效果图,也可以先用 Surface Edit 换个材质或贴上印花。有了产品图之后,我们再一起配色、配场景、看 3D 效果,最后导出三视图就完成了。我建议先从 To Real Style 开始,看看整体感觉 ✨",
|
||||
|
||||
"to_real_style_zh": "To Real Style 🎨 这个功能我很喜欢——你只需要把草图丢进来,我来帮你把光影和材质都处理好,直接生成真实感效果图。出来不满意的话就多试几次,每次我都会给你不一样的结果。",
|
||||
"surface_edit_canvas_zh": "Surface Edit(Canvas 模式) 🪡 如果你对材质有具体想法,可以用这个模式来做。布艺、皮革、木材这些都可以换,也可以把你自己的印花上传进来。这个模式支持你手动精细编辑,想细调哪里都可以。",
|
||||
"surface_edit_ai_zh": "Surface Edit(AI 模式) 🪡 想快速看看换材质之后的效果?用这个模式,把你想要的材质或印花告诉我,AI 智能贴图帮你一步到位。如果觉得还想再调整细节,随时可以切换到 Canvas 模式继续编辑。",
|
||||
"color_palette_zh": "Color Palette 🎨 配色交给我来帮你——你选几种喜欢的颜色,我来帮你搭配应用到产品上。我可以一次给你生成好几个方案,你对比着挑就好。",
|
||||
"scene_composition_zh": "Scene Composition 🛋️ 我来帮你把产品放进一个真实的空间场景里,光影我会自动帮你匹配。我的建议是先出一张背景干净的主图,再出一张有生活感的氛围图,两张配合着用,展示效果会好很多。",
|
||||
"3d_model_zh": "3D Model 🔄 我把你的效果图变成可以转着看的立体模型,你可以从各个角度检查一下结构。我建议重点看看转角、腿脚比例和座面厚度——这几个地方在草图里不容易发现问题,但打样的时候最容易出偏差,现在发现比较好改。",
|
||||
"to_3d_view_zh": "To 3D View 📐 我们到最后一步了!我来帮你把 3D 模型导出为前视图、侧视图和俯视图!",
|
||||
|
||||
# English
|
||||
"welcome_en": "Hi, I'm Fiphant, your design assistant 👋 I'm here to help you get started with the canvas. My suggestion: start with To Real Style ✨",
|
||||
|
||||
"to_real_style_en": "To Real Style 🎨 This is one of my favorite features — just drop in your sketch and I'll handle the lighting and materials to create a photorealistic render.",
|
||||
"surface_edit_canvas_en": "Surface Edit (Canvas Mode) 🪡 Perfect for precise material control. You can swap fabrics, leather, wood, or upload your own prints.",
|
||||
"surface_edit_ai_en": "Surface Edit (AI Mode) 🪡 Want quick material preview? Tell me what you want and I'll apply it instantly with AI.",
|
||||
"color_palette_en": "Color Palette 🎨 Let me handle the colors for you. Pick your favorite colors and I'll generate multiple schemes.",
|
||||
"scene_composition_en": "Scene Composition 🛋️ I'll place your product in a real scene with matching lighting.",
|
||||
"3d_model_en": "3D Model 🔄 I'll turn your render into a rotatable 3D model. Check corners, leg proportions, and seat thickness carefully.",
|
||||
"to_3d_view_en": "To 3D View 📐 Final step! I'll export your 3D model as front, side, and top views."
|
||||
}
|
||||
|
||||
|
||||
class AgentState(MessagesState):
|
||||
trigger: str | None = None
|
||||
language: str = "zh"
|
||||
is_first_enter: bool = True # 新增标志位,控制是否输出欢迎语
|
||||
|
||||
|
||||
# ==================== Nodes ====================
|
||||
def assistant_node(state: AgentState):
|
||||
"""路由节点:判断是进入画布还是点击工具"""
|
||||
if state.get("is_first_enter", True):
|
||||
# 第一次进入画布
|
||||
lang = state.get("language", "zh")
|
||||
key = f"welcome_{lang}"
|
||||
content = PROMPTS.get(key, PROMPTS["welcome_zh"])
|
||||
return {
|
||||
"messages": [AIMessage(content=content)],
|
||||
"is_first_enter": False
|
||||
}
|
||||
else:
|
||||
# 点击工具
|
||||
trigger = state.get("trigger")
|
||||
lang = state.get("language", "zh")
|
||||
|
||||
if trigger:
|
||||
key = f"{trigger}_{lang}"
|
||||
content = PROMPTS.get(key, "功能说明加载中...")
|
||||
else:
|
||||
content = "请点击工具让我为你说明用法。" if lang == "zh" else "Please click a tool for instructions."
|
||||
|
||||
return {
|
||||
"messages": [AIMessage(content=content)],
|
||||
"is_first_enter": False
|
||||
}
|
||||
|
||||
|
||||
# ==================== Graph ====================
|
||||
workflow = StateGraph(state_schema=AgentState)
|
||||
|
||||
workflow.add_node("assistant", assistant_node)
|
||||
|
||||
workflow.add_edge(START, "assistant")
|
||||
workflow.add_edge("assistant", END)
|
||||
|
||||
graph = workflow.compile()
|
||||
Reference in New Issue
Block a user