Skip to content

Commit 3058fcb

Browse files
使用SuggarChat新写法重构
1 parent 73642f1 commit 3058fcb

File tree

6 files changed

+2109
-1038
lines changed

6 files changed

+2109
-1038
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
- SuggarChat 框架
4949
- 支持的LLM服务(如OpenAI、Anthropic等)
5050

51-
### 使用pip安装(推荐)
51+
### 使用nb-cli安装(推荐)
5252

5353
```bash
54-
pip install nonebot-plugin-omikuji
54+
nb plugin install nonebot-plugin-omikuji
5555
```
5656

5757
### 使用uv安装

nonebot_plugin_omikuji/llm_tool.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
from nonebot import get_bot, logger
44
from nonebot.adapters.onebot.v11 import MessageEvent
55
from nonebot_plugin_suggarchat.API import (
6-
FunctionDefinitionSchema,
7-
FunctionParametersSchema,
8-
FunctionPropertySchema,
96
ToolContext,
107
ToolData,
11-
ToolFunctionSchema,
128
)
139

1410
from nonebot_plugin_omikuji.cache import cache_omikuji, get_cached_omikuji
1511

1612
from .config import get_config
17-
from .models import OMIKUJI_THEMES, OmikujiData
13+
from .models import FUNC_META, OmikujiData
1814
from .utils import generate_omikuji
1915

2016
LEVEL = ["大吉", "吉", "中吉", "小吉", "末吉", "凶", "大凶"]
@@ -58,23 +54,4 @@ async def omikuji(ctx: ToolContext):
5854
ctx.matcher.cancel_nonebot_process()
5955

6056

61-
FUNC_META = ToolFunctionSchema(
62-
strict=True,
63-
function=FunctionDefinitionSchema(
64-
name="御神签(omikuji)",
65-
description="抽取一个御神签",
66-
parameters=FunctionParametersSchema(
67-
type="object",
68-
properties={
69-
"theme": FunctionPropertySchema(
70-
type="string",
71-
description="御神签主题(如果包含不良内容则随机选择)",
72-
enum=OMIKUJI_THEMES,
73-
)
74-
},
75-
required=["theme"],
76-
),
77-
),
78-
)
79-
8057
TOOL_DATA = ToolData(data=FUNC_META, func=omikuji, custom_run=True)

nonebot_plugin_omikuji/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ class OmikujiData(BaseModel):
125125
)
126126

127127
FUNC_META = ToolFunctionSchema(
128-
strict=False,
128+
strict=True,
129129
function=FunctionDefinitionSchema(
130-
name="御神签(omikuji)",
130+
name="omikuji",
131131
description="抽取一个御神签",
132132
parameters=FunctionParametersSchema(
133133
type="object",

nonebot_plugin_omikuji/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
config_manager,
99
tools_caller,
1010
)
11+
from nonebot_plugin_suggarchat.utils.models import Message
1112

1213
from .cache import OmikujiCacheData
1314
from .config import get_config
@@ -66,14 +67,17 @@ async def generate_omikuji(
6667
if cache := await _hit_cache_omikuji(theme, level):
6768
return cache
6869
logger.debug(f"theme: {theme}, level: {level} Cache miss")
69-
system_prompt = deepcopy(
70-
config_manager.group_train if is_group else config_manager.private_train
70+
system_prompt = Message.model_validate(
71+
deepcopy(
72+
config_manager.group_train if is_group else config_manager.private_train
73+
)
74+
)
75+
assert isinstance(system_prompt.content, str)
76+
system_prompt.content += "\n你现在需要结合你的角色设定生成御神签。"
77+
user_prompt = Message(
78+
role="user",
79+
content=f"御神签的运势是:'{level}'\n现在生成一张主题为:'{theme}'的御神签",
7180
)
72-
system_prompt["content"] += "\n你现在需要结合你的角色设定生成御神签。"
73-
user_prompt = {
74-
"role": "user",
75-
"content": f"御神签的运势是:'{level}'\n现在生成一张主题为:'{theme}'的御神签",
76-
}
7781
msg_input = [system_prompt, user_prompt]
7882
data = await tools_caller(
7983
messages=msg_input, tools=[OMIKUJI_SCHEMA_META], tool_choice="required"

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "nonebot-plugin-omikuji"
3-
version = "0.1.0.post1"
3+
version = "0.1.1"
44
description = "Nonebot2的御神签插件"
55
readme = "README.md"
66
requires-python = ">=3.10, <4.0"
@@ -11,6 +11,7 @@ dependencies = [
1111
"nonebot-plugin-localstore>=0.7.4",
1212
"aiofiles>=24.1.0",
1313
"nonebot-plugin-orm>=0.8.2",
14+
"zipp>=3.23.0",
1415
]
1516
license = "GPL-3.0-or-later"
1617
keywords = ['chat", "suggar", "nonebot']

0 commit comments

Comments
 (0)