nonebot-plugin-githubmodels 0.1.0__tar.gz → 0.1.3__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.0 → nonebot_plugin_githubmodels-0.1.3}/PKG-INFO +2 -3
- {nonebot_plugin_githubmodels-0.1.0 → nonebot_plugin_githubmodels-0.1.3}/nonebot_plugin_githubmodels/__init__.py +15 -13
- nonebot_plugin_githubmodels-0.1.3/nonebot_plugin_githubmodels/config.py +25 -0
- {nonebot_plugin_githubmodels-0.1.0 → nonebot_plugin_githubmodels-0.1.3}/pyproject.toml +2 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nonebot-plugin-githubmodels
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: API 调用 GitHub Models 的 GPT-4o 模型
|
|
5
5
|
Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
|
|
6
6
|
License: MIT
|
|
@@ -14,7 +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:
|
|
18
|
-
Requires-Dist: nonebot2[fastapi] (>=2.0.0,<3.0.0)
|
|
17
|
+
Requires-Dist: nonebot2 (>=2.2.1,<3.0.0)
|
|
19
18
|
Requires-Dist: openai (>=1.44.1,<2.0.0)
|
|
20
19
|
Project-URL: Repository, https://github.com/lyqgzbl/nonebot-plugin-githubmodels
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import nonebot
|
|
2
|
-
from openai import
|
|
2
|
+
from openai import AsyncOpenAI
|
|
3
3
|
from nonebot import on_command
|
|
4
4
|
from nonebot.adapters import Message
|
|
5
5
|
from nonebot.params import CommandArg
|
|
6
6
|
from nonebot.plugin import PluginMetadata
|
|
7
|
+
from .config import TOKEN,MODEL_NAME,MAX_CONTEXT_LENGTH,Config
|
|
7
8
|
|
|
8
|
-
config = nonebot.get_driver().config
|
|
9
|
-
token = config.github_token
|
|
10
9
|
endpoint = "https://models.inference.ai.azure.com"
|
|
11
|
-
|
|
12
|
-
client = OpenAI(
|
|
10
|
+
client = AsyncOpenAI(
|
|
13
11
|
base_url=endpoint,
|
|
14
|
-
api_key=
|
|
12
|
+
api_key=TOKEN,
|
|
15
13
|
)
|
|
14
|
+
|
|
16
15
|
shared_context = []
|
|
17
|
-
MAX_CONTEXT_LENGTH = 20 # 设置上下文最大保留条数
|
|
18
16
|
AI = on_command("AI", priority=10, block=True)
|
|
19
17
|
|
|
20
18
|
@AI.handle()
|
|
@@ -29,7 +27,6 @@ async def handle_function(args: Message = CommandArg()):
|
|
|
29
27
|
|
|
30
28
|
shared_context.append({"role": "user", "content": user_input})
|
|
31
29
|
|
|
32
|
-
# 保持上下文列表的最大长度
|
|
33
30
|
if len(shared_context) > MAX_CONTEXT_LENGTH:
|
|
34
31
|
shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
|
|
35
32
|
|
|
@@ -39,21 +36,26 @@ async def handle_function(args: Message = CommandArg()):
|
|
|
39
36
|
"content": "回答尽量简练,请始终用中文回答。",
|
|
40
37
|
}
|
|
41
38
|
] + shared_context
|
|
42
|
-
|
|
39
|
+
|
|
40
|
+
response = await client.chat.completions.create(
|
|
43
41
|
messages=messages,
|
|
44
|
-
model=
|
|
42
|
+
model=MODEL_NAME,
|
|
45
43
|
temperature=1,
|
|
46
44
|
max_tokens=500,
|
|
47
45
|
top_p=1,
|
|
48
46
|
)
|
|
47
|
+
|
|
49
48
|
reply = response.choices[0].message.content
|
|
50
49
|
shared_context.append({"role": "assistant", "content": reply})
|
|
51
50
|
|
|
52
|
-
# 保持上下文列表的最大长度
|
|
53
51
|
if len(shared_context) > MAX_CONTEXT_LENGTH:
|
|
54
52
|
shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
|
|
55
53
|
|
|
56
54
|
await AI.send(reply, reply_message=True)
|
|
55
|
+
reply = response.choices[0].message.content
|
|
56
|
+
shared_context.append({"role": "assistant", "content": reply})
|
|
57
|
+
|
|
58
|
+
|
|
57
59
|
|
|
58
60
|
__plugin_meta__ = PluginMetadata(
|
|
59
61
|
name="githubmodels",
|
|
@@ -61,5 +63,5 @@ __plugin_meta__ = PluginMetadata(
|
|
|
61
63
|
usage="AI",
|
|
62
64
|
type="application",
|
|
63
65
|
homepage="https://github.com/lyqgzbl/nonebot-plugin-githubmodels",
|
|
64
|
-
supported_adapters=
|
|
65
|
-
)
|
|
66
|
+
supported_adapters=None,
|
|
67
|
+
)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from nonebot import get_driver
|
|
3
|
+
from nonebot import get_plugin_config
|
|
4
|
+
|
|
5
|
+
class Config:
|
|
6
|
+
def __init__(self):
|
|
7
|
+
try:
|
|
8
|
+
self.github_token = get_driver().config.github_token
|
|
9
|
+
except AttributeError:
|
|
10
|
+
self.github_token = None
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
self.model_name = get_driver().config.model_name
|
|
14
|
+
except AttributeError:
|
|
15
|
+
self.model_name = "gpt-4o-mini"
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
self.MAX_CONTEXT_LENGTH = get_driver().config.MAX_CONTEXT_LENGTH
|
|
19
|
+
except AttributeError:
|
|
20
|
+
self.MAX_CONTEXT_LENGTH = 20
|
|
21
|
+
|
|
22
|
+
config = Config()
|
|
23
|
+
TOKEN = config.github_token
|
|
24
|
+
MODEL_NAME = config.model_name
|
|
25
|
+
MAX_CONTEXT_LENGTH = config.MAX_CONTEXT_LENGTH
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "nonebot-plugin-githubmodels"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.3"
|
|
4
4
|
description = "API 调用 GitHub Models 的 GPT-4o 模型"
|
|
5
5
|
authors = ["lyqgzbl <admin@lyqgzbl.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -9,9 +9,8 @@ repository = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels"
|
|
|
9
9
|
|
|
10
10
|
[tool.poetry.dependencies]
|
|
11
11
|
python = "^3.8"
|
|
12
|
-
nonebot2 =
|
|
12
|
+
nonebot2 = "^2.2.1"
|
|
13
13
|
openai = "^1.44.1"
|
|
14
|
-
nonebot-adapter-onebot = "^2.0.0"
|
|
15
14
|
|
|
16
15
|
[build-system]
|
|
17
16
|
requires = ["poetry-core>=1.0.0"]
|
|
@@ -21,4 +20,3 @@ build-backend = "poetry.core.masonry.api"
|
|
|
21
20
|
name = "githubmodels"
|
|
22
21
|
description = "API 调用 GitHub Models 的 GPT-4o 模型"
|
|
23
22
|
type = "application"
|
|
24
|
-
supported_adapters = ["~onebot.v11"]
|