nonebot-plugin-githubmodels 0.2.2__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nonebot-plugin-githubmodels
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: API 调用 GitHub Models 的大语言模型
5
5
  Home-page: https://github.com/lyqgzbl/nonebot-plugin-githubmodels
6
6
  License: MIT
@@ -54,19 +54,22 @@ async def handle_function(user_input: Match[tuple[str]]):
54
54
 
55
55
  @ai.got_path("user_input", prompt="请输入有效问题")
56
56
  async def got_location(user_input: str):
57
- global shared_context
58
- shared_context.append({"role": "user", "content": user_input})
59
- if len(shared_context) > MAX_CONTEXT_LENGTH:
60
- shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
57
+ global shared_context, REPLY_IMAGE
58
+ if MAX_CONTEXT_LENGTH > 0:
59
+ shared_context.append({"role": "user", "content": user_input})
60
+ if len(shared_context) > MAX_CONTEXT_LENGTH:
61
+ shared_context = shared_context[-MAX_CONTEXT_LENGTH:]
61
62
 
62
63
  messages = [
63
- {
64
- "role": "system",
65
- "content": "回答尽量简练,请始终用中文回答",
66
- }
67
- ] + shared_context
64
+ {"role": "system", "content": "回答尽量简练,请始终用中文回答"}
65
+ ]
66
+ if MAX_CONTEXT_LENGTH > 0:
67
+ messages += shared_context
68
+ else:
69
+ messages.append({"role": "user", "content": user_input})
68
70
 
69
- response = await client.chat.completions.create(
71
+ try:
72
+ response = await client.chat.completions.create(
70
73
  messages=messages,
71
74
  model=MODEL_NAME,
72
75
  temperature=1,
@@ -74,14 +77,17 @@ async def got_location(user_input: str):
74
77
  top_p=1,
75
78
  )
76
79
 
77
- reply = response.choices[0].message.content
78
- shared_context.append({"role": "assistant", "content": reply})
80
+ reply = response.choices[0].message.content
81
+ if MAX_CONTEXT_LENGTH > 0:
82
+ shared_context.append({"role": "assistant", "content": reply})
79
83
 
80
- if REPLY_IMAGE:
81
- pic = await md_to_pic(md=reply)
82
- await UniMessage.image(raw=pic).send(reply_to=True)
83
- else:
84
- await UniMessage.text(reply).send(reply_to=True)
84
+ if REPLY_IMAGE:
85
+ pic = await md_to_pic(md=reply)
86
+ await UniMessage.image(raw=pic).send(reply_to=True)
87
+ else:
88
+ await UniMessage.text(reply).send(reply_to=True)
89
+ finally:
90
+ REPLY_IMAGE = plugin_config.ai_reply_image
85
91
 
86
92
  __plugin_meta__ = PluginMetadata(
87
93
  name="githubmodels",
@@ -4,5 +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)
8
8
  ai_reply_image: bool = False
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "nonebot-plugin-githubmodels"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "API 调用 GitHub Models 的大语言模型"
5
5
  readme = "README.md"
6
6
  authors = ["lyqgzbl <admin@lyqgzbl.com>"]