QChatGPT/pkg/plugin/events.py

171 lines
3.2 KiB
Python
Raw Normal View History

2024-01-29 21:22:27 +08:00
from __future__ import annotations
import typing
import pydantic
import mirai
from ..core import entities as core_entities
2024-01-30 17:24:22 +08:00
from ..provider import entities as llm_entities
2024-01-29 21:22:27 +08:00
class BaseEventModel(pydantic.BaseModel):
"""事件模型基类"""
2024-01-29 21:22:27 +08:00
2024-02-20 11:47:04 +08:00
query: typing.Union[core_entities.Query, None]
"""此次请求的query对象非请求过程的事件时为None"""
2024-01-30 17:24:22 +08:00
2024-01-29 21:22:27 +08:00
class Config:
arbitrary_types_allowed = True
class PersonMessageReceived(BaseEventModel):
"""收到任何私聊消息时"""
launcher_type: str
"""发起对象类型(group/person)"""
launcher_id: int
"""发起对象ID(群号/QQ号)"""
sender_id: int
"""发送者ID(QQ号)"""
message_chain: mirai.MessageChain
class GroupMessageReceived(BaseEventModel):
"""收到任何群聊消息时"""
launcher_type: str
launcher_id: int
sender_id: int
message_chain: mirai.MessageChain
class PersonNormalMessageReceived(BaseEventModel):
"""判断为应该处理的私聊普通消息时触发"""
launcher_type: str
launcher_id: int
sender_id: int
text_message: str
alter: typing.Optional[str] = None
"""修改后的消息文本"""
reply: typing.Optional[list] = None
"""回复消息组件列表"""
class PersonCommandSent(BaseEventModel):
"""判断为应该处理的私聊命令时触发"""
launcher_type: str
launcher_id: int
sender_id: int
command: str
params: list[str]
text_message: str
is_admin: bool
2024-01-30 17:24:22 +08:00
alter: typing.Optional[str] = None
"""修改后的完整命令文本"""
reply: typing.Optional[list] = None
"""回复消息组件列表"""
class GroupNormalMessageReceived(BaseEventModel):
"""判断为应该处理的群聊普通消息时触发"""
launcher_type: str
launcher_id: int
sender_id: int
text_message: str
alter: typing.Optional[str] = None
"""修改后的消息文本"""
reply: typing.Optional[list] = None
"""回复消息组件列表"""
class GroupCommandSent(BaseEventModel):
"""判断为应该处理的群聊命令时触发"""
launcher_type: str
launcher_id: int
sender_id: int
command: str
params: list[str]
text_message: str
is_admin: bool
2024-01-29 21:22:27 +08:00
alter: typing.Optional[str] = None
"""修改后的完整命令文本"""
reply: typing.Optional[list] = None
"""回复消息组件列表"""
2024-01-30 17:24:22 +08:00
class NormalMessageResponded(BaseEventModel):
"""回复普通消息时触发"""
launcher_type: str
launcher_id: int
sender_id: int
session: core_entities.Session
"""会话对象"""
prefix: str
2024-01-30 21:45:17 +08:00
"""回复消息的前缀"""
2024-01-30 17:24:22 +08:00
response_text: str
"""回复消息的文本"""
finish_reason: str
"""响应结束原因"""
funcs_called: list[str]
"""调用的函数列表"""
reply: typing.Optional[list] = None
"""回复消息组件列表"""
class PromptPreProcessing(BaseEventModel):
"""会话中的Prompt预处理时触发"""
session_name: str
default_prompt: list[llm_entities.Message]
"""此对话的情景预设,可修改"""
prompt: list[llm_entities.Message]
"""此对话现有消息记录,可修改"""