nonebot-plugin-githubmodels 0.1.0__py3-none-any.whl

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,65 @@
1
+ import nonebot
2
+ from openai import OpenAI
3
+ from nonebot import on_command
4
+ from nonebot.adapters import Message
5
+ from nonebot.params import CommandArg
6
+ from nonebot.plugin import PluginMetadata
7
+
8
+ config = nonebot.get_driver().config
9
+ token = config.github_token
10
+ endpoint = "https://models.inference.ai.azure.com"
11
+ model_name = "gpt-4o-mini"
12
+ client = OpenAI(
13
+ base_url=endpoint,
14
+ api_key=token,
15
+ )
16
+ shared_context = []
17
+ MAX_CONTEXT_LENGTH = 20 # 设置上下文最大保留条数
18
+ AI = on_command("AI", priority=10, block=True)
19
+
20
+ @AI.handle()
21
+ async def handle_function(args: Message = CommandArg()):
22
+ global shared_context
23
+ user_input = args.extract_plain_text().strip()
24
+ if user_input.lower() == "重置":
25
+ shared_context = []
26
+ await AI.finish("上下文已重置。请开始新的对话。")
27
+ if not user_input:
28
+ await AI.finish("请输入有效的问题。")
29
+
30
+ shared_context.append({"role": "user", "content": user_input})
31
+
32
+ # 保持上下文列表的最大长度
33
+ if len(shared_context) > MAX_CONTEXT_LENGTH:
34
+ shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
35
+
36
+ messages = [
37
+ {
38
+ "role": "system",
39
+ "content": "回答尽量简练,请始终用中文回答。",
40
+ }
41
+ ] + shared_context
42
+ response = client.chat.completions.create(
43
+ messages=messages,
44
+ model=model_name,
45
+ temperature=1,
46
+ max_tokens=500,
47
+ top_p=1,
48
+ )
49
+ reply = response.choices[0].message.content
50
+ shared_context.append({"role": "assistant", "content": reply})
51
+
52
+ # 保持上下文列表的最大长度
53
+ if len(shared_context) > MAX_CONTEXT_LENGTH:
54
+ shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
55
+
56
+ await AI.send(reply, reply_message=True)
57
+
58
+ __plugin_meta__ = PluginMetadata(
59
+ name="githubmodels",
60
+ description="API 调用 GitHub Models 的 GPT-4o 模型",
61
+ usage="AI",
62
+ type="application",
63
+ homepage="https://github.com/lyqgzbl/nonebot-plugin-githubmodels",
64
+ supported_adapters={"~onebot.v11"},
65
+ )
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.1
2
+ Name: nonebot-plugin-githubmodels
3
+ Version: 0.1.0
4
+ Summary: API 调用 GitHub Models 的 GPT-4o 模型
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
+ Requires-Dist: nonebot-adapter-onebot (>=2.0.0,<3.0.0)
18
+ Requires-Dist: nonebot2[fastapi] (>=2.0.0,<3.0.0)
19
+ Requires-Dist: openai (>=1.44.1,<2.0.0)
20
+ Project-URL: Repository, https://github.com/lyqgzbl/nonebot-plugin-githubmodels
@@ -0,0 +1,4 @@
1
+ nonebot_plugin_githubmodels/__init__.py,sha256=o759LWr6H6V_sH0WOb5YoOwc0ikHPDZaufHtEDz4EuY,2057
2
+ nonebot_plugin_githubmodels-0.1.0.dist-info/METADATA,sha256=b1JWOuc8ATz0R_FDQzYalyZMFkfjC4snkVxwE-zdcAo,855
3
+ nonebot_plugin_githubmodels-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
4
+ nonebot_plugin_githubmodels-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any