65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
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()) |