From 428c1a70c36169bc138239c166a92c9484621330 Mon Sep 17 00:00:00 2001 From: JiajunLI Date: Mon, 2 Mar 2026 18:59:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E3=80=82?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=A7=86=E8=A7=89=E8=BE=93=E5=85=A5=E5=92=8C?= =?UTF-8?q?=E8=A1=A8=E6=83=85=E7=AE=A1=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..ab2244f --- /dev/null +++ b/main.py @@ -0,0 +1,65 @@ +import asyncio +from typing import Annotated +from autogen_agentchat.agents import AssistantAgent +from autogen_ext.models.openai import OpenAIChatCompletionClient + +# --- 第一部分:模拟表情输出工具 --- +# 以后你接上机器人时,只需要把这里的 print 改成串口发送指令 +async def set_expression( + expression: Annotated[str, "机器人要展示的表情,如:开心、疑惑、难过、待机"], + intensity: Annotated[int, "表情强度 1-10"] = 5 +) -> str: + """ + [模拟 MCP3]:控制机器人头部的表情展示。 + 目前为文字输出模式。 + """ + print(f"\n>>>>>> 🤖 机器人表情更新: 【{expression}】 (强度: {intensity}/10) <<<<<<\n") + return f"已成功切换到 {expression} 模式。" + +# --- 第二部分:配置 VLM 大脑 --- +async def start_simulated_head(): + # 指向你本地的 vLLM/Ollama (localhost:8000) + model_client = OpenAIChatCompletionClient( + model="Qwen/Qwen3-VL-8B-Instruct", # 必须与 vLLM 启动的名称一致 + base_url="http://localhost:8000/v1", + api_key="EMPTY", + model_info={ + "vision": True, + "function_calling": True, + "json_output": True, + "structured_output": True, + "family": "unknown", + "context_length": 4096, + } + ) + + # 定义大脑 + brain = AssistantAgent( + name="RobotBrain", + model_client=model_client, + tools=[set_expression], + system_message="""你是一个有情感的机器人。 + 1. 观察用户的视觉信息(图片描述)。 + 2. 调用 set_expression 工具,通过文字描述你的面部变化。 + 3. 你的回复要自然,像在和老朋友聊天。""" + ) + + # --- 第三部分:模拟交互循环 --- + # 在真实项目中,这里会持续读取摄像头 current_view.jpg + scenarios = [ + "视觉输入:用户 d51 满脸愁容地坐在电脑前,正在处理复杂的代码报错。", + "视觉输入:用户 d51 突然拍了一下桌子,笑了起来,看来 Bug 解决了。" + ] + + for scene in scenarios: + print(f"\n--- 场景模拟: {scene} ---") + + # 运行智能体 + response = await brain.run(task=scene) + + # 打印大脑最终说的话 + print(f"机器人说: {response.messages[-1].content}") + await asyncio.sleep(1) + +if __name__ == "__main__": + asyncio.run(start_simulated_head()) \ No newline at end of file