xiaogpt 1.51__py3-none-any.whl → 1.60__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/bard_bot.py +32 -0
- xiaogpt/bot/chatgptapi_bot.py +12 -4
- xiaogpt/bot/glm_bot.py +6 -2
- xiaogpt/bot/gpt3_bot.py +10 -2
- xiaogpt/bot/newbing_bot.py +9 -2
- xiaogpt/cli.py +14 -2
- xiaogpt/config.py +5 -0
- xiaogpt/xiaogpt.py +4 -3
- {xiaogpt-1.51.dist-info → xiaogpt-1.60.dist-info}/METADATA +7 -2
- xiaogpt-1.60.dist-info/RECORD +18 -0
- {xiaogpt-1.51.dist-info → xiaogpt-1.60.dist-info}/WHEEL +1 -1
- xiaogpt-1.51.dist-info/RECORD +0 -17
- {xiaogpt-1.51.dist-info → xiaogpt-1.60.dist-info}/entry_points.txt +0 -0
- {xiaogpt-1.51.dist-info → xiaogpt-1.60.dist-info}/licenses/LICENSE +0 -0
xiaogpt/bot/__init__.py
CHANGED
@@ -5,6 +5,7 @@ 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
7
|
from xiaogpt.bot.glm_bot import GLMBot
|
8
|
+
from xiaogpt.bot.bard_bot import BardBot
|
8
9
|
from xiaogpt.config import Config
|
9
10
|
|
10
11
|
BOTS: dict[str, type[BaseBot]] = {
|
@@ -12,6 +13,7 @@ BOTS: dict[str, type[BaseBot]] = {
|
|
12
13
|
"newbing": NewBingBot,
|
13
14
|
"chatgptapi": ChatGPTBot,
|
14
15
|
"glm": GLMBot,
|
16
|
+
"bard": BardBot,
|
15
17
|
}
|
16
18
|
|
17
19
|
|
@@ -22,4 +24,4 @@ def get_bot(config: Config) -> BaseBot:
|
|
22
24
|
raise ValueError(f"Unsupported bot {config.bot}, must be one of {list(BOTS)}")
|
23
25
|
|
24
26
|
|
25
|
-
__all__ = ["GPT3Bot", "ChatGPTBot", "NewBingBot", "GLMBot", "get_bot"]
|
27
|
+
__all__ = ["GPT3Bot", "ChatGPTBot", "NewBingBot", "GLMBot", "BardBot", "get_bot"]
|
xiaogpt/bot/bard_bot.py
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
"""ChatGLM bot"""
|
2
|
+
from __future__ import annotations
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
from bardapi import BardAsync
|
6
|
+
from rich import print
|
7
|
+
|
8
|
+
from xiaogpt.bot.base_bot import BaseBot
|
9
|
+
|
10
|
+
|
11
|
+
class BardBot(BaseBot):
|
12
|
+
def __init__(
|
13
|
+
self,
|
14
|
+
bard_token: str,
|
15
|
+
) -> None:
|
16
|
+
self._bot = BardAsync(token=bard_token)
|
17
|
+
self.history = []
|
18
|
+
|
19
|
+
@classmethod
|
20
|
+
def from_config(cls, config):
|
21
|
+
return cls(bard_token=config.bard_token)
|
22
|
+
|
23
|
+
async def ask(self, query, **options):
|
24
|
+
try:
|
25
|
+
r = await self._bot.get_answer(query)
|
26
|
+
except Exception as e:
|
27
|
+
print(str(e))
|
28
|
+
print(r["content"])
|
29
|
+
return r["content"]
|
30
|
+
|
31
|
+
def ask_stream(self, query: str, **options: Any):
|
32
|
+
raise Exception("Bard do not support stream")
|
xiaogpt/bot/chatgptapi_bot.py
CHANGED
@@ -48,7 +48,11 @@ class ChatGPTBot(BaseBot):
|
|
48
48
|
ms.append({"role": "assistant", "content": h[1]})
|
49
49
|
ms.append({"role": "user", "content": f"{query}"})
|
50
50
|
kwargs = {**self.default_options, **options}
|
51
|
-
|
51
|
+
try:
|
52
|
+
completion = await openai.ChatCompletion.acreate(messages=ms, **kwargs)
|
53
|
+
except Exception as e:
|
54
|
+
print(str(e))
|
55
|
+
return ""
|
52
56
|
message = (
|
53
57
|
completion["choices"][0]
|
54
58
|
.get("message")
|
@@ -72,9 +76,13 @@ class ChatGPTBot(BaseBot):
|
|
72
76
|
kwargs = {"model": "gpt-3.5-turbo", **options}
|
73
77
|
if openai.api_type == "azure":
|
74
78
|
kwargs["deployment_id"] = self.deployment_id
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
try:
|
80
|
+
completion = await openai.ChatCompletion.acreate(
|
81
|
+
messages=ms, stream=True, **kwargs
|
82
|
+
)
|
83
|
+
except Exception as e:
|
84
|
+
print(str(e))
|
85
|
+
return
|
78
86
|
|
79
87
|
async def text_gen():
|
80
88
|
async for event in completion:
|
xiaogpt/bot/glm_bot.py
CHANGED
@@ -30,7 +30,11 @@ class GLMBot(BaseBot):
|
|
30
30
|
kwargs = {**self.default_options, **options}
|
31
31
|
kwargs["prompt"] = ms
|
32
32
|
ms.append({"role": "user", "content": f"{query}"})
|
33
|
-
|
33
|
+
try:
|
34
|
+
r = zhipuai.model_api.sse_invoke(**kwargs)
|
35
|
+
except Exception as e:
|
36
|
+
print(str(e))
|
37
|
+
return
|
34
38
|
message = ""
|
35
39
|
for i in r.events():
|
36
40
|
message += str(i.data)
|
@@ -43,4 +47,4 @@ class GLMBot(BaseBot):
|
|
43
47
|
return message
|
44
48
|
|
45
49
|
def ask_stream(self, query: str, **options: Any):
|
46
|
-
|
50
|
+
raise Exception("GLM do not support stream")
|
xiaogpt/bot/gpt3_bot.py
CHANGED
@@ -29,7 +29,11 @@ class GPT3Bot(BaseBot):
|
|
29
29
|
"top_p": 1,
|
30
30
|
**options,
|
31
31
|
}
|
32
|
-
|
32
|
+
try:
|
33
|
+
completion = await openai.Completion.acreate(**data)
|
34
|
+
except Exception as e:
|
35
|
+
print(str(e))
|
36
|
+
return ""
|
33
37
|
print(completion["choices"][0]["text"])
|
34
38
|
return completion["choices"][0]["text"]
|
35
39
|
|
@@ -43,7 +47,11 @@ class GPT3Bot(BaseBot):
|
|
43
47
|
"stream": True,
|
44
48
|
**options,
|
45
49
|
}
|
46
|
-
|
50
|
+
try:
|
51
|
+
completion = await openai.Completion.acreate(**data)
|
52
|
+
except Exception as e:
|
53
|
+
print(str(e))
|
54
|
+
return
|
47
55
|
|
48
56
|
async def text_gen():
|
49
57
|
async for event in completion:
|
xiaogpt/bot/newbing_bot.py
CHANGED
@@ -40,13 +40,20 @@ class NewBingBot(BaseBot):
|
|
40
40
|
async def ask(self, query, **options):
|
41
41
|
kwargs = {"conversation_style": ConversationStyle.balanced, **options}
|
42
42
|
completion = await self._bot.ask(prompt=query, **kwargs)
|
43
|
-
|
43
|
+
try:
|
44
|
+
text = self.clean_text(completion["item"]["messages"][1]["text"])
|
45
|
+
except Exception as e:
|
46
|
+
print(str(e))
|
47
|
+
return
|
44
48
|
print(text)
|
45
49
|
return text
|
46
50
|
|
47
51
|
async def ask_stream(self, query, **options):
|
48
52
|
kwargs = {"conversation_style": ConversationStyle.balanced, **options}
|
49
|
-
|
53
|
+
try:
|
54
|
+
completion = self._bot.ask_stream(prompt=query, **kwargs)
|
55
|
+
except Exception as e:
|
56
|
+
return
|
50
57
|
|
51
58
|
async def text_gen():
|
52
59
|
current = ""
|
xiaogpt/cli.py
CHANGED
@@ -32,6 +32,11 @@ def main():
|
|
32
32
|
dest="glm_key",
|
33
33
|
help="chatglm api key",
|
34
34
|
)
|
35
|
+
parser.add_argument(
|
36
|
+
"--bard_token",
|
37
|
+
dest="bard_token",
|
38
|
+
help="google bard token see https://github.com/dsdanielpark/Bard-API",
|
39
|
+
)
|
35
40
|
parser.add_argument(
|
36
41
|
"--proxy",
|
37
42
|
dest="proxy",
|
@@ -106,6 +111,13 @@ def main():
|
|
106
111
|
const="glm",
|
107
112
|
help="if use chatglm",
|
108
113
|
)
|
114
|
+
group.add_argument(
|
115
|
+
"--use_bard",
|
116
|
+
dest="bot",
|
117
|
+
action="store_const",
|
118
|
+
const="bard",
|
119
|
+
help="if use bard",
|
120
|
+
)
|
109
121
|
parser.add_argument(
|
110
122
|
"--bing_cookie_path",
|
111
123
|
dest="bing_cookie_path",
|
@@ -115,7 +127,7 @@ def main():
|
|
115
127
|
"--bot",
|
116
128
|
dest="bot",
|
117
129
|
help="bot type",
|
118
|
-
choices=["gpt3", "chatgptapi", "newbing", "glm"],
|
130
|
+
choices=["gpt3", "chatgptapi", "newbing", "glm", "bard"],
|
119
131
|
)
|
120
132
|
parser.add_argument(
|
121
133
|
"--config",
|
@@ -144,7 +156,7 @@ def main():
|
|
144
156
|
)
|
145
157
|
|
146
158
|
options = parser.parse_args()
|
147
|
-
if options.bot
|
159
|
+
if options.bot in ["glm", "bard"] and options.stream:
|
148
160
|
raise Exception("For now ChatGLM do not support stream")
|
149
161
|
config = Config.from_options(options)
|
150
162
|
|
xiaogpt/config.py
CHANGED
@@ -61,6 +61,7 @@ class Config:
|
|
61
61
|
password: str = os.getenv("MI_PASS", "")
|
62
62
|
openai_key: str = os.getenv("OPENAI_API_KEY", "")
|
63
63
|
glm_key: str = os.getenv("CHATGLM_KEY", "")
|
64
|
+
bard_token: str = os.getenv("BARD_TOKEN", "")
|
64
65
|
proxy: str | None = None
|
65
66
|
mi_did: str = os.getenv("MI_DID", "")
|
66
67
|
keyword: Iterable[str] = KEY_WORD
|
@@ -139,5 +140,9 @@ class Config:
|
|
139
140
|
key, value = "bot", "gpt3"
|
140
141
|
elif key == "use_newbing":
|
141
142
|
key, value = "bot", "newbing"
|
143
|
+
elif key == "use_glm":
|
144
|
+
key, value = "bot", "glm"
|
145
|
+
elif key == "use_bard":
|
146
|
+
key, value = "bot", "bard"
|
142
147
|
result[key] = value
|
143
148
|
return result
|
xiaogpt/xiaogpt.py
CHANGED
@@ -421,6 +421,7 @@ class MiGPT:
|
|
421
421
|
)
|
422
422
|
|
423
423
|
async def run_forever(self):
|
424
|
+
ask_name = self.config.bot.upper()
|
424
425
|
async with ClientSession() as session:
|
425
426
|
await self.init_all_data(session)
|
426
427
|
task = asyncio.create_task(self.poll_latest_ask())
|
@@ -470,7 +471,7 @@ class MiGPT:
|
|
470
471
|
else:
|
471
472
|
# waiting for xiaoai speaker done
|
472
473
|
await asyncio.sleep(8)
|
473
|
-
await self.do_tts("正在问
|
474
|
+
await self.do_tts(f"正在问{ask_name}请耐心等待")
|
474
475
|
try:
|
475
476
|
print(
|
476
477
|
"以下是小爱的回答: ",
|
@@ -478,7 +479,7 @@ class MiGPT:
|
|
478
479
|
)
|
479
480
|
except IndexError:
|
480
481
|
print("小爱没回")
|
481
|
-
print("以下是
|
482
|
+
print(f"以下是 {ask_name} 的回答: ", end="")
|
482
483
|
try:
|
483
484
|
if not self.config.enable_edge_tts:
|
484
485
|
async for message in self.ask_gpt(query):
|
@@ -492,7 +493,7 @@ class MiGPT:
|
|
492
493
|
await self.edge_tts(self.ask_gpt(query), tts_lang)
|
493
494
|
print("回答完毕")
|
494
495
|
except Exception as e:
|
495
|
-
print(f"
|
496
|
+
print(f"{ask_name} 回答出错 {str(e)}")
|
496
497
|
if self.in_conversation:
|
497
498
|
print(f"继续对话, 或用`{self.config.end_conversation}`结束对话")
|
498
499
|
await self.wakeup_xiaoai()
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: xiaogpt
|
3
|
-
Version: 1.
|
4
|
-
Summary: Play ChatGPT with xiaomi AI speaker
|
3
|
+
Version: 1.60
|
4
|
+
Summary: Play ChatGPT or other LLM with xiaomi AI speaker
|
5
5
|
Author-Email: yihong0618 <zouzou0208@gmail.com>
|
6
6
|
License: MIT
|
7
7
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -14,6 +14,7 @@ Requires-Dist: openai
|
|
14
14
|
Requires-Dist: aiohttp
|
15
15
|
Requires-Dist: rich
|
16
16
|
Requires-Dist: zhipuai
|
17
|
+
Requires-Dist: bardapi
|
17
18
|
Requires-Dist: edge-tts>=6.1.3
|
18
19
|
Requires-Dist: EdgeGPT==0.1.26
|
19
20
|
Description-Content-Type: text/markdown
|
@@ -115,6 +116,8 @@ python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gpt3
|
|
115
116
|
|
116
117
|
# 如果你想使用 ChatGLM api
|
117
118
|
python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_glm --glm_key ${glm_key}
|
119
|
+
# 如果你想使用 google 的 bard
|
120
|
+
python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_bard --bard_token ${bard_token}
|
118
121
|
```
|
119
122
|
|
120
123
|
## config.json
|
@@ -147,6 +150,7 @@ python3 xiaogpt.py
|
|
147
150
|
|
148
151
|
具体参数作用请参考 [Open AI API 文档](https://platform.openai.com/docs/api-reference/chat/create)。
|
149
152
|
ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
|
153
|
+
Bard-API [参考](https://github.com/dsdanielpark/Bard-API)
|
150
154
|
## 配置项说明
|
151
155
|
|
152
156
|
| 参数 | 说明 | 默认值 |
|
@@ -156,6 +160,7 @@ ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
|
|
156
160
|
| password | 小爱账户密码 | |
|
157
161
|
| openai_key | openai的apikey | |
|
158
162
|
| glm_key | chatglm 的 apikey | |
|
163
|
+
| bard_token | bard 的 token 参考 [Bard-API](https://github.com/dsdanielpark/Bard-API) | |
|
159
164
|
| cookie | 小爱账户cookie (如果用上面密码登录可以不填) | |
|
160
165
|
| mi_did | 设备did | |
|
161
166
|
| use_command | 使用 MI command 与小爱交互 | `false` |
|
@@ -0,0 +1,18 @@
|
|
1
|
+
xiaogpt-1.60.dist-info/METADATA,sha256=R29SaPwyUtu65J7LcGCchYGca_RmwwTzoZLuEuCrDO4,12819
|
2
|
+
xiaogpt-1.60.dist-info/WHEEL,sha256=0QD4Fi8spmPDA9YIWsctxI6ukFf44Zgk0L9495lbqs0,90
|
3
|
+
xiaogpt-1.60.dist-info/entry_points.txt,sha256=zLFzA72qQ_eWBepdA2YU5vdXFqORH8wXhv2Ox1vnYP8,46
|
4
|
+
xiaogpt-1.60.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=CrxzcQXn4DZVw83l8qXWQOZxSFbo7570mjyTcZTi6Jk,780
|
8
|
+
xiaogpt/bot/bard_bot.py,sha256=UKgfLLKwte8XBZFl7H7bAQRZM17qbI8Sa2AUrtzBrwM,774
|
9
|
+
xiaogpt/bot/base_bot.py,sha256=kzbUw1eQrgFqkE_eZZrWmcbPdwFrQezJBLm7cJAM8qw,554
|
10
|
+
xiaogpt/bot/chatgptapi_bot.py,sha256=cq0CwXD6ynNw7hB-bYubP0Nsz7pT49JYKp0_UjRoIps,3477
|
11
|
+
xiaogpt/bot/glm_bot.py,sha256=aenSgy6w5GKCAlJ9vrmNUliHOgVqen8OHsDpcLYWzj8,1385
|
12
|
+
xiaogpt/bot/gpt3_bot.py,sha256=Ju_c9izW09XbCCSgZTp-3Rjz1zBMeBGj19zH0UwqGFw,1827
|
13
|
+
xiaogpt/bot/newbing_bot.py,sha256=fRRrNnnw6xVFlkp4aQ37XRrOCnZmc2tCyMmW7BFgrOE,2156
|
14
|
+
xiaogpt/cli.py,sha256=DXSH-5YEejQdPkrfbrKoykCglkvyUzvVN7-sRHk2kEI,4152
|
15
|
+
xiaogpt/config.py,sha256=6_GMtOx2_CMHfZwlC0q7JKm9QI1oF04P1G3zpB1Fhks,5604
|
16
|
+
xiaogpt/utils.py,sha256=kJ8nOBkilEoo1i2uUSp9tkUWV4pWrd5_EzEicZXzNjY,2071
|
17
|
+
xiaogpt/xiaogpt.py,sha256=KeRQqXL6DV1_nG0tw0sxCiZFQwXQ-mpULvnia43JboU,18769
|
18
|
+
xiaogpt-1.60.dist-info/RECORD,,
|
xiaogpt-1.51.dist-info/RECORD
DELETED
@@ -1,17 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|