xiaogpt 1.46__py3-none-any.whl → 1.51__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.
- xiaogpt/bot/__init__.py +3 -1
- xiaogpt/bot/glm_bot.py +46 -0
- xiaogpt/bot/gpt3_bot.py +3 -2
- xiaogpt/cli.py +18 -1
- xiaogpt/config.py +1 -0
- xiaogpt/xiaogpt.py +4 -1
- {xiaogpt-1.46.dist-info → xiaogpt-1.51.dist-info}/METADATA +8 -1
- xiaogpt-1.51.dist-info/RECORD +17 -0
- {xiaogpt-1.46.dist-info → xiaogpt-1.51.dist-info}/WHEEL +1 -1
- xiaogpt-1.46.dist-info/RECORD +0 -16
- {xiaogpt-1.46.dist-info → xiaogpt-1.51.dist-info}/entry_points.txt +0 -0
- {xiaogpt-1.46.dist-info → xiaogpt-1.51.dist-info}/licenses/LICENSE +0 -0
xiaogpt/bot/__init__.py
CHANGED
@@ -4,12 +4,14 @@ from xiaogpt.bot.base_bot import BaseBot
|
|
4
4
|
from xiaogpt.bot.chatgptapi_bot import ChatGPTBot
|
5
5
|
from xiaogpt.bot.gpt3_bot import GPT3Bot
|
6
6
|
from xiaogpt.bot.newbing_bot import NewBingBot
|
7
|
+
from xiaogpt.bot.glm_bot import GLMBot
|
7
8
|
from xiaogpt.config import Config
|
8
9
|
|
9
10
|
BOTS: dict[str, type[BaseBot]] = {
|
10
11
|
"gpt3": GPT3Bot,
|
11
12
|
"newbing": NewBingBot,
|
12
13
|
"chatgptapi": ChatGPTBot,
|
14
|
+
"glm": GLMBot,
|
13
15
|
}
|
14
16
|
|
15
17
|
|
@@ -20,4 +22,4 @@ def get_bot(config: Config) -> BaseBot:
|
|
20
22
|
raise ValueError(f"Unsupported bot {config.bot}, must be one of {list(BOTS)}")
|
21
23
|
|
22
24
|
|
23
|
-
__all__ = ["GPT3Bot", "ChatGPTBot", "NewBingBot", "get_bot"]
|
25
|
+
__all__ = ["GPT3Bot", "ChatGPTBot", "NewBingBot", "GLMBot", "get_bot"]
|
xiaogpt/bot/glm_bot.py
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
"""ChatGLM bot"""
|
2
|
+
from __future__ import annotations
|
3
|
+
from typing import Any, AsyncGenerator
|
4
|
+
|
5
|
+
import zhipuai
|
6
|
+
from rich import print
|
7
|
+
|
8
|
+
from xiaogpt.bot.base_bot import BaseBot
|
9
|
+
|
10
|
+
|
11
|
+
class GLMBot(BaseBot):
|
12
|
+
default_options = {"model": "chatglm_130b"}
|
13
|
+
|
14
|
+
def __init__(
|
15
|
+
self,
|
16
|
+
glm_key: str,
|
17
|
+
) -> None:
|
18
|
+
self.history = []
|
19
|
+
zhipuai.api_key = glm_key
|
20
|
+
|
21
|
+
@classmethod
|
22
|
+
def from_config(cls, config):
|
23
|
+
return cls(glm_key=config.glm_key)
|
24
|
+
|
25
|
+
def ask(self, query, **options):
|
26
|
+
ms = []
|
27
|
+
for h in self.history:
|
28
|
+
ms.append({"role": "user", "content": h[0]})
|
29
|
+
ms.append({"role": "assistant", "content": h[1]})
|
30
|
+
kwargs = {**self.default_options, **options}
|
31
|
+
kwargs["prompt"] = ms
|
32
|
+
ms.append({"role": "user", "content": f"{query}"})
|
33
|
+
r = zhipuai.model_api.sse_invoke(**kwargs)
|
34
|
+
message = ""
|
35
|
+
for i in r.events():
|
36
|
+
message += str(i.data)
|
37
|
+
|
38
|
+
self.history.append([f"{query}", message])
|
39
|
+
# only keep 5 history
|
40
|
+
first_history = self.history.pop(0)
|
41
|
+
self.history = [first_history] + self.history[-5:]
|
42
|
+
print(message)
|
43
|
+
return message
|
44
|
+
|
45
|
+
def ask_stream(self, query: str, **options: Any):
|
46
|
+
pass
|
xiaogpt/bot/gpt3_bot.py
CHANGED
@@ -47,8 +47,9 @@ class GPT3Bot(BaseBot):
|
|
47
47
|
|
48
48
|
async def text_gen():
|
49
49
|
async for event in completion:
|
50
|
-
|
51
|
-
|
50
|
+
text = event["choices"][0]["text"]
|
51
|
+
print(text, end="")
|
52
|
+
yield text
|
52
53
|
|
53
54
|
try:
|
54
55
|
async for sentence in split_sentences(text_gen()):
|
xiaogpt/cli.py
CHANGED
@@ -27,6 +27,11 @@ def main():
|
|
27
27
|
dest="openai_key",
|
28
28
|
help="openai api key",
|
29
29
|
)
|
30
|
+
parser.add_argument(
|
31
|
+
"--glm_key",
|
32
|
+
dest="glm_key",
|
33
|
+
help="chatglm api key",
|
34
|
+
)
|
30
35
|
parser.add_argument(
|
31
36
|
"--proxy",
|
32
37
|
dest="proxy",
|
@@ -94,13 +99,23 @@ def main():
|
|
94
99
|
const="newbing",
|
95
100
|
help="if use newbing",
|
96
101
|
)
|
102
|
+
group.add_argument(
|
103
|
+
"--use_glm",
|
104
|
+
dest="bot",
|
105
|
+
action="store_const",
|
106
|
+
const="glm",
|
107
|
+
help="if use chatglm",
|
108
|
+
)
|
97
109
|
parser.add_argument(
|
98
110
|
"--bing_cookie_path",
|
99
111
|
dest="bing_cookie_path",
|
100
112
|
help="new bing cookies path if use new bing",
|
101
113
|
)
|
102
114
|
group.add_argument(
|
103
|
-
"--bot",
|
115
|
+
"--bot",
|
116
|
+
dest="bot",
|
117
|
+
help="bot type",
|
118
|
+
choices=["gpt3", "chatgptapi", "newbing", "glm"],
|
104
119
|
)
|
105
120
|
parser.add_argument(
|
106
121
|
"--config",
|
@@ -129,6 +144,8 @@ def main():
|
|
129
144
|
)
|
130
145
|
|
131
146
|
options = parser.parse_args()
|
147
|
+
if options.bot == "glm" and options.stream:
|
148
|
+
raise Exception("For now ChatGLM do not support stream")
|
132
149
|
config = Config.from_options(options)
|
133
150
|
|
134
151
|
miboy = MiGPT(config)
|
xiaogpt/config.py
CHANGED
@@ -60,6 +60,7 @@ class Config:
|
|
60
60
|
account: str = os.getenv("MI_USER", "")
|
61
61
|
password: str = os.getenv("MI_PASS", "")
|
62
62
|
openai_key: str = os.getenv("OPENAI_API_KEY", "")
|
63
|
+
glm_key: str = os.getenv("CHATGLM_KEY", "")
|
63
64
|
proxy: str | None = None
|
64
65
|
mi_did: str = os.getenv("MI_DID", "")
|
65
66
|
keyword: Iterable[str] = KEY_WORD
|
xiaogpt/xiaogpt.py
CHANGED
@@ -356,7 +356,10 @@ class MiGPT:
|
|
356
356
|
if not self.config.stream:
|
357
357
|
async with ClientSession(trust_env=True) as session:
|
358
358
|
openai.aiosession.set(session)
|
359
|
-
|
359
|
+
if self.config.bot == "glm":
|
360
|
+
answer = self._chatbot.ask(query, **self.config.gpt_options)
|
361
|
+
else:
|
362
|
+
answer = await self.chatbot.ask(query, **self.config.gpt_options)
|
360
363
|
message = self._normalize(answer) if answer else ""
|
361
364
|
yield message
|
362
365
|
return
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xiaogpt
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.51
|
4
4
|
Summary: Play ChatGPT with xiaomi AI speaker
|
5
5
|
Author-Email: yihong0618 <zouzou0208@gmail.com>
|
6
6
|
License: MIT
|
@@ -13,6 +13,7 @@ Requires-Dist: miservice_fork
|
|
13
13
|
Requires-Dist: openai
|
14
14
|
Requires-Dist: aiohttp
|
15
15
|
Requires-Dist: rich
|
16
|
+
Requires-Dist: zhipuai
|
16
17
|
Requires-Dist: edge-tts>=6.1.3
|
17
18
|
Requires-Dist: EdgeGPT==0.1.26
|
18
19
|
Description-Content-Type: text/markdown
|
@@ -36,6 +37,7 @@ Play ChatGPT with Xiaomi AI Speaker
|
|
36
37
|
- GPT3
|
37
38
|
- ChatGPT
|
38
39
|
- New Bing
|
40
|
+
- [ChatGLM](http://open.bigmodel.cn/)
|
39
41
|
|
40
42
|
## Windows 获取小米音响DID
|
41
43
|
|
@@ -110,6 +112,9 @@ python3 xiaogpt.py --hardware LX06 --mute_xiaoai --stream
|
|
110
112
|
# 如果你想使用 gpt3 ai
|
111
113
|
export OPENAI_API_KEY=${your_api_key}
|
112
114
|
python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gpt3
|
115
|
+
|
116
|
+
# 如果你想使用 ChatGLM api
|
117
|
+
python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_glm --glm_key ${glm_key}
|
113
118
|
```
|
114
119
|
|
115
120
|
## config.json
|
@@ -141,6 +146,7 @@ python3 xiaogpt.py
|
|
141
146
|
```
|
142
147
|
|
143
148
|
具体参数作用请参考 [Open AI API 文档](https://platform.openai.com/docs/api-reference/chat/create)。
|
149
|
+
ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
|
144
150
|
## 配置项说明
|
145
151
|
|
146
152
|
| 参数 | 说明 | 默认值 |
|
@@ -149,6 +155,7 @@ python3 xiaogpt.py
|
|
149
155
|
| account | 小爱账户 | |
|
150
156
|
| password | 小爱账户密码 | |
|
151
157
|
| openai_key | openai的apikey | |
|
158
|
+
| glm_key | chatglm 的 apikey | |
|
152
159
|
| cookie | 小爱账户cookie (如果用上面密码登录可以不填) | |
|
153
160
|
| mi_did | 设备did | |
|
154
161
|
| use_command | 使用 MI command 与小爱交互 | `false` |
|
@@ -0,0 +1,17 @@
|
|
1
|
+
xiaogpt-1.51.dist-info/METADATA,sha256=7OOFi4_MDsknspD3Dd5w7kZ2lhFzc551vS9Saa-60Jw,12425
|
2
|
+
xiaogpt-1.51.dist-info/WHEEL,sha256=g58cvAsF5_9d0VXJuk7F0rhl6nAjUc5P9vx880WkZtI,90
|
3
|
+
xiaogpt-1.51.dist-info/entry_points.txt,sha256=zLFzA72qQ_eWBepdA2YU5vdXFqORH8wXhv2Ox1vnYP8,46
|
4
|
+
xiaogpt-1.51.dist-info/licenses/LICENSE,sha256=XdClh516MvlnOf9749JZHCxSB7y6_fyXcWmLDz6IkZY,1063
|
5
|
+
xiaogpt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
xiaogpt/__main__.py,sha256=MSmt_5Xg84uHqzTN38JwgseJK8rsJn_11A8WD99VtEo,61
|
7
|
+
xiaogpt/bot/__init__.py,sha256=A_kVOZY4tiW8V7V_MP85Ij8PyjS3KaUuCzRKMGeJr7Y,707
|
8
|
+
xiaogpt/bot/base_bot.py,sha256=kzbUw1eQrgFqkE_eZZrWmcbPdwFrQezJBLm7cJAM8qw,554
|
9
|
+
xiaogpt/bot/chatgptapi_bot.py,sha256=XcePzPpTo5ofVJtT6IBjSRjj0aoppdJ8Zs18spAc76o,3280
|
10
|
+
xiaogpt/bot/glm_bot.py,sha256=u6vXAvsveHgqGcrDlY2TUnTWxMc8gI1VoXU4x2zlkaE,1252
|
11
|
+
xiaogpt/bot/gpt3_bot.py,sha256=c_37SMs_karXH3lKuyeyNZA5iGyj5uzErVdbuGA1GtA,1638
|
12
|
+
xiaogpt/bot/newbing_bot.py,sha256=OBTZYWEqd3sfPl_0BrQxXZC79l8-l-2ikYFIhc4plqI,1996
|
13
|
+
xiaogpt/cli.py,sha256=qcVekNdynS-sxn5WqZGDcUweYd12JD4rUZm6FAIrxaA,3821
|
14
|
+
xiaogpt/config.py,sha256=CioOI4UMHmFcvsEoGIZI41Gc1Z-oI0Yh3i3wc-1C93o,5366
|
15
|
+
xiaogpt/utils.py,sha256=kJ8nOBkilEoo1i2uUSp9tkUWV4pWrd5_EzEicZXzNjY,2071
|
16
|
+
xiaogpt/xiaogpt.py,sha256=_IQAxihPqjhVAhAuYcUFf1QlPZaGELqus0D9ioEUeeI,18700
|
17
|
+
xiaogpt-1.51.dist-info/RECORD,,
|
xiaogpt-1.46.dist-info/RECORD
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
xiaogpt-1.46.dist-info/METADATA,sha256=tjWzKlMShGwc88kMhdhkSWv21f0G6m5sfEEaBbnRabg,12066
|
2
|
-
xiaogpt-1.46.dist-info/WHEEL,sha256=2pzpU5yX8ZDRkL1JJPwjqHXoJgM2dqtofaxvD6IHFj4,90
|
3
|
-
xiaogpt-1.46.dist-info/entry_points.txt,sha256=zLFzA72qQ_eWBepdA2YU5vdXFqORH8wXhv2Ox1vnYP8,46
|
4
|
-
xiaogpt-1.46.dist-info/licenses/LICENSE,sha256=XdClh516MvlnOf9749JZHCxSB7y6_fyXcWmLDz6IkZY,1063
|
5
|
-
xiaogpt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
xiaogpt/__main__.py,sha256=MSmt_5Xg84uHqzTN38JwgseJK8rsJn_11A8WD99VtEo,61
|
7
|
-
xiaogpt/bot/__init__.py,sha256=ggkvJF_CgTJkYGvklIfKQalM5MyshZHShl5vugLZTiY,639
|
8
|
-
xiaogpt/bot/base_bot.py,sha256=kzbUw1eQrgFqkE_eZZrWmcbPdwFrQezJBLm7cJAM8qw,554
|
9
|
-
xiaogpt/bot/chatgptapi_bot.py,sha256=XcePzPpTo5ofVJtT6IBjSRjj0aoppdJ8Zs18spAc76o,3280
|
10
|
-
xiaogpt/bot/gpt3_bot.py,sha256=D9F_8ZGKp264ro6aTCzV3PGZ3ZSdj__-Idi5_xmkga0,1605
|
11
|
-
xiaogpt/bot/newbing_bot.py,sha256=OBTZYWEqd3sfPl_0BrQxXZC79l8-l-2ikYFIhc4plqI,1996
|
12
|
-
xiaogpt/cli.py,sha256=YP8OcSN0Xqw7FRhp0VRb6SSBND-czYVi2BhKITHnki8,3415
|
13
|
-
xiaogpt/config.py,sha256=O-hGXaaDvHFjpwWxSrLxfdGaO7OxJILfn99swElGkCs,5318
|
14
|
-
xiaogpt/utils.py,sha256=kJ8nOBkilEoo1i2uUSp9tkUWV4pWrd5_EzEicZXzNjY,2071
|
15
|
-
xiaogpt/xiaogpt.py,sha256=OByDLqV2AmDZ-QsJIgCnR2b8A0b2O-d7nqMAF-0z2M8,18548
|
16
|
-
xiaogpt-1.46.dist-info/RECORD,,
|
File without changes
|
File without changes
|