init
This commit is contained in:
45
my_agent_test2.py
Normal file
45
my_agent_test2.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import os
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
from agentscope.agent import ReActAgent
|
||||||
|
from agentscope.formatter import OllamaChatFormatter
|
||||||
|
from agentscope.memory import InMemoryMemory
|
||||||
|
from agentscope.model import OpenAIChatModel
|
||||||
|
from agentscope.tool import ToolResponse, 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")
|
||||||
|
LLAMA_CPP_MODEL_NAME = os.getenv("LLAMA_CPP_MODEL_NAME", "Qwen3.5-35B-A3B-UD-Q8_K_XL.gguf")
|
||||||
|
LLAMA_CPP_API_KEY = os.getenv("LLAMA_CPP_API_KEY", "EMPTY")
|
||||||
|
|
||||||
|
|
||||||
|
async def creating_react_agent() -> None:
|
||||||
|
"""创建一个 ReAct 智能体并运行一个简单任务。"""
|
||||||
|
# 准备工具
|
||||||
|
toolkit = Toolkit()
|
||||||
|
toolkit.register_tool_function(execute_python_code)
|
||||||
|
|
||||||
|
yyp_bot = ReActAgent(
|
||||||
|
name="yyp_bot",
|
||||||
|
sys_prompt="你是一个名为 yyp_bot 的助手",
|
||||||
|
model=OpenAIChatModel(
|
||||||
|
model_name=LLAMA_CPP_MODEL_NAME,
|
||||||
|
api_key=LLAMA_CPP_API_KEY,
|
||||||
|
client_kwargs={"base_url": LLAMA_CPP_BASE_URL}
|
||||||
|
),
|
||||||
|
memory=InMemoryMemory(),
|
||||||
|
formatter=OllamaChatFormatter(),
|
||||||
|
toolkit=toolkit,
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = Msg(
|
||||||
|
name="user",
|
||||||
|
content="你好!yyp_bot,用 Python 运行 Hello World。",
|
||||||
|
role="user",
|
||||||
|
)
|
||||||
|
|
||||||
|
await yyp_bot(msg)
|
||||||
|
|
||||||
|
|
||||||
|
asyncio.run(creating_react_agent())
|
||||||
Reference in New Issue
Block a user