nonebot-plugin-githubmodels 0.1.5__tar.gz → 0.1.8__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,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,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-githubmodels
3
- Version: 0.1.5
4
- Summary: API 调用 GitHub Models 的 GPT-4o 模型
3
+ Version: 0.1.8
4
+ Summary: API 调用 GitHub Models 的大语言模型
5
5
  Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
6
6
  License: MIT
7
7
  Author: lyqgzbl
@@ -14,6 +14,9 @@ Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
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)
17
20
  Requires-Dist: nonebot2 (>=2.2.1,<3.0.0)
18
21
  Requires-Dist: openai (>=1.44.1,<2.0.0)
19
22
  Project-URL: Repository, https://github.com/lyqgzbl/nonebot-plugin-githubmodels
@@ -1,16 +1,21 @@
1
1
  import nonebot
2
+ from .config import Config
3
+ from nonebot import require
2
4
  from openai import AsyncOpenAI
3
5
  from nonebot import on_command
4
- from nonebot import get_plugin_config
6
+ require("nonebot_plugin_alconna")
7
+ require("nonebot_plugin_htmlrender")
5
8
  from nonebot.adapters import Message
9
+ from nonebot import get_plugin_config
6
10
  from nonebot.params import CommandArg
7
11
  from nonebot.plugin import PluginMetadata
8
- from .config import Config
12
+ from nonebot_plugin_htmlrender import md_to_pic
13
+ from nonebot_plugin_alconna import UniMessage, Image
9
14
 
10
15
  plugin_config = get_plugin_config(Config)
11
-
12
16
  TOKEN = plugin_config.github_token
13
17
  MODEL_NAME = plugin_config.ai_model_name
18
+ REPLY_IMAGE = plugin_config.ai_reply_image
14
19
  MAX_CONTEXT_LENGTH = plugin_config.max_context_length
15
20
 
16
21
  endpoint = "https://models.inference.ai.azure.com"
@@ -18,19 +23,21 @@ client = AsyncOpenAI(
18
23
  base_url=endpoint,
19
24
  api_key=TOKEN,
20
25
  )
21
-
22
26
  shared_context = []
27
+
23
28
  AI = on_command("AI", priority=10, block=True)
24
29
 
25
30
  @AI.handle()
26
31
  async def handle_function(args: Message = CommandArg()):
27
32
  global shared_context
28
33
  user_input = args.extract_plain_text().strip()
34
+
29
35
  if user_input.lower() == "重置":
30
36
  shared_context = []
31
- await AI.finish("上下文已重置。请开始新的对话。")
37
+ await AI.finish("上下文已重置")
38
+
32
39
  if not user_input:
33
- await AI.finish("请输入有效的问题。")
40
+ await AI.finish("请输入有效的问题")
34
41
 
35
42
  shared_context.append({"role": "user", "content": user_input})
36
43
 
@@ -54,17 +61,16 @@ async def handle_function(args: Message = CommandArg()):
54
61
 
55
62
  reply = response.choices[0].message.content
56
63
  shared_context.append({"role": "assistant", "content": reply})
57
-
58
- if len(shared_context) > MAX_CONTEXT_LENGTH:
59
- shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
60
-
61
- await AI.send(reply, reply_message=True)
62
- reply = response.choices[0].message.content
63
- shared_context.append({"role": "assistant", "content": reply})
64
-
64
+
65
+ if REPLY_IMAGE:
66
+ pic = await md_to_pic(md=reply)
67
+ await UniMessage.image(raw=pic).send(reply_to=True)
68
+ else:
69
+ await UniMessage.text(reply).send(reply_to=True)
70
+
65
71
  __plugin_meta__ = PluginMetadata(
66
72
  name="githubmodels",
67
- description="API 调用 GitHub Models 的 GPT-4o 模型",
73
+ description="API 调用 GitHub Models 的大语言模型",
68
74
  usage="AI",
69
75
  type="application",
70
76
  homepage="https://github.com/lyqgzbl/nonebot-plugin-githubmodels",
@@ -4,4 +4,5 @@ from pydantic import BaseModel, Field
4
4
  class Config(BaseModel):
5
5
  github_token: Optional[str] = None
6
6
  ai_model_name: str = "gpt-4o-mini"
7
- max_context_length: int = Field(20, gt=0)
7
+ max_context_length: int = Field(20, gt=0)
8
+ ai_reply_image: bool = False
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "nonebot-plugin-githubmodels"
3
- version = "0.1.5"
4
- description = "API 调用 GitHub Models 的 GPT-4o 模型"
3
+ version = "0.1.8"
4
+ description = "API 调用 GitHub Models 的大语言模型"
5
5
  authors = ["lyqgzbl <admin@lyqgzbl.com>"]
6
6
  license = "MIT"
7
7
  homepage = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels"
@@ -11,6 +11,8 @@ repository = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels"
11
11
  python = "^3.8"
12
12
  nonebot2 = "^2.2.1"
13
13
  openai = "^1.44.1"
14
+ nonebot-plugin-htmlrender = "^0.3.5"
15
+ nonebot-plugin-alconna = "^0.52.0"
14
16
 
15
17
  [build-system]
16
18
  requires = ["poetry-core>=1.0.0"]
@@ -18,5 +20,5 @@ build-backend = "poetry.core.masonry.api"
18
20
 
19
21
  [tool.nonebot.plugin]
20
22
  name = "githubmodels"
21
- description = "API 调用 GitHub Models 的 GPT-4o 模型"
23
+ description = "API 调用 GitHub Models 的大语言模型"
22
24
  type = "application"