nonebot-plugin-githubmodels 0.1.1__tar.gz → 0.1.4__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.1
3
+ Version: 0.1.4
4
4
  Summary: API 调用 GitHub Models 的 GPT-4o 模型
5
5
  Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
6
6
  License: MIT
@@ -14,6 +14,6 @@ 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
- Requires-Dist: nonebot2 (>=2.0.0,<3.0.0)
17
+ Requires-Dist: nonebot2 (>=2.2.1,<3.0.0)
18
18
  Requires-Dist: openai (>=1.44.1,<2.0.0)
19
19
  Project-URL: Repository, https://github.com/lyqgzbl/nonebot-plugin-githubmodels
@@ -1,20 +1,25 @@
1
1
  import nonebot
2
2
  from openai import AsyncOpenAI
3
3
  from nonebot import on_command
4
+ from nonebot import get_plugin_config
4
5
  from nonebot.adapters import Message
5
6
  from nonebot.params import CommandArg
6
7
  from nonebot.plugin import PluginMetadata
8
+ from .config import Config
9
+
10
+ plugin_config = get_plugin_config(Config)
11
+
12
+ TOKEN = plugin_config.github_token
13
+ MODEL_NAME = plugin_config.ai_model_name
14
+ MAX_CONTEXT_LENGTH = plugin_config.MAX_CONTEXT_LENGTH
7
15
 
8
- config = nonebot.get_driver().config
9
- token = config.github_token
10
16
  endpoint = "https://models.inference.ai.azure.com"
11
- model_name = "gpt-4o-mini"
12
17
  client = AsyncOpenAI(
13
18
  base_url=endpoint,
14
- api_key=token,
19
+ api_key=TOKEN,
15
20
  )
21
+
16
22
  shared_context = []
17
- MAX_CONTEXT_LENGTH = 20 # 上下文最大保留条数
18
23
  AI = on_command("AI", priority=10, block=True)
19
24
 
20
25
  @AI.handle()
@@ -41,7 +46,7 @@ async def handle_function(args: Message = CommandArg()):
41
46
 
42
47
  response = await client.chat.completions.create(
43
48
  messages=messages,
44
- model=model_name,
49
+ model=MODEL_NAME,
45
50
  temperature=1,
46
51
  max_tokens=500,
47
52
  top_p=1,
@@ -54,12 +59,14 @@ async def handle_function(args: Message = CommandArg()):
54
59
  shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
55
60
 
56
61
  await AI.send(reply, reply_message=True)
57
-
58
-
62
+ reply = response.choices[0].message.content
63
+ shared_context.append({"role": "assistant", "content": reply})
64
+
59
65
  __plugin_meta__ = PluginMetadata(
60
66
  name="githubmodels",
61
67
  description="API 调用 GitHub Models 的 GPT-4o 模型",
62
68
  usage="AI",
63
69
  type="application",
64
70
  homepage="https://github.com/lyqgzbl/nonebot-plugin-githubmodels",
71
+ supported_adapters=None,
65
72
  )
@@ -0,0 +1,14 @@
1
+ from typing import Optional
2
+ from pydantic import BaseModel, field_validator
3
+
4
+ class Config(BaseModel):
5
+ github_token: Optional[str] = None
6
+ ai_model_name: str = "gpt-4o-mini"
7
+ MAX_CONTEXT_LENGTH: int = 20
8
+
9
+ @field_validator("MAX_CONTEXT_LENGTH")
10
+ @classmethod
11
+ def check_max_context_length(cls, v: int) -> int:
12
+ if v > 0:
13
+ return v
14
+ raise ValueError("MAX_CONTEXT_LENGTH must be greater than 0")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "nonebot-plugin-githubmodels"
3
- version = "0.1.1"
3
+ version = "0.1.4"
4
4
  description = "API 调用 GitHub Models 的 GPT-4o 模型"
5
5
  authors = ["lyqgzbl <admin@lyqgzbl.com>"]
6
6
  license = "MIT"
@@ -9,7 +9,7 @@ repository = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels"
9
9
 
10
10
  [tool.poetry.dependencies]
11
11
  python = "^3.8"
12
- nonebot2 = "^2.0.0"
12
+ nonebot2 = "^2.2.1"
13
13
  openai = "^1.44.1"
14
14
 
15
15
  [build-system]