nonebot-plugin-githubmodels 0.1.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-githubmodels
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: API 调用 GitHub Models 的大语言模型
5
5
  Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
6
6
  License: MIT
@@ -1,19 +1,16 @@
1
1
  import nonebot
2
- from .config import Config
3
- from nonebot import require
4
- from openai import AsyncOpenAI
5
- from nonebot import on_command
2
+ from nonebot import require, get_plugin_config
6
3
  require("nonebot_plugin_alconna")
7
4
  require("nonebot_plugin_htmlrender")
8
- from nonebot.adapters import Message
9
- from nonebot import get_plugin_config
10
- from nonebot.params import CommandArg
5
+ from openai import AsyncOpenAI
6
+ from arclet.alconna import Args, Option, Alconna
11
7
  from nonebot.plugin import PluginMetadata
12
8
  from nonebot_plugin_htmlrender import md_to_pic
13
- from nonebot_plugin_alconna import UniMessage, Image
9
+ from nonebot_plugin_alconna import UniMessage, on_alconna, Match
10
+ from .config import Config
14
11
 
15
12
  plugin_config = get_plugin_config(Config)
16
- TOKEN = plugin_config.github_token
13
+ TOKEN = plugin_config.github_token
17
14
  MODEL_NAME = plugin_config.ai_model_name
18
15
  REPLY_IMAGE = plugin_config.ai_reply_image
19
16
  MAX_CONTEXT_LENGTH = plugin_config.max_context_length
@@ -25,32 +22,42 @@ client = AsyncOpenAI(
25
22
  )
26
23
  shared_context = []
27
24
 
28
- AI = on_command("AI", priority=10, block=True)
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
+ )
29
35
 
30
- @AI.handle()
31
- async def handle_function(args: Message = CommandArg()):
36
+ @ai.assign("resett")
37
+ async def ai_reset():
32
38
  global shared_context
33
- user_input = args.extract_plain_text().strip()
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)
34
46
 
35
- if user_input.lower() == "重置":
36
- shared_context = []
37
- await AI.finish("上下文已重置")
38
-
39
- if not user_input:
40
- await AI.finish("请输入有效的问题")
41
-
47
+ @ai.got_path("user_input", prompt="请输入有效问题")
48
+ async def got_location(user_input: str):
49
+ global shared_context
42
50
  shared_context.append({"role": "user", "content": user_input})
43
-
44
51
  if len(shared_context) > MAX_CONTEXT_LENGTH:
45
52
  shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
46
-
53
+
47
54
  messages = [
48
55
  {
49
56
  "role": "system",
50
- "content": "回答尽量简练,请始终用中文回答。",
57
+ "content": "回答尽量简练,请始终用中文回答",
51
58
  }
52
59
  ] + shared_context
53
-
60
+
54
61
  response = await client.chat.completions.create(
55
62
  messages=messages,
56
63
  model=MODEL_NAME,
@@ -58,7 +65,7 @@ async def handle_function(args: Message = CommandArg()):
58
65
  max_tokens=500,
59
66
  top_p=1,
60
67
  )
61
-
68
+
62
69
  reply = response.choices[0].message.content
63
70
  shared_context.append({"role": "assistant", "content": reply})
64
71
 
@@ -67,7 +74,7 @@ async def handle_function(args: Message = CommandArg()):
67
74
  await UniMessage.image(raw=pic).send(reply_to=True)
68
75
  else:
69
76
  await UniMessage.text(reply).send(reply_to=True)
70
-
77
+
71
78
  __plugin_meta__ = PluginMetadata(
72
79
  name="githubmodels",
73
80
  description="API 调用 GitHub Models 的大语言模型",
@@ -75,4 +82,4 @@ __plugin_meta__ = PluginMetadata(
75
82
  type="application",
76
83
  homepage="https://github.com/lyqgzbl/nonebot-plugin-githubmodels",
77
84
  supported_adapters=None,
78
- )
85
+ )
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "nonebot-plugin-githubmodels"
3
- version = "0.1.8"
3
+ version = "0.1.9"
4
4
  description = "API 调用 GitHub Models 的大语言模型"
5
5
  authors = ["lyqgzbl <admin@lyqgzbl.com>"]
6
6
  license = "MIT"