xiaogpt 2.32__tar.gz → 2.41__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.
Files changed (30) hide show
  1. {xiaogpt-2.32 → xiaogpt-2.41}/PKG-INFO +6 -18
  2. {xiaogpt-2.32 → xiaogpt-2.41}/README.md +5 -16
  3. {xiaogpt-2.32 → xiaogpt-2.41}/pyproject.toml +1 -2
  4. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/__init__.py +0 -6
  5. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/cli.py +0 -23
  6. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/config.py +1 -6
  7. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/tts/azure.py +1 -0
  8. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/tts/base.py +14 -19
  9. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/xiaogpt.py +0 -2
  10. xiaogpt-2.32/xiaogpt/bot/bard_bot.py +0 -37
  11. xiaogpt-2.32/xiaogpt/bot/gpt3_bot.py +0 -90
  12. {xiaogpt-2.32 → xiaogpt-2.41}/LICENSE +0 -0
  13. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/__init__.py +0 -0
  14. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/__main__.py +0 -0
  15. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/base_bot.py +0 -0
  16. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/chatgptapi_bot.py +0 -0
  17. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/gemini_bot.py +0 -0
  18. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/glm_bot.py +0 -0
  19. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/langchain_bot.py +0 -0
  20. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/newbing_bot.py +0 -0
  21. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/bot/qwen_bot.py +0 -0
  22. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/langchain/callbacks.py +0 -0
  23. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/langchain/chain.py +0 -0
  24. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/langchain/examples/email/mail_box.py +0 -0
  25. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/langchain/examples/email/mail_summary_tools.py +0 -0
  26. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/tts/__init__.py +0 -0
  27. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/tts/edge.py +0 -0
  28. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/tts/mi.py +0 -0
  29. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/tts/openai.py +0 -0
  30. {xiaogpt-2.32 → xiaogpt-2.41}/xiaogpt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xiaogpt
3
- Version: 2.32
3
+ Version: 2.41
4
4
  Summary: Play ChatGPT or other LLM with xiaomi AI speaker
5
5
  Author-Email: yihong0618 <zouzou0208@gmail.com>
6
6
  License: MIT
@@ -15,7 +15,6 @@ Requires-Dist: aiohttp
15
15
  Requires-Dist: rich
16
16
  Requires-Dist: zhipuai==2.0.1
17
17
  Requires-Dist: httpx==0.24.1
18
- Requires-Dist: bardapi
19
18
  Requires-Dist: edge-tts>=6.1.3
20
19
  Requires-Dist: EdgeGPT==0.1.26
21
20
  Requires-Dist: langchain>=0.0.343
@@ -43,12 +42,10 @@ Play ChatGPT and other LLM with Xiaomi AI Speaker
43
42
 
44
43
  ## 支持的 AI 类型
45
44
 
46
- - GPT3
47
45
  - ChatGPT
48
46
  - New Bing
49
47
  - [ChatGLM](http://open.bigmodel.cn/)
50
48
  - [Gemini](https://makersuite.google.com/app/apikey)
51
- - [Bard](https://github.com/dsdanielpark/Bard-API)
52
49
  - [通义千问](https://help.aliyun.com/zh/dashscope/developer-reference/api-details)
53
50
 
54
51
  ## 获取小米音响DID
@@ -102,7 +99,6 @@ export MI_DID=xxxx
102
99
  - 使用 `--account ${account} --password ${password}`
103
100
  - 如果有能力可以自行替换唤醒词,也可以去掉唤醒词
104
101
  - 使用 `--use_chatgpt_api` 的 api 那样可以更流畅的对话,速度特别快,达到了对话的体验, [openai api](https://platform.openai.com/account/api-keys), 命令 `--use_chatgpt_api`
105
- - 使用 gpt-3 的 api 那样可以更流畅的对话,速度快, 请 google 如何用 [openai api](https://platform.openai.com/account/api-keys) 命令 --use_gpt3
106
102
  - 如果你遇到了墙需要用 Cloudflare Workers 替换 api_base 请使用 `--api_base ${url}` 来替换。 **请注意,此处你输入的api应该是'`https://xxxx/v1`'的字样,域名需要用引号包裹**
107
103
  - 可以跟小爱说 `开始持续对话` 自动进入持续对话状态,`结束持续对话` 结束持续对话状态。
108
104
  - 可以使用 `--tts edge` 来获取更好的 tts 能力
@@ -123,9 +119,6 @@ xiaogpt --hardware LX06 --account ${your_xiaomi_account} --password ${your_passw
123
119
  xiaogpt --hardware LX06 --mute_xiaoai --use_chatgpt_api
124
120
  # 使用流式响应,获得更快的响应
125
121
  xiaogpt --hardware LX06 --mute_xiaoai --stream
126
- # 如果你想使用 gpt3 ai
127
- export OPENAI_API_KEY=${your_api_key}
128
- xiaogpt --hardware LX06 --mute_xiaoai --use_gpt3
129
122
  # 如果你想使用 google 的 gemini
130
123
  xiaogpt --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
131
124
  # 如果你想使用阿里的通义千问
@@ -151,13 +144,8 @@ python3 xiaogpt.py --hardware LX06 --account ${your_xiaomi_account} --password $
151
144
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai
152
145
  # 使用流式响应,获得更快的响应
153
146
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --stream
154
- # 如果你想使用 gpt3 ai
155
- export OPENAI_API_KEY=${your_api_key}
156
- python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gpt3
157
147
  # 如果你想使用 ChatGLM api
158
148
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_glm --glm_key ${glm_key}
159
- # 如果你想使用 google 的 bard
160
- python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_bard --bard_token ${bard_token}
161
149
  # 如果你想使用 google 的 gemini
162
150
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
163
151
  # 如果你想使用阿里的通义千问
@@ -202,7 +190,6 @@ python3 xiaogpt.py
202
190
 
203
191
  具体参数作用请参考 [Open AI API 文档](https://platform.openai.com/docs/api-reference/chat/create)。
204
192
  ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
205
- Bard-API [参考](https://github.com/dsdanielpark/Bard-API)
206
193
 
207
194
  ## 配置项说明
208
195
 
@@ -216,13 +203,12 @@ Bard-API [参考](https://github.com/dsdanielpark/Bard-API)
216
203
  | glm_key | chatglm 的 apikey | | |
217
204
  | gemini_key | gemini 的 apikey [参考](https://makersuite.google.com/app/apikey) | | |
218
205
  | qwen_key | qwen 的 apikey [参考](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) | | |
219
- | bard_token | bard 的 token 参考 [Bard-API](https://github.com/dsdanielpark/Bard-API) | | |
220
206
  | cookie | 小爱账户cookie (如果用上面密码登录可以不填) | | |
221
207
  | mi_did | 设备did | | |
222
208
  | use_command | 使用 MI command 与小爱交互 | `false` | |
223
209
  | mute_xiaoai | 快速停掉小爱自己的回答 | `true` | |
224
210
  | verbose | 是否打印详细日志 | `false` | |
225
- | bot | 使用的 bot 类型,目前支持gpt3,chatgptapi和newbing | `chatgptapi` | |
211
+ | bot | 使用的 bot 类型,目前支持 chatgptapi,newbing, qwen, gemini | `chatgptapi` | |
226
212
  | tts | 使用的 TTS 类型 | `mi` | `edge`、 `openai`、`azure` |
227
213
  | tts_voice | TTS 的嗓音 | `zh-CN-XiaoxiaoNeural`(edge), `alloy`(openai), `zh-CN-XiaoxiaoMultilingualNeural`(azure) | |
228
214
  | prompt | 自定义prompt | `请用100字以内回答` | |
@@ -315,9 +301,11 @@ docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
315
301
 
316
302
  ### 第三方 TTS
317
303
 
318
- 我们目前支持两种第三方 TTS:edge/openai
304
+ 我们目前支持是三种第三方 TTS:edge/openai/azure
319
305
 
320
306
  [edge-tts](https://github.com/rany2/edge-tts) 提供了类似微软tts的能力
307
+ [azure-tts](https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/9-more-realistic-ai-voices-for-conversations-now-generally/ba-p/4099471) 提供了微软 azure tts 的能力
308
+ [openai-tts](https://platform.openai.com/docs/guides/text-to-speech) 提供了类似 openai tts 的能力
321
309
 
322
310
  #### Usage
323
311
 
@@ -336,7 +324,7 @@ docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
336
324
  edge-tts --list-voices
337
325
  ```
338
326
 
339
- #### 在容器中使用edge-tts
327
+ #### 在容器中使用 edge-tts/azure-tts/openai-tts
340
328
 
341
329
  由于 Edge TTS 启动了一个本地的 HTTP 服务,所以需要将容器的端口映射到宿主机上,并且指定本地机器的 hostname:
342
330
 
@@ -12,12 +12,10 @@ Play ChatGPT and other LLM with Xiaomi AI Speaker
12
12
 
13
13
  ## 支持的 AI 类型
14
14
 
15
- - GPT3
16
15
  - ChatGPT
17
16
  - New Bing
18
17
  - [ChatGLM](http://open.bigmodel.cn/)
19
18
  - [Gemini](https://makersuite.google.com/app/apikey)
20
- - [Bard](https://github.com/dsdanielpark/Bard-API)
21
19
  - [通义千问](https://help.aliyun.com/zh/dashscope/developer-reference/api-details)
22
20
 
23
21
  ## 获取小米音响DID
@@ -71,7 +69,6 @@ export MI_DID=xxxx
71
69
  - 使用 `--account ${account} --password ${password}`
72
70
  - 如果有能力可以自行替换唤醒词,也可以去掉唤醒词
73
71
  - 使用 `--use_chatgpt_api` 的 api 那样可以更流畅的对话,速度特别快,达到了对话的体验, [openai api](https://platform.openai.com/account/api-keys), 命令 `--use_chatgpt_api`
74
- - 使用 gpt-3 的 api 那样可以更流畅的对话,速度快, 请 google 如何用 [openai api](https://platform.openai.com/account/api-keys) 命令 --use_gpt3
75
72
  - 如果你遇到了墙需要用 Cloudflare Workers 替换 api_base 请使用 `--api_base ${url}` 来替换。 **请注意,此处你输入的api应该是'`https://xxxx/v1`'的字样,域名需要用引号包裹**
76
73
  - 可以跟小爱说 `开始持续对话` 自动进入持续对话状态,`结束持续对话` 结束持续对话状态。
77
74
  - 可以使用 `--tts edge` 来获取更好的 tts 能力
@@ -92,9 +89,6 @@ xiaogpt --hardware LX06 --account ${your_xiaomi_account} --password ${your_passw
92
89
  xiaogpt --hardware LX06 --mute_xiaoai --use_chatgpt_api
93
90
  # 使用流式响应,获得更快的响应
94
91
  xiaogpt --hardware LX06 --mute_xiaoai --stream
95
- # 如果你想使用 gpt3 ai
96
- export OPENAI_API_KEY=${your_api_key}
97
- xiaogpt --hardware LX06 --mute_xiaoai --use_gpt3
98
92
  # 如果你想使用 google 的 gemini
99
93
  xiaogpt --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
100
94
  # 如果你想使用阿里的通义千问
@@ -120,13 +114,8 @@ python3 xiaogpt.py --hardware LX06 --account ${your_xiaomi_account} --password $
120
114
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai
121
115
  # 使用流式响应,获得更快的响应
122
116
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --stream
123
- # 如果你想使用 gpt3 ai
124
- export OPENAI_API_KEY=${your_api_key}
125
- python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gpt3
126
117
  # 如果你想使用 ChatGLM api
127
118
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_glm --glm_key ${glm_key}
128
- # 如果你想使用 google 的 bard
129
- python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_bard --bard_token ${bard_token}
130
119
  # 如果你想使用 google 的 gemini
131
120
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
132
121
  # 如果你想使用阿里的通义千问
@@ -171,7 +160,6 @@ python3 xiaogpt.py
171
160
 
172
161
  具体参数作用请参考 [Open AI API 文档](https://platform.openai.com/docs/api-reference/chat/create)。
173
162
  ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
174
- Bard-API [参考](https://github.com/dsdanielpark/Bard-API)
175
163
 
176
164
  ## 配置项说明
177
165
 
@@ -185,13 +173,12 @@ Bard-API [参考](https://github.com/dsdanielpark/Bard-API)
185
173
  | glm_key | chatglm 的 apikey | | |
186
174
  | gemini_key | gemini 的 apikey [参考](https://makersuite.google.com/app/apikey) | | |
187
175
  | qwen_key | qwen 的 apikey [参考](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) | | |
188
- | bard_token | bard 的 token 参考 [Bard-API](https://github.com/dsdanielpark/Bard-API) | | |
189
176
  | cookie | 小爱账户cookie (如果用上面密码登录可以不填) | | |
190
177
  | mi_did | 设备did | | |
191
178
  | use_command | 使用 MI command 与小爱交互 | `false` | |
192
179
  | mute_xiaoai | 快速停掉小爱自己的回答 | `true` | |
193
180
  | verbose | 是否打印详细日志 | `false` | |
194
- | bot | 使用的 bot 类型,目前支持gpt3,chatgptapi和newbing | `chatgptapi` | |
181
+ | bot | 使用的 bot 类型,目前支持 chatgptapi,newbing, qwen, gemini | `chatgptapi` | |
195
182
  | tts | 使用的 TTS 类型 | `mi` | `edge`、 `openai`、`azure` |
196
183
  | tts_voice | TTS 的嗓音 | `zh-CN-XiaoxiaoNeural`(edge), `alloy`(openai), `zh-CN-XiaoxiaoMultilingualNeural`(azure) | |
197
184
  | prompt | 自定义prompt | `请用100字以内回答` | |
@@ -284,9 +271,11 @@ docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
284
271
 
285
272
  ### 第三方 TTS
286
273
 
287
- 我们目前支持两种第三方 TTS:edge/openai
274
+ 我们目前支持是三种第三方 TTS:edge/openai/azure
288
275
 
289
276
  [edge-tts](https://github.com/rany2/edge-tts) 提供了类似微软tts的能力
277
+ [azure-tts](https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/9-more-realistic-ai-voices-for-conversations-now-generally/ba-p/4099471) 提供了微软 azure tts 的能力
278
+ [openai-tts](https://platform.openai.com/docs/guides/text-to-speech) 提供了类似 openai tts 的能力
290
279
 
291
280
  #### Usage
292
281
 
@@ -305,7 +294,7 @@ docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
305
294
  edge-tts --list-voices
306
295
  ```
307
296
 
308
- #### 在容器中使用edge-tts
297
+ #### 在容器中使用 edge-tts/azure-tts/openai-tts
309
298
 
310
299
  由于 Edge TTS 启动了一个本地的 HTTP 服务,所以需要将容器的端口映射到宿主机上,并且指定本地机器的 hostname:
311
300
 
@@ -18,7 +18,6 @@ dependencies = [
18
18
  "rich",
19
19
  "zhipuai==2.0.1",
20
20
  "httpx==0.24.1",
21
- "bardapi",
22
21
  "edge-tts>=6.1.3",
23
22
  "EdgeGPT==0.1.26",
24
23
  "langchain>=0.0.343",
@@ -32,7 +31,7 @@ dependencies = [
32
31
  "azure-cognitiveservices-speech>=1.37.0",
33
32
  ]
34
33
  dynamic = []
35
- version = "2.32"
34
+ version = "2.41"
36
35
 
37
36
  [project.license]
38
37
  text = "MIT"
@@ -2,21 +2,17 @@ from __future__ import annotations
2
2
 
3
3
  from xiaogpt.bot.base_bot import BaseBot
4
4
  from xiaogpt.bot.chatgptapi_bot import ChatGPTBot
5
- from xiaogpt.bot.gpt3_bot import GPT3Bot
6
5
  from xiaogpt.bot.newbing_bot import NewBingBot
7
6
  from xiaogpt.bot.glm_bot import GLMBot
8
- from xiaogpt.bot.bard_bot import BardBot
9
7
  from xiaogpt.bot.gemini_bot import GeminiBot
10
8
  from xiaogpt.bot.qwen_bot import QwenBot
11
9
  from xiaogpt.bot.langchain_bot import LangChainBot
12
10
  from xiaogpt.config import Config
13
11
 
14
12
  BOTS: dict[str, type[BaseBot]] = {
15
- "gpt3": GPT3Bot,
16
13
  "newbing": NewBingBot,
17
14
  "chatgptapi": ChatGPTBot,
18
15
  "glm": GLMBot,
19
- "bard": BardBot,
20
16
  "gemini": GeminiBot,
21
17
  "qwen": QwenBot,
22
18
  "langchain": LangChainBot,
@@ -31,11 +27,9 @@ def get_bot(config: Config) -> BaseBot:
31
27
 
32
28
 
33
29
  __all__ = [
34
- "GPT3Bot",
35
30
  "ChatGPTBot",
36
31
  "NewBingBot",
37
32
  "GLMBot",
38
- "BardBot",
39
33
  "GeminiBot",
40
34
  "QwenBot",
41
35
  "get_bot",
@@ -42,11 +42,6 @@ def main():
42
42
  dest="qwen_key",
43
43
  help="Alibaba Qwen api key",
44
44
  )
45
- parser.add_argument(
46
- "--bard_token",
47
- dest="bard_token",
48
- help="google bard token see https://github.com/dsdanielpark/Bard-API",
49
- )
50
45
  parser.add_argument(
51
46
  "--serpapi_api_key",
52
47
  dest="serpapi_api_key",
@@ -114,13 +109,6 @@ def main():
114
109
  choices=["mi", "edge", "openai", "azure"],
115
110
  )
116
111
  bot_group = parser.add_mutually_exclusive_group()
117
- bot_group.add_argument(
118
- "--use_gpt3",
119
- dest="bot",
120
- action="store_const",
121
- const="gpt3",
122
- help="if use openai gpt3 api",
123
- )
124
112
  bot_group.add_argument(
125
113
  "--use_chatgpt_api",
126
114
  dest="bot",
@@ -149,13 +137,6 @@ def main():
149
137
  const="glm",
150
138
  help="if use chatglm",
151
139
  )
152
- bot_group.add_argument(
153
- "--use_bard",
154
- dest="bot",
155
- action="store_const",
156
- const="bard",
157
- help="if use bard",
158
- )
159
140
  bot_group.add_argument(
160
141
  "--use_qwen",
161
142
  dest="bot",
@@ -180,11 +161,9 @@ def main():
180
161
  dest="bot",
181
162
  help="bot type",
182
163
  choices=[
183
- "gpt3",
184
164
  "chatgptapi",
185
165
  "newbing",
186
166
  "glm",
187
- "bard",
188
167
  "gemini",
189
168
  "langchain",
190
169
  "qwen",
@@ -209,8 +188,6 @@ def main():
209
188
  )
210
189
 
211
190
  options = parser.parse_args()
212
- if options.bot in ["bard"] and options.stream:
213
- raise Exception("For now Bard do not support stream")
214
191
  config = Config.from_options(options)
215
192
 
216
193
  miboy = MiGPT(config)
@@ -64,7 +64,6 @@ class Config:
64
64
  glm_key: str = os.getenv("CHATGLM_KEY", "")
65
65
  gemini_key: str = os.getenv("GEMINI_KEY", "") # keep the old rule
66
66
  qwen_key: str = os.getenv("DASHSCOPE_API_KEY", "") # keep the old rule
67
- bard_token: str = os.getenv("BARD_TOKEN", "")
68
67
  serpapi_api_key: str = os.getenv("SERPAPI_API_KEY", "")
69
68
  proxy: str | None = None
70
69
  mi_did: str = os.getenv("MI_DID", "")
@@ -107,7 +106,7 @@ class Config:
107
106
  "Using Azure OpenAI needs deployment_id, read this: "
108
107
  "https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/chatgpt?pivots=programming-language-chat-completions"
109
108
  )
110
- if self.bot in ["chatgptapi", "gpt3"]:
109
+ if self.bot in ["chatgptapi"]:
111
110
  if not self.openai_key:
112
111
  raise Exception(
113
112
  "Using GPT api needs openai API key, please google how to"
@@ -147,8 +146,6 @@ class Config:
147
146
  value = [kw for kw in value if kw]
148
147
  elif key == "use_chatgpt_api":
149
148
  key, value = "bot", "chatgptapi"
150
- elif key == "use_gpt3":
151
- key, value = "bot", "gpt3"
152
149
  elif key == "use_newbing":
153
150
  key, value = "bot", "newbing"
154
151
  elif key == "use_glm":
@@ -157,8 +154,6 @@ class Config:
157
154
  key, value = "bot", "gemini"
158
155
  elif key == "use_qwen":
159
156
  key, value = "bot", "qwen"
160
- elif key == "use_bard":
161
- key, value = "bot", "bard"
162
157
  elif key == "use_langchain":
163
158
  key, value = "bot", "langchain"
164
159
  elif key == "enable_edge_tts":
@@ -32,6 +32,7 @@ class AzureTTS(AudioFileTTS):
32
32
  # Check result
33
33
  if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
34
34
  logger.debug("Speech synthesized for text [{}]".format(text))
35
+
35
36
  return Path(output_file.name), calculate_tts_elapse(text)
36
37
  elif result.reason == speechsdk.ResultReason.Canceled:
37
38
  cancellation_details = result.cancellation_details
@@ -106,26 +106,21 @@ class AudioFileTTS(TTS):
106
106
  finished.set()
107
107
 
108
108
  task = asyncio.create_task(worker())
109
- while not queue.empty() or not finished.is_set():
110
- done, other = await asyncio.wait(
111
- [
112
- asyncio.ensure_future(queue.get()),
113
- asyncio.ensure_future(finished.wait()),
114
- ],
115
- return_when=asyncio.FIRST_COMPLETED,
116
- )
117
- if other:
118
- other.pop().cancel()
119
109
 
120
- result = done.pop().result()
121
- if result is True:
122
- # finished is set, break the loop
123
- break
124
- else:
125
- url, duration = result
126
- logger.debug("Playing URL %s (%s seconds)", url, duration)
127
- await self.mina_service.play_by_url(self.device_id, url)
128
- await self.wait_for_duration(duration)
110
+ while True:
111
+ try:
112
+ url, duration = queue.get_nowait()
113
+ except asyncio.QueueEmpty:
114
+ if finished.is_set():
115
+ break
116
+ else:
117
+ await asyncio.sleep(0.1)
118
+ continue
119
+ logger.debug("Playing URL %s (%s seconds)", url, duration)
120
+ await asyncio.gather(
121
+ self.mina_service.play_by_url(self.device_id, url),
122
+ self.wait_for_duration(duration),
123
+ )
129
124
  await task
130
125
 
131
126
  def _start_http_server(self):
@@ -181,8 +181,6 @@ class MiGPT:
181
181
  )
182
182
 
183
183
  def need_change_prompt(self, record):
184
- if self.config.bot == "gpt3":
185
- return False
186
184
  query = record.get("query", "")
187
185
  return query.startswith(tuple(self.config.change_prompt_keyword))
188
186
 
@@ -1,37 +0,0 @@
1
- """ChatGLM bot"""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import Any
6
-
7
- from rich import print
8
-
9
- from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
10
-
11
-
12
- class BardBot(ChatHistoryMixin, BaseBot):
13
- name = "Bard"
14
-
15
- def __init__(
16
- self,
17
- bard_token: str,
18
- ) -> None:
19
- from bardapi import BardAsync
20
-
21
- self._bot = BardAsync(token=bard_token)
22
- self.history = []
23
-
24
- @classmethod
25
- def from_config(cls, config):
26
- return cls(bard_token=config.bard_token)
27
-
28
- async def ask(self, query, **options):
29
- try:
30
- r = await self._bot.get_answer(query)
31
- except Exception as e:
32
- print(str(e))
33
- print(r["content"])
34
- return r["content"]
35
-
36
- def ask_stream(self, query: str, **options: Any):
37
- raise Exception("Bard do not support stream")
@@ -1,90 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import dataclasses
4
- from typing import ClassVar
5
-
6
- import httpx
7
- from rich import print
8
-
9
- from xiaogpt.bot.base_bot import BaseBot, ChatHistoryMixin
10
- from xiaogpt.utils import split_sentences
11
-
12
-
13
- @dataclasses.dataclass
14
- class GPT3Bot(ChatHistoryMixin, BaseBot):
15
- name: ClassVar[str] = "GPT3"
16
- openai_key: str
17
- api_base: str | None = None
18
- proxy: str | None = None
19
- history: list[tuple[str, str]] = dataclasses.field(default_factory=list, init=False)
20
-
21
- @classmethod
22
- def from_config(cls, config):
23
- return cls(
24
- openai_key=config.openai_key, api_base=config.api_base, proxy=config.proxy
25
- )
26
-
27
- async def ask(self, query, **options):
28
- import openai
29
-
30
- data = {
31
- "prompt": query,
32
- "model": "text-davinci-003",
33
- "max_tokens": 1024,
34
- "temperature": 1,
35
- "top_p": 1,
36
- **options,
37
- }
38
- httpx_kwargs = {}
39
- if self.config.proxy:
40
- httpx_kwargs["proxies"] = self.config.proxy
41
- async with httpx.AsyncClient(trust_env=True, **httpx_kwargs) as sess:
42
- client = openai.AsyncOpenAI(
43
- api_key=self.openai_key, http_client=sess, base_url=self.api_base
44
- )
45
- try:
46
- completion = await client.completions.create(**data)
47
- except Exception as e:
48
- print(str(e))
49
- return ""
50
- print(completion.choices[0].text)
51
- return completion.choices[0].text
52
-
53
- async def ask_stream(self, query, **options):
54
- import openai
55
-
56
- data = {
57
- "prompt": query,
58
- "model": "text-davinci-003",
59
- "max_tokens": 1024,
60
- "temperature": 1,
61
- "top_p": 1,
62
- "stream": True,
63
- **options,
64
- }
65
- httpx_kwargs = {}
66
- if self.config.proxy:
67
- httpx_kwargs["proxies"] = self.config.proxy
68
- async with httpx.AsyncClient(trust_env=True, **httpx_kwargs) as sess:
69
- client = openai.AsyncOpenAI(
70
- api_key=self.openai_key, http_client=sess, base_url=self.api_base
71
- )
72
- try:
73
- completion = await client.completions.create(**data)
74
- except Exception as e:
75
- print(str(e))
76
- return
77
-
78
- async def text_gen():
79
- async for event in completion:
80
- if not event.choices:
81
- continue
82
- text = event.choices[0].text
83
- print(text, end="")
84
- yield text
85
-
86
- try:
87
- async for sentence in split_sentences(text_gen()):
88
- yield sentence
89
- finally:
90
- print()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes