nonebot-plugin-githubmodels 0.1.7__tar.gz → 0.1.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_githubmodels-0.1.9/LICENSE +19 -0
- {nonebot_plugin_githubmodels-0.1.7 → nonebot_plugin_githubmodels-0.1.9}/PKG-INFO +1 -1
- {nonebot_plugin_githubmodels-0.1.7 → nonebot_plugin_githubmodels-0.1.9}/nonebot_plugin_githubmodels/__init__.py +37 -25
- {nonebot_plugin_githubmodels-0.1.7 → nonebot_plugin_githubmodels-0.1.9}/nonebot_plugin_githubmodels/config.py +2 -1
- {nonebot_plugin_githubmodels-0.1.7 → nonebot_plugin_githubmodels-0.1.9}/pyproject.toml +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2024 lyqgzbl
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
17
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
18
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
19
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import nonebot
|
|
2
|
-
from
|
|
3
|
-
from nonebot import on_command, get_plugin_config, require
|
|
2
|
+
from nonebot import require, get_plugin_config
|
|
4
3
|
require("nonebot_plugin_alconna")
|
|
5
4
|
require("nonebot_plugin_htmlrender")
|
|
6
|
-
from
|
|
7
|
-
from
|
|
5
|
+
from openai import AsyncOpenAI
|
|
6
|
+
from arclet.alconna import Args, Option, Alconna
|
|
8
7
|
from nonebot.plugin import PluginMetadata
|
|
9
|
-
from nonebot_plugin_alconna import UniMessage, Image
|
|
10
8
|
from nonebot_plugin_htmlrender import md_to_pic
|
|
9
|
+
from nonebot_plugin_alconna import UniMessage, on_alconna, Match
|
|
11
10
|
from .config import Config
|
|
12
11
|
|
|
13
12
|
plugin_config = get_plugin_config(Config)
|
|
14
|
-
TOKEN = plugin_config.github_token
|
|
13
|
+
TOKEN = plugin_config.github_token
|
|
15
14
|
MODEL_NAME = plugin_config.ai_model_name
|
|
15
|
+
REPLY_IMAGE = plugin_config.ai_reply_image
|
|
16
16
|
MAX_CONTEXT_LENGTH = plugin_config.max_context_length
|
|
17
17
|
|
|
18
18
|
endpoint = "https://models.inference.ai.azure.com"
|
|
@@ -22,32 +22,42 @@ client = AsyncOpenAI(
|
|
|
22
22
|
)
|
|
23
23
|
shared_context = []
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
ai = on_alconna(
|
|
26
|
+
Alconna(
|
|
27
|
+
"AI",
|
|
28
|
+
Args["user_input?", str],
|
|
29
|
+
Option("-重置|--reset"),
|
|
30
|
+
),
|
|
31
|
+
use_cmd_start=True,
|
|
32
|
+
block=True,
|
|
33
|
+
aliases={"ai"},
|
|
34
|
+
)
|
|
26
35
|
|
|
27
|
-
@
|
|
28
|
-
async def
|
|
36
|
+
@ai.assign("resett")
|
|
37
|
+
async def ai_reset():
|
|
29
38
|
global shared_context
|
|
30
|
-
|
|
39
|
+
shared_context = []
|
|
40
|
+
await ai.finish("上下文已重置")
|
|
41
|
+
|
|
42
|
+
@ai.handle()
|
|
43
|
+
async def handle_function(user_input: Match[str]):
|
|
44
|
+
if user_input.available:
|
|
45
|
+
ai.set_path_arg("user_input", user_input.result)
|
|
31
46
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if not user_input:
|
|
37
|
-
await AI.finish("请输入有效的问题")
|
|
38
|
-
|
|
47
|
+
@ai.got_path("user_input", prompt="请输入有效问题")
|
|
48
|
+
async def got_location(user_input: str):
|
|
49
|
+
global shared_context
|
|
39
50
|
shared_context.append({"role": "user", "content": user_input})
|
|
40
|
-
|
|
41
51
|
if len(shared_context) > MAX_CONTEXT_LENGTH:
|
|
42
52
|
shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
|
|
43
|
-
|
|
53
|
+
|
|
44
54
|
messages = [
|
|
45
55
|
{
|
|
46
56
|
"role": "system",
|
|
47
|
-
"content": "
|
|
57
|
+
"content": "回答尽量简练,请始终用中文回答",
|
|
48
58
|
}
|
|
49
59
|
] + shared_context
|
|
50
|
-
|
|
60
|
+
|
|
51
61
|
response = await client.chat.completions.create(
|
|
52
62
|
messages=messages,
|
|
53
63
|
model=MODEL_NAME,
|
|
@@ -55,14 +65,16 @@ async def handle_function(args: Message = CommandArg()):
|
|
|
55
65
|
max_tokens=500,
|
|
56
66
|
top_p=1,
|
|
57
67
|
)
|
|
58
|
-
|
|
68
|
+
|
|
59
69
|
reply = response.choices[0].message.content
|
|
60
70
|
shared_context.append({"role": "assistant", "content": reply})
|
|
61
71
|
|
|
72
|
+
if REPLY_IMAGE:
|
|
73
|
+
pic = await md_to_pic(md=reply)
|
|
74
|
+
await UniMessage.image(raw=pic).send(reply_to=True)
|
|
75
|
+
else:
|
|
76
|
+
await UniMessage.text(reply).send(reply_to=True)
|
|
62
77
|
|
|
63
|
-
pic = await md_to_pic(md=reply)
|
|
64
|
-
await UniMessage.image(raw=pic).send(reply_to=True)
|
|
65
|
-
|
|
66
78
|
__plugin_meta__ = PluginMetadata(
|
|
67
79
|
name="githubmodels",
|
|
68
80
|
description="API 调用 GitHub Models 的大语言模型",
|