mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-17 17:51:20 +08:00
chore: initialize
This commit is contained in:
12
dev/plugin_sample/handlers/commands/hello.py
Normal file
12
dev/plugin_sample/handlers/commands/hello.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from astrbot.api.v1.components.command import CommandComponent
|
||||
from astrbot.api.v1.event import AstrMessageEvent, filter
|
||||
from astrbot.api.v1.context import Context
|
||||
|
||||
|
||||
class HelloCommand(CommandComponent):
|
||||
def __init__(self, context: Context):
|
||||
super().__init__(context)
|
||||
|
||||
@filter.command("hello")
|
||||
async def hello(self, event: AstrMessageEvent):
|
||||
yield event.plain_result("Hello, Astrbot!")
|
||||
12
dev/plugin_sample/handlers/listeners/echo.py
Normal file
12
dev/plugin_sample/handlers/listeners/echo.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from astrbot.api.v1.components.listener import ListenerComponent
|
||||
from astrbot.api.v1.event import AstrMessageEvent, filter
|
||||
from astrbot.api.v1.context import Context
|
||||
|
||||
|
||||
class EchoListener(ListenerComponent):
|
||||
def __init__(self, context: Context):
|
||||
super().__init__(context)
|
||||
|
||||
@filter.platform_adapter_type(filter.PlatformAdapterType.ALL)
|
||||
async def on_message(self, event: AstrMessageEvent):
|
||||
yield event.plain_result("Hello, Astrbot!")
|
||||
31
dev/plugin_sample/handlers/tools/hello.py
Normal file
31
dev/plugin_sample/handlers/tools/hello.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from mcp.types import CallToolResult
|
||||
from pydantic import Field
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
from astrbot.api.v1.components.agent.tool import FunctionTool
|
||||
from astrbot.api.v1.components.agent import ContextWrapper, AstrAgentContext
|
||||
|
||||
|
||||
@dataclass
|
||||
class HelloWorldTool(FunctionTool):
|
||||
name: str = "hello_world" # 工具名称
|
||||
description: str = "Say hello to the world." # 工具描述
|
||||
parameters: dict = Field(
|
||||
default_factory=lambda: {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"greeting": {
|
||||
"type": "string",
|
||||
"description": "The greeting message.",
|
||||
},
|
||||
},
|
||||
"required": ["greeting"],
|
||||
}
|
||||
) # 工具参数定义,见 OpenAI 官网或 https://json-schema.org/understanding-json-schema/
|
||||
|
||||
async def call(
|
||||
self, context: ContextWrapper[AstrAgentContext], **kwargs
|
||||
) -> str | CallToolResult:
|
||||
# event 在 context.context.event 中可用
|
||||
greeting = kwargs.get("greeting", "Hello")
|
||||
return f"{greeting}, World!" # 也支持 mcp.types.CallToolResult 类型
|
||||
Reference in New Issue
Block a user