From 1e58967f54b1a225fd6596b58a3a77866c91721b Mon Sep 17 00:00:00 2001 From: "ye.yp" <1436237912@qq.com> Date: Sat, 14 Mar 2026 02:44:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87=E8=BE=93?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- my_agent_test2.py | 49 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/my_agent_test2.py b/my_agent_test2.py index 9869eee..e056724 100644 --- a/my_agent_test2.py +++ b/my_agent_test2.py @@ -1,12 +1,11 @@ import os import asyncio - -from agentscope.agent import ReActAgent, UserAgent +from agentscope.agent import ReActAgent from agentscope.formatter import OpenAIChatFormatter from agentscope.memory import InMemoryMemory from agentscope.model import OpenAIChatModel -from agentscope.tool import ToolResponse, Toolkit, execute_python_code +from agentscope.tool import Toolkit, execute_python_code from agentscope.message import ImageBlock, Msg, TextBlock, URLSource LLAMA_CPP_BASE_URL = os.getenv("LLAMA_CPP_BASE_URL", "http://yyplab.site:8033/v1") @@ -15,8 +14,6 @@ LLAMA_CPP_API_KEY = os.getenv("LLAMA_CPP_API_KEY", "EMPTY") async def main(): - """创建一个 ReAct 智能体并运行一个简单任务。""" - # 准备工具 toolkit = Toolkit() toolkit.register_tool_function(execute_python_code) @@ -26,22 +23,46 @@ async def main(): model=OpenAIChatModel( model_name=LLAMA_CPP_MODEL_NAME, api_key=LLAMA_CPP_API_KEY, - client_kwargs={"base_url": LLAMA_CPP_BASE_URL} + client_kwargs={"base_url": LLAMA_CPP_BASE_URL}, + stream=True, ), memory=InMemoryMemory(), formatter=OpenAIChatFormatter(), toolkit=toolkit, ) - - user = UserAgent(name="user") - - msg = await user() + while True: - msg = await yyp_bot(msg) - msg = await user(msg) - if msg.get_text_content() == "exit": + user_text = input("请输入问题:").strip() + if user_text == "exit": break -asyncio.run(main()) + image_path = input("请输入图片路径,留空则不发送图片:").strip() + if image_path: + msg = Msg( + name="user", + role="user", + content=[ + TextBlock( + type="text", + text=user_text, + ), + ImageBlock( + type="image", + source=URLSource( + type="url", + url=image_path, + ), + ), + ], + ) + else: + msg = Msg( + name="user", + role="user", + content=user_text, + ) + await yyp_bot(msg) + +asyncio.run(main()) \ No newline at end of file