mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2025-08-01 03:59:51 +00:00
Nonebot2插件构建准备
This commit is contained in:
40
nonebot_plugin_marshoai/models.py
Normal file
40
nonebot_plugin_marshoai/models.py
Normal file
@ -0,0 +1,40 @@
|
||||
from .util import *
|
||||
|
||||
class MarshoContext:
|
||||
"""
|
||||
Marsho 的上下文类
|
||||
"""
|
||||
def __init__(self):
|
||||
self.contents = {
|
||||
"private": {},
|
||||
"non-private": {}
|
||||
}
|
||||
|
||||
def _get_target_dict(self, is_private):
|
||||
return self.contents["private"] if is_private else self.contents["non-private"]
|
||||
|
||||
def append(self, content, target_id, is_private):
|
||||
"""
|
||||
往上下文中添加消息
|
||||
"""
|
||||
target_dict = self._get_target_dict(is_private)
|
||||
if target_id not in target_dict:
|
||||
target_dict[target_id] = []
|
||||
target_dict[target_id].append(content)
|
||||
|
||||
def reset(self, target_id, is_private):
|
||||
"""
|
||||
重置上下文
|
||||
"""
|
||||
target_dict = self._get_target_dict(is_private)
|
||||
target_dict[target_id].clear()
|
||||
|
||||
def build(self, target_id, is_private):
|
||||
"""
|
||||
构建返回的上下文,其中包括系统消息
|
||||
"""
|
||||
spell = get_prompt()
|
||||
target_dict = self._get_target_dict(is_private)
|
||||
if target_id not in target_dict:
|
||||
target_dict[target_id] = []
|
||||
return [spell] + target_dict[target_id]
|
Reference in New Issue
Block a user