nonebot-plugin-githubmodels 0.2.7__tar.gz → 1.0.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,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: nonebot-plugin-githubmodels
3
+ Version: 1.0.0
4
+ Summary: NoneBot 集成 GitHub Copilot 和 OpenAI 的 AI 代码生成模型插件
5
+ Author: lyqgzbl
6
+ Author-email: lyqgzbl <122811297+lyqgzbl@users.noreply.github.com>
7
+ License-Expression: MIT
8
+ Requires-Dist: nonebot2>=2.2.1,<3.0.0
9
+ Requires-Dist: azure-ai-inference>=1.0.0,<2.0.0
10
+ Requires-Dist: nonebot-plugin-htmlrender>=0.5.0,<1.0.0
11
+ Requires-Dist: nonebot-plugin-alconna>=0.54.0,<1.0.0
12
+ Requires-Python: >=3.10, <4.0
13
+ Project-URL: documentation, https://github.com/lyqgzbl/nonebot-plugin-daily-bing#readme
14
+ Project-URL: homepage, https://github.com/lyqgzbl/nonebot-plugin-daily-bing
15
+ Project-URL: repository, https://github.com/lyqgzbl/nonebot-plugin-daily-bing
16
+ Description-Content-Type: text/markdown
17
+
18
+ <!-- markdownlint-disable MD033 MD036 MD041 -->
19
+
20
+ <div align="center">
21
+
22
+ <a href="https://v2.nonebot.dev/store">
23
+ <img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
24
+ </a>
25
+
26
+ <p>
27
+ <img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
28
+ </p>
29
+
30
+ # nonebot-plugin-githubmodels
31
+
32
+ _✨ 一个调用 GitHub Models 的 AI 对话插件 ✨_
33
+
34
+ ![License](https://img.shields.io/pypi/l/nonebot-plugin-githubmodels)
35
+ ![PyPI](https://img.shields.io/pypi/v/nonebot-plugin-githubmodels.svg)
36
+ ![Python](https://img.shields.io/badge/python-3.8+-blue.svg)
37
+ [![NoneBot Registry](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin%2Fnonebot-plugin-githubmodels)](https://registry.nonebot.dev/plugin/nonebot-plugin-githubmodels:nonebot_plugin_githubmodels)
38
+ [![Supported Adapters](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin-adapters%2Fnonebot-plugin-alconna)](https://registry.nonebot.dev/plugin/nonebot-plugin-alconna:nonebot_plugin_alconna)
39
+
40
+ </div>
41
+
42
+ ## 安装
43
+ 使用nb-cli [推荐]
44
+ ```shell
45
+ nb plugin install nonebot-plugin-githubmodels
46
+ ```
47
+ 使用pip
48
+ ```shell
49
+ pip install nonebot-plugin-githubmodels
50
+ ```
51
+
52
+ ## 使用
53
+ 命令需要加 [NoneBot 命令前缀](https://nonebot.dev/docs/appendices/config#command-start-和-command-separator) (默认为`/`)
54
+ 使用命令`AI`/`ai`触发插件
55
+ 命令选项`-r` 重置上下文记忆
56
+ 命令选项`-i` 临时启用图片回复
57
+
58
+ ## 配置项
59
+
60
+ 配置方式:直接在 NoneBot 全局配置文件中添加以下配置项即可
61
+
62
+ ### github_token [必填]
63
+
64
+ - 类型:`str`
65
+ - 默认值:`None`
66
+ - 说明:用于访问 GitHub Models 的 GitHub token
67
+
68
+ ### max_context_length [选填]
69
+
70
+ - 类型:`int`
71
+ - 默认值:`20`
72
+ - 说明:记忆的上下文数量的最大值
73
+
74
+ ### ai_reply_image [选填]
75
+
76
+
77
+ - 类型: `bool`
78
+ - 默认: `False`
79
+ - 说明: 是否以图片的形式回复
80
+
81
+ ### ai_model_name [选填]
82
+
83
+ - 类型: `str`
84
+ - 默认: `openai/gpt-4.1-mini`
85
+ - 说明: 所使用的模型
86
+
87
+ ### ai_temperature [选填]
88
+
89
+ - 类型: `float`
90
+ - 默认: `1.0`
91
+ - 说明: 生成的文本的多样性和连贯性
92
+
93
+ ## ai_top_p [选填]
94
+
95
+ - 类型: `float`
96
+ - 默认: `1.0`
97
+ - 说明: 生成文本随机性
@@ -0,0 +1,80 @@
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
+ _✨ 一个调用 GitHub Models 的 AI 对话插件 ✨_
16
+
17
+ ![License](https://img.shields.io/pypi/l/nonebot-plugin-githubmodels)
18
+ ![PyPI](https://img.shields.io/pypi/v/nonebot-plugin-githubmodels.svg)
19
+ ![Python](https://img.shields.io/badge/python-3.8+-blue.svg)
20
+ [![NoneBot Registry](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin%2Fnonebot-plugin-githubmodels)](https://registry.nonebot.dev/plugin/nonebot-plugin-githubmodels:nonebot_plugin_githubmodels)
21
+ [![Supported Adapters](https://img.shields.io/endpoint?url=https%3A%2F%2Fnbbdg.lgc2333.top%2Fplugin-adapters%2Fnonebot-plugin-alconna)](https://registry.nonebot.dev/plugin/nonebot-plugin-alconna:nonebot_plugin_alconna)
22
+
23
+ </div>
24
+
25
+ ## 安装
26
+ 使用nb-cli [推荐]
27
+ ```shell
28
+ nb plugin install nonebot-plugin-githubmodels
29
+ ```
30
+ 使用pip
31
+ ```shell
32
+ pip install nonebot-plugin-githubmodels
33
+ ```
34
+
35
+ ## 使用
36
+ 命令需要加 [NoneBot 命令前缀](https://nonebot.dev/docs/appendices/config#command-start-和-command-separator) (默认为`/`)
37
+ 使用命令`AI`/`ai`触发插件
38
+ 命令选项`-r` 重置上下文记忆
39
+ 命令选项`-i` 临时启用图片回复
40
+
41
+ ## 配置项
42
+
43
+ 配置方式:直接在 NoneBot 全局配置文件中添加以下配置项即可
44
+
45
+ ### github_token [必填]
46
+
47
+ - 类型:`str`
48
+ - 默认值:`None`
49
+ - 说明:用于访问 GitHub Models 的 GitHub token
50
+
51
+ ### max_context_length [选填]
52
+
53
+ - 类型:`int`
54
+ - 默认值:`20`
55
+ - 说明:记忆的上下文数量的最大值
56
+
57
+ ### ai_reply_image [选填]
58
+
59
+
60
+ - 类型: `bool`
61
+ - 默认: `False`
62
+ - 说明: 是否以图片的形式回复
63
+
64
+ ### ai_model_name [选填]
65
+
66
+ - 类型: `str`
67
+ - 默认: `openai/gpt-4.1-mini`
68
+ - 说明: 所使用的模型
69
+
70
+ ### ai_temperature [选填]
71
+
72
+ - 类型: `float`
73
+ - 默认: `1.0`
74
+ - 说明: 生成的文本的多样性和连贯性
75
+
76
+ ## ai_top_p [选填]
77
+
78
+ - 类型: `float`
79
+ - 默认: `1.0`
80
+ - 说明: 生成文本随机性
@@ -0,0 +1,45 @@
1
+ [project]
2
+ name = "nonebot-plugin-githubmodels"
3
+ version = "1.0.0"
4
+ description = "NoneBot 集成 GitHub Copilot 和 OpenAI 的 AI 代码生成模型插件"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "lyqgzbl", email = "122811297+lyqgzbl@users.noreply.github.com" }
8
+ ]
9
+ requires-python = ">=3.10, <4.0"
10
+ license = "MIT"
11
+ dependencies = [
12
+ "nonebot2 >=2.2.1, <3.0.0",
13
+ "azure-ai-inference >=1.0.0, <2.0.0",
14
+ "nonebot-plugin-htmlrender >=0.5.0, <1.0.0",
15
+ "nonebot-plugin-alconna >=0.54.0, <1.0.0",
16
+ ]
17
+
18
+ [project.urls]
19
+ homepage = "https://github.com/lyqgzbl/nonebot-plugin-daily-bing"
20
+ repository = "https://github.com/lyqgzbl/nonebot-plugin-daily-bing"
21
+ documentation = "https://github.com/lyqgzbl/nonebot-plugin-daily-bing#readme"
22
+
23
+ [build-system]
24
+ requires = ["uv_build>=0.8.17,<0.9.0"]
25
+ build-backend = "uv_build"
26
+
27
+ [dependency-groups]
28
+ dev = [
29
+ "ruff>=0.14.0",
30
+ ]
31
+
32
+ [tool.ruff]
33
+ line-length = 88
34
+ target-version = "py310"
35
+
36
+ [tool.ruff.lint]
37
+ select = ["E", "W", "F", "UP", "C", "T", "PYI", "PT", "Q"]
38
+ ignore = ["E402", "C901"]
39
+ fixable = ["ALL"]
40
+
41
+ [tool.ruff.format]
42
+ quote-style = "double"
43
+ indent-style = "space"
44
+ skip-magic-trailing-comma = false
45
+ line-ending = "auto"
@@ -1,20 +1,20 @@
1
1
  import datetime
2
2
  from pathlib import Path
3
3
 
4
- import nonebot
5
- from nonebot import require, get_plugin_config
4
+
6
5
  from nonebot.rule import Rule
7
6
  from nonebot.log import logger
7
+ from nonebot import require, get_plugin_config
8
+ from azure.ai.inference.models import SystemMessage
8
9
  from nonebot.plugin import PluginMetadata, inherit_supported_adapters
9
10
  require("nonebot_plugin_alconna")
10
11
  require("nonebot_plugin_htmlrender")
11
- from openai import BadRequestError
12
- from arclet.alconna import Args, Option, Alconna, MultiVar, CommandMeta
13
- from nonebot_plugin_alconna import UniMessage, on_alconna, Match
14
12
  from nonebot_plugin_htmlrender import md_to_pic
13
+ from nonebot_plugin_alconna import UniMessage, on_alconna, Match
14
+ from arclet.alconna import Args, Option, Alconna, MultiVar, CommandMeta
15
15
 
16
16
  from .config import Config
17
- from .GPT_handler import GPTHandler
17
+ from .openai_handler import OPENAI_Handler
18
18
  from .context_manager import ContextManager
19
19
 
20
20
 
@@ -34,16 +34,16 @@ REPLY_IMAGE = plugin_config.ai_reply_image
34
34
 
35
35
 
36
36
  if not plugin_config.github_token:
37
- logger.opt(colors=True).warning("<yellow>缺失必要配置项 'github_token',已禁用该插件</yellow>")
38
- GPT_handler = None
37
+ logger.opt(colors=True).warning("<yellow>缺失必要配置项 'github_token'" \
38
+ "已禁用该插件</yellow>")
39
+ Openai_Handler = None
39
40
  else:
40
- GPT_handler = GPTHandler(
41
+ Openai_Handler = OPENAI_Handler(
41
42
  api_key=plugin_config.github_token,
42
- endpoint="https://models.inference.ai.azure.com",
43
+ endpoint="https://models.github.ai/inference",
43
44
  model_name=plugin_config.ai_model_name,
44
45
  max_context_length=plugin_config.max_context_length,
45
46
  temperature=plugin_config.ai_temperature,
46
- max_tokens=plugin_config.ai_max_tokens,
47
47
  top_p=plugin_config.ai_top_p,
48
48
  )
49
49
 
@@ -54,7 +54,7 @@ def is_enable() -> Rule:
54
54
  return Rule(_rule)
55
55
 
56
56
 
57
- context_manager = ContextManager(max_context_length=plugin_config.max_context_length)
57
+ Context_Manager = ContextManager(max_context_length=plugin_config.max_context_length)
58
58
 
59
59
 
60
60
  ai = on_alconna(
@@ -63,7 +63,7 @@ ai = on_alconna(
63
63
  Args["user_input?", MultiVar(str)],
64
64
  Option("-r|--reset", help_text="重置上下文记忆"),
65
65
  Option("-i|--image", help_text="临时启用图片回复"),
66
- meta=CommandMeta(
66
+ meta=CommandMeta(
67
67
  description="AI 对话插件",
68
68
  usage=__plugin_meta__.usage,
69
69
  example="/AI Hello; /AI -i Hello; /AI -r",
@@ -79,7 +79,7 @@ ai = on_alconna(
79
79
 
80
80
  @ai.assign("reset")
81
81
  async def ai_reset():
82
- context_manager.reset_context()
82
+ Context_Manager.reset_context()
83
83
  await ai.finish("上下文已重置")
84
84
 
85
85
 
@@ -101,23 +101,25 @@ async def handle_function(user_input: Match[tuple[str]]):
101
101
  async def got_location(user_input: str):
102
102
  global REPLY_IMAGE
103
103
  try:
104
- messages = [{"role": "system", "content": "回答尽量简练,请始终用中文回答"}]
105
- context_manager.add_message("user", user_input)
106
- messages += context_manager.get_context()
107
- reply = await GPT_handler.get_response(messages)
108
- context_manager.add_message("assistant", reply)
104
+ messages = [SystemMessage(content="回答尽量简练,请始终用中文回答")]
105
+ Context_Manager.add_message("user", user_input)
106
+ messages += Context_Manager.get_context()
107
+ if Openai_Handler is not None:
108
+ reply = await Openai_Handler.get_response(messages)
109
+ Context_Manager.add_message("assistant", reply)
109
110
  if REPLY_IMAGE:
110
111
  current_hour = datetime.datetime.now().hour
111
112
  is_dark_mode = 18 <= current_hour or current_hour < 6
112
113
  css_file = (
113
- Path(__file__).parent / "css" / ("dark.css" if is_dark_mode else "light.css")
114
+ Path(__file__).
115
+ parent / "css" / ("dark.css" if is_dark_mode else "light.css")
114
116
  )
115
117
  pic = await md_to_pic(md=reply, css_path=str(css_file))
116
118
  await UniMessage.image(raw=pic).send(reply_to=True)
117
119
  else:
118
120
  await UniMessage.text(reply).send(reply_to=True)
119
- except BadRequestError as e:
121
+ except Exception as e:
120
122
  logger.opt(colors=True).error(f"<red>API 请求失败: {e}</red>")
121
123
  await ai.send("问题触发了内容过滤策略,请修改问题后重试")
122
124
  finally:
123
- REPLY_IMAGE = plugin_config.ai_reply_image
125
+ REPLY_IMAGE = plugin_config.ai_reply_image
@@ -1,11 +1,9 @@
1
- from typing import Optional
2
1
  from pydantic import BaseModel, Field
3
2
 
4
3
  class Config(BaseModel):
5
- github_token: Optional[str] = None
4
+ github_token: str | None = None
6
5
  max_context_length: int = Field(20)
7
6
  ai_reply_image: bool = False
8
- ai_model_name: str = "gpt-4o-mini"
7
+ ai_model_name: str = "openai/gpt-4.1-mini"
9
8
  ai_temperature: float = Field(1.0)
10
- ai_max_tokens: int = Field(1024)
11
- ai_top_p: float = Field(1.0)
9
+ ai_top_p: float = Field(1.0)
@@ -0,0 +1,41 @@
1
+ from __future__ import annotations
2
+ from azure.ai.inference.models import (
3
+ AssistantMessage,
4
+ ChatRequestMessage,
5
+ SystemMessage,
6
+ UserMessage,
7
+ )
8
+
9
+
10
+ class ContextManager:
11
+ def __init__(self, max_context_length: int):
12
+ self.max_context_length = max_context_length
13
+ self.shared_context: list[ChatRequestMessage] = []
14
+
15
+ def add_message(self, role: str, content: str):
16
+ if self.max_context_length <= 0:
17
+ return
18
+
19
+ message = self._create_message(role, content)
20
+ if message is None:
21
+ return
22
+
23
+ self.shared_context.append(message)
24
+ if len(self.shared_context) > self.max_context_length:
25
+ self.shared_context = self.shared_context[-self.max_context_length:]
26
+
27
+ def get_context(self) -> list[ChatRequestMessage]:
28
+ return self.shared_context.copy() if self.max_context_length > 0 else []
29
+
30
+ def reset_context(self):
31
+ self.shared_context = []
32
+
33
+ @staticmethod
34
+ def _create_message(role: str, content: str) -> ChatRequestMessage | None:
35
+ if role == "user":
36
+ return UserMessage(content=content)
37
+ if role == "assistant":
38
+ return AssistantMessage(content=content)
39
+ if role == "system":
40
+ return SystemMessage(content=content)
41
+ return None
@@ -1,19 +1,23 @@
1
1
  body {
2
- background-color: #1e1e2f; /* 深色背景 */
3
- color: #d4d4d4; /* 浅色文字 */
4
- font-family: Arial, Helvetica, sans-serif;
5
- line-height: 1.6;
2
+ background-color: #1e1e2f;
3
+ color: #d4d4d4;
4
+ font-family: -apple-system, BlinkMacSystemFont, "Microsoft Yahei", "Noto Sans", sans-serif, monospace;
5
+ line-height: 1.8;
6
6
  margin: 0;
7
7
  padding: 1rem;
8
+ overflow-wrap: break-word;
9
+ text-rendering: optimizeLegibility;
10
+ -webkit-font-smoothing: antialiased;
11
+ font-size: 16px;
8
12
  }
9
13
 
10
14
  h1, h2, h3, h4, h5, h6 {
11
- color: #ffffff; /* 标题白色 */
12
- border-bottom: 1px solid #444; /* 标题下的分隔线 */
15
+ color: #ffffff;
16
+ border-bottom: 1px solid #444;
13
17
  }
14
18
 
15
19
  a {
16
- color: #569cd6; /* 链接蓝色 */
20
+ color: #569cd6;
17
21
  text-decoration: none;
18
22
  }
19
23
 
@@ -22,14 +26,14 @@ a:hover {
22
26
  }
23
27
 
24
28
  code, pre {
25
- background-color: #2d2d3a; /* 代码块背景 */
26
- color: #dcdcaa; /* 代码块文字颜色 */
29
+ background-color: #2d2d3a;
30
+ color: #d4d4d4;
27
31
  border-radius: 5px;
28
32
  padding: 0.2rem 0.4rem;
29
33
  }
30
34
 
31
35
  blockquote {
32
- border-left: 4px solid #444; /* 引用的边框 */
36
+ border-left: 4px solid #444;
33
37
  padding-left: 1rem;
34
38
  color: #999;
35
39
  font-style: italic;
@@ -0,0 +1,61 @@
1
+ body {
2
+ background-color: #f9f9f9;
3
+ color: #333333;
4
+ font-family: -apple-system, BlinkMacSystemFont, "Microsoft Yahei", "Noto Sans", sans-serif, monospace;
5
+ line-height: 1.8;
6
+ margin: 0;
7
+ padding: 1rem;
8
+ overflow-wrap: break-word;
9
+ text-rendering: optimizeLegibility;
10
+ -webkit-font-smoothing: antialiased;
11
+ font-size: 16px;
12
+ }
13
+
14
+ h1, h2, h3, h4, h5, h6 {
15
+ color: #000000;
16
+ border-bottom: 1px solid #cccccc;
17
+ }
18
+
19
+ a {
20
+ color: #0066cc;
21
+ text-decoration: none;
22
+ }
23
+
24
+ a:hover {
25
+ text-decoration: underline;
26
+ }
27
+
28
+ code, pre {
29
+ background-color: #e5e5e5;
30
+ color: #333333;
31
+ border-radius: 5px;
32
+ padding: 0.2rem 0.4rem;
33
+ }
34
+
35
+ blockquote {
36
+ border-left: 4px solid #cccccc;
37
+ padding-left: 1rem;
38
+ color: #666666;
39
+ font-style: italic;
40
+ }
41
+
42
+ table {
43
+ width: 100%;
44
+ border-collapse: collapse;
45
+ margin: 1rem 0;
46
+ background-color: #ffffff;
47
+ }
48
+
49
+ table th, table td {
50
+ border: 1px solid #cccccc;
51
+ padding: 0.5rem;
52
+ text-align: left;
53
+ color: #333333;
54
+ }
55
+
56
+ hr {
57
+ border: 0;
58
+ height: 1px;
59
+ background: #cccccc;
60
+ margin: 2rem 0;
61
+ }
@@ -0,0 +1,36 @@
1
+ from collections.abc import Sequence
2
+ from azure.ai.inference.aio import ChatCompletionsClient
3
+ from azure.ai.inference.models import ChatRequestMessage
4
+ from azure.core.credentials import AzureKeyCredential
5
+
6
+
7
+ class OPENAI_Handler:
8
+ def __init__(
9
+ self,
10
+ api_key: str,
11
+ endpoint: str,
12
+ model_name: str,
13
+ max_context_length: int,
14
+ temperature: float,
15
+ top_p: float,
16
+ ):
17
+ self.client = ChatCompletionsClient(
18
+ endpoint=endpoint,
19
+ credential=AzureKeyCredential(api_key)
20
+ )
21
+ self.model_name = model_name
22
+ self.max_context_length = max_context_length
23
+ self.temperature = temperature
24
+ self.top_p = top_p
25
+
26
+ async def get_response(self, messages: Sequence[ChatRequestMessage]) -> str:
27
+ response = await self.client.complete(
28
+ messages=list(messages),
29
+ model=self.model_name,
30
+ temperature=self.temperature,
31
+ top_p=self.top_p,
32
+ )
33
+ content = response.choices[0].message.content
34
+ if not content:
35
+ raise ValueError("模型未返回内容")
36
+ return content
@@ -1,19 +0,0 @@
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,68 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: nonebot-plugin-githubmodels
3
- Version: 0.2.7
4
- Summary: 一个调用 GitHub Models 的 AI 对话插件
5
- Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
6
- License: MIT
7
- Keywords: nonebot2,GitHub Models
8
- Author: lyqgzbl
9
- Author-email: admin@lyqgzbl.com
10
- Requires-Python: >=3.8,<4.0
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.8
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Programming Language :: Python :: 3.13
19
- Requires-Dist: nonebot-plugin-alconna (>=0.54.0,<0.55.0)
20
- Requires-Dist: nonebot-plugin-htmlrender (>=0.3.5,<0.4.0)
21
- Requires-Dist: nonebot2 (>=2.2.1,<3.0.0)
22
- Requires-Dist: openai (>=1.44.1,<2.0.0)
23
- Project-URL: Documentation, https://github.com/lyqgzbl/nonebot-plugin-githubmodels#readme
24
- Project-URL: Repository, https://github.com/lyqgzbl/nonebot-plugin-githubmodels
25
- Description-Content-Type: text/markdown
26
-
27
- <!-- markdownlint-disable MD033 MD036 MD041 -->
28
-
29
- <div align="center">
30
-
31
- <a href="https://v2.nonebot.dev/store">
32
- <img src="https://raw.githubusercontent.com/A-kirami/nonebot-plugin-template/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo">
33
- </a>
34
-
35
- <p>
36
- <img src="https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/plugin.svg" alt="NoneBotPluginText">
37
- </p>
38
-
39
- # nonebot-plugin-githubmodels
40
-
41
- _✨ API调用GitHub models大语言模型 ✨_
42
-
43
- <a href ="https://raw.githubusercontent.com/lyqgzbl/nonebot-plugin-githubmodels/refs/heads/main/LICENSE"><img src="https://img.shields.io/pypi/l/nonebot-plugin-githubmodels"> </a>
44
- <a href="https://pypi.python.org/pypi/nonebot-plugin-githubmodels"> <img src="https://img.shields.io/pypi/v/nonebot-plugin-githubmodels.svg" alt="pypi"></a>
45
- <img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
46
-
47
- </div>
48
-
49
- # 安装
50
- 使用nb-cli [推荐]
51
- ```shell
52
- nb plugin install nonebot-plugin-githubmodels
53
- ```
54
- 使用pip
55
- ```shell
56
- pip install nonebot-plugin-githubmodels
57
- ```
58
-
59
- # 使用
60
- 命令需要加 [NoneBot 命令前缀](https://nonebot.dev/docs/appendices/config#command-start-和-command-separator) (默认为`/`)
61
- 使用命令`AI`/`ai`触发插件
62
- 命令选项`-r` 重置上下文记忆
63
- 命令选项`-i` 临时启用图片回复
64
-
65
- # 配置
66
-
67
- 配置参见 [.env.example](https://github.com/lyqgzbl/nonebot-plugin-githubmodels/blob/main/.env.example)
68
-
@@ -1,41 +0,0 @@
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
- <a href ="https://raw.githubusercontent.com/lyqgzbl/nonebot-plugin-githubmodels/refs/heads/main/LICENSE"><img src="https://img.shields.io/pypi/l/nonebot-plugin-githubmodels"> </a>
18
- <a href="https://pypi.python.org/pypi/nonebot-plugin-githubmodels"> <img src="https://img.shields.io/pypi/v/nonebot-plugin-githubmodels.svg" alt="pypi"></a>
19
- <img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
20
-
21
- </div>
22
-
23
- # 安装
24
- 使用nb-cli [推荐]
25
- ```shell
26
- nb plugin install nonebot-plugin-githubmodels
27
- ```
28
- 使用pip
29
- ```shell
30
- pip install nonebot-plugin-githubmodels
31
- ```
32
-
33
- # 使用
34
- 命令需要加 [NoneBot 命令前缀](https://nonebot.dev/docs/appendices/config#command-start-和-command-separator) (默认为`/`)
35
- 使用命令`AI`/`ai`触发插件
36
- 命令选项`-r` 重置上下文记忆
37
- 命令选项`-i` 临时启用图片回复
38
-
39
- # 配置
40
-
41
- 配置参见 [.env.example](https://github.com/lyqgzbl/nonebot-plugin-githubmodels/blob/main/.env.example)
@@ -1,29 +0,0 @@
1
- from openai import AsyncOpenAI
2
-
3
- class GPTHandler:
4
- def __init__(
5
- self,
6
- api_key: str,
7
- endpoint: str,
8
- model_name: str,
9
- max_context_length: int,
10
- temperature: float,
11
- max_tokens: int,
12
- top_p: float,
13
- ):
14
- self.client = AsyncOpenAI(base_url=endpoint, api_key=api_key)
15
- self.model_name = model_name
16
- self.max_context_length = max_context_length
17
- self.temperature = temperature
18
- self.max_tokens = max_tokens
19
- self.top_p = top_p
20
-
21
- async def get_response(self, messages: list) -> str:
22
- response = await self.client.chat.completions.create(
23
- messages=messages,
24
- model=self.model_name,
25
- temperature=self.temperature,
26
- max_tokens=self.max_tokens,
27
- top_p=self.top_p,
28
- )
29
- return response.choices[0].message.content
@@ -1,16 +0,0 @@
1
- class ContextManager:
2
- def __init__(self, max_context_length: int):
3
- self.max_context_length = max_context_length
4
- self.shared_context = []
5
-
6
- def add_message(self, role: str, content: str):
7
- if self.max_context_length > 0:
8
- self.shared_context.append({"role": role, "content": content})
9
- if len(self.shared_context) > self.max_context_length:
10
- self.shared_context = self.shared_context[-self.max_context_length:]
11
-
12
- def get_context(self):
13
- return self.shared_context.copy() if self.max_context_length > 0 else []
14
-
15
- def reset_context(self):
16
- self.shared_context = []
@@ -1,57 +0,0 @@
1
- body {
2
- background-color: #ffffff; /* 亮色背景 */
3
- color: #333333; /* 深色文字 */
4
- font-family: Arial, Helvetica, sans-serif;
5
- line-height: 1.6;
6
- margin: 0;
7
- padding: 1rem;
8
- }
9
-
10
- h1, h2, h3, h4, h5, h6 {
11
- color: #000000; /* 标题黑色 */
12
- border-bottom: 1px solid #ccc; /* 标题下的分隔线 */
13
- }
14
-
15
- a {
16
- color: #007acc; /* 链接蓝色 */
17
- text-decoration: none;
18
- }
19
-
20
- a:hover {
21
- text-decoration: underline;
22
- }
23
-
24
- code, pre {
25
- background-color: #f4f4f4; /* 代码块背景 */
26
- color: #d14; /* 代码块文字颜色 */
27
- border-radius: 5px;
28
- padding: 0.2rem 0.4rem;
29
- }
30
-
31
- blockquote {
32
- border-left: 4px solid #ccc; /* 引用的边框 */
33
- padding-left: 1rem;
34
- color: #666;
35
- font-style: italic;
36
- }
37
-
38
- table {
39
- width: 100%;
40
- border-collapse: collapse;
41
- margin: 1rem 0;
42
- background-color: #f9f9f9;
43
- }
44
-
45
- table th, table td {
46
- border: 1px solid #ccc;
47
- padding: 0.5rem;
48
- text-align: left;
49
- color: #333;
50
- }
51
-
52
- hr {
53
- border: 0;
54
- height: 1px;
55
- background: #ccc;
56
- margin: 2rem 0;
57
- }
@@ -1,22 +0,0 @@
1
- [tool.poetry]
2
- name = "nonebot-plugin-githubmodels"
3
- version = "0.2.7"
4
- description = "一个调用 GitHub Models 的 AI 对话插件"
5
- readme = "README.md"
6
- authors = ["lyqgzbl <admin@lyqgzbl.com>"]
7
- license = "MIT"
8
- homepage = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels"
9
- repository = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels"
10
- documentation = "https://github.com/lyqgzbl/nonebot-plugin-githubmodels#readme"
11
- keywords = ["nonebot2", "GitHub Models"]
12
-
13
- [tool.poetry.dependencies]
14
- python = "^3.8"
15
- nonebot2 = "^2.2.1"
16
- openai = "^1.44.1"
17
- nonebot-plugin-htmlrender = "^0.3.5"
18
- nonebot-plugin-alconna = "^0.54.0"
19
-
20
- [build-system]
21
- requires = ["poetry-core>=1.0.0"]
22
- build-backend = "poetry.core.masonry.api"