nonebot-plugin-githubmodels 0.1.8__tar.gz → 0.2.0__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.
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.1
2
+ Name: nonebot-plugin-githubmodels
3
+ Version: 0.2.0
4
+ Summary: API 调用 GitHub Models 的大语言模型
5
+ Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
6
+ License: MIT
7
+ Author: lyqgzbl
8
+ Author-email: admin@lyqgzbl.com
9
+ Requires-Python: >=3.8,<4.0
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Requires-Dist: nonebot-plugin-alconna (>=0.52.0,<0.53.0)
19
+ Requires-Dist: nonebot-plugin-htmlrender (>=0.3.5,<0.4.0)
20
+ Requires-Dist: nonebot2 (>=2.2.1,<3.0.0)
21
+ Requires-Dist: openai (>=1.44.1,<2.0.0)
22
+ Project-URL: Repository, https://github.com/lyqgzbl/nonebot-plugin-githubmodels
23
+ Description-Content-Type: text/markdown
24
+
25
+ <!-- markdownlint-disable MD033 MD036 MD041 -->
26
+
27
+ <div align="center">
28
+
29
+ <a href="https://v2.nonebot.dev/store">
30
+ <img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
31
+ </a>
32
+
33
+ <p>
34
+ <img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
35
+ </p>
36
+
37
+ # nonebot-plugin-githubmodels
38
+
39
+ _✨ API调用GitHub models大语言模型 ✨_
40
+
41
+ </div>
42
+
43
+ <p align="center">
44
+ <a href="https://raw.githubusercontent.com/kexue-z/nonebot-plugin-heweather/master/LICENSE">
45
+ <img src="https://img.shields.io/github/license/kexue-z/nonebot-plugin-heweather.svg" alt="license">
46
+ </a>
47
+ <a href="https://pypi.org/project/nonebot-plugin-heweather/">
48
+ <img src="https://img.shields.io/pypi/v/nonebot-plugin-heweather" alt="pypi">
49
+ </a>
50
+ <img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
51
+ </p>
52
+
53
+ # 安装
54
+
55
+ 使用nb-cli
56
+ ```shell
57
+ nb plugin install nonebot-plugin-githubmodels
58
+ ```
59
+
60
+ # 指令
61
+
62
+ “AI xxx” 询问AI
63
+ 例如“AI 嗨”
64
+
65
+ ”AI 重置“ 重置上下文记忆
66
+
67
+ # 配置
68
+
69
+ ## 见 [.env.example](https://github.com/lyqgzbl/nonebot-plugin-githubmodels/blob/main/.env.example)
70
+
@@ -0,0 +1,45 @@
1
+ <!-- markdownlint-disable MD033 MD036 MD041 -->
2
+
3
+ <div align="center">
4
+
5
+ <a href="https://v2.nonebot.dev/store">
6
+ <img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
7
+ </a>
8
+
9
+ <p>
10
+ <img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
11
+ </p>
12
+
13
+ # nonebot-plugin-githubmodels
14
+
15
+ _✨ API调用GitHub models大语言模型 ✨_
16
+
17
+ </div>
18
+
19
+ <p align="center">
20
+ <a href="https://raw.githubusercontent.com/kexue-z/nonebot-plugin-heweather/master/LICENSE">
21
+ <img src="https://img.shields.io/github/license/kexue-z/nonebot-plugin-heweather.svg" alt="license">
22
+ </a>
23
+ <a href="https://pypi.org/project/nonebot-plugin-heweather/">
24
+ <img src="https://img.shields.io/pypi/v/nonebot-plugin-heweather" alt="pypi">
25
+ </a>
26
+ <img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
27
+ </p>
28
+
29
+ # 安装
30
+
31
+ 使用nb-cli
32
+ ```shell
33
+ nb plugin install nonebot-plugin-githubmodels
34
+ ```
35
+
36
+ # 指令
37
+
38
+ “AI xxx” 询问AI
39
+ 例如“AI 嗨”
40
+
41
+ ”AI 重置“ 重置上下文记忆
42
+
43
+ # 配置
44
+
45
+ ## 见 [.env.example](https://github.com/lyqgzbl/nonebot-plugin-githubmodels/blob/main/.env.example)
@@ -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("reset")
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,7 +1,8 @@
1
1
  [tool.poetry]
2
2
  name = "nonebot-plugin-githubmodels"
3
- version = "0.1.8"
3
+ version = "0.2.0"
4
4
  description = "API 调用 GitHub Models 的大语言模型"
5
+ readme = "README.md"
5
6
  authors = ["lyqgzbl <admin@lyqgzbl.com>"]
6
7
  license = "MIT"
7
8
  homepage = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels"
@@ -1,22 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: nonebot-plugin-githubmodels
3
- Version: 0.1.8
4
- Summary: API 调用 GitHub Models 的大语言模型
5
- Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
6
- License: MIT
7
- Author: lyqgzbl
8
- Author-email: admin@lyqgzbl.com
9
- Requires-Python: >=3.8,<4.0
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.8
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Classifier: Programming Language :: Python :: 3.13
18
- Requires-Dist: nonebot-plugin-alconna (>=0.52.0,<0.53.0)
19
- Requires-Dist: nonebot-plugin-htmlrender (>=0.3.5,<0.4.0)
20
- Requires-Dist: nonebot2 (>=2.2.1,<3.0.0)
21
- Requires-Dist: openai (>=1.44.1,<2.0.0)
22
- Project-URL: Repository, https://github.com/lyqgzbl/nonebot-plugin-githubmodels